mirror of
https://github.com/dart-lang/sdk
synced 2024-09-05 16:41:07 +00:00
[VM/Service] Include newline in the stdout service event.
TEST=new test added Bug:54582 Change-Id: I5e8d3aab19c37353a12e3a0a65edbb954d52bb4b Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/346084 Reviewed-by: Ben Konyi <bkonyi@google.com> Commit-Queue: Siva Annamalai <asiva@google.com>
This commit is contained in:
parent
8758f1f954
commit
82c385f73a
|
@ -37,11 +37,11 @@ var tests = <IsolateTest>[
|
|||
// initial stream subscription. Wait for the initial sentinel before
|
||||
// executing test logic.
|
||||
if (!started) {
|
||||
started = output == 'start';
|
||||
started = output == 'start\n';
|
||||
return;
|
||||
}
|
||||
expect(event.kind, EventKind.kWriteEvent);
|
||||
expect(output, 'stdout');
|
||||
expect(output, 'stdout\n');
|
||||
await stdoutSub.cancel();
|
||||
await service.streamCancel(EventStreams.kStdout);
|
||||
completer.complete();
|
||||
|
@ -57,7 +57,7 @@ var tests = <IsolateTest>[
|
|||
stdoutSub = service.onStdoutEvent.listen((event) async {
|
||||
expect(event.kind, EventKind.kWriteEvent);
|
||||
final decoded = utf8.decode(base64Decode(event.bytes!));
|
||||
expect(decoded, 'print');
|
||||
expect(decoded, 'print\n');
|
||||
await service.streamCancel(EventStreams.kStdout);
|
||||
await stdoutSub.cancel();
|
||||
completer.complete();
|
||||
|
|
53
pkg/vm_service/test/stdio_newline_test.dart
Normal file
53
pkg/vm_service/test/stdio_newline_test.dart
Normal file
|
@ -0,0 +1,53 @@
|
|||
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:test/test.dart';
|
||||
import 'package:vm_service/vm_service.dart';
|
||||
|
||||
import 'common/service_test_common.dart';
|
||||
import 'common/test_helper.dart';
|
||||
|
||||
void test() {
|
||||
print('started');
|
||||
debugger();
|
||||
print('lf1\ntrail');
|
||||
}
|
||||
|
||||
var tests = <IsolateTest>[
|
||||
hasStoppedAtBreakpoint,
|
||||
(VmService service, IsolateRef isolateRef) async {
|
||||
print('At breakpoint');
|
||||
final completer = Completer<void>();
|
||||
late StreamSubscription stdoutSub;
|
||||
bool started = false;
|
||||
stdoutSub = service.onStdoutEvent.listen((event) async {
|
||||
final output = utf8.decode(base64Decode(event.bytes!));
|
||||
// DDS buffers log history and sends each entry as an event upon the
|
||||
// initial stream subscription. Wait for the initial sentinel before
|
||||
// executing test logic.
|
||||
if (!started) {
|
||||
started = output == 'started\n';
|
||||
return;
|
||||
}
|
||||
expect(output, 'lf1\ntrail\n');
|
||||
await stdoutSub.cancel();
|
||||
await service.streamCancel(EventStreams.kStdout);
|
||||
completer.complete();
|
||||
});
|
||||
await service.streamListen(EventStreams.kStdout);
|
||||
await service.resume(isolateRef.id!);
|
||||
await completer.future;
|
||||
},
|
||||
];
|
||||
|
||||
Future<void> main(args) => runIsolateTests(
|
||||
args,
|
||||
tests,
|
||||
'stdio_newline_test.dart',
|
||||
testeeConcurrent: test,
|
||||
);
|
|
@ -89,7 +89,8 @@ void FUNCTION_NAME(Builtin_PrintString)(Dart_NativeArguments args) {
|
|||
if (Dart_IsError(result)) {
|
||||
Dart_PropagateError(result);
|
||||
}
|
||||
uint8_t* chars = Dart_ScopeAllocate(length + 1);
|
||||
intptr_t new_length = length + 1;
|
||||
uint8_t* chars = Dart_ScopeAllocate(new_length);
|
||||
ASSERT(chars != nullptr);
|
||||
result = Dart_CopyUTF8EncodingOfString(str, chars, length);
|
||||
if (Dart_IsError(result)) {
|
||||
|
@ -98,13 +99,13 @@ void FUNCTION_NAME(Builtin_PrintString)(Dart_NativeArguments args) {
|
|||
chars[length] = '\n';
|
||||
|
||||
// Uses fwrite to support printing NUL bytes.
|
||||
intptr_t res = fwrite(chars, 1, length + 1, stdout);
|
||||
ASSERT(res == (length + 1));
|
||||
intptr_t res = fwrite(chars, 1, new_length, stdout);
|
||||
ASSERT(res == new_length);
|
||||
fflush(stdout);
|
||||
if (ShouldCaptureStdout()) {
|
||||
// For now we report print output on the Stdout stream.
|
||||
const char* res =
|
||||
Dart_ServiceSendDataEvent("Stdout", "WriteEvent", chars, length);
|
||||
Dart_ServiceSendDataEvent("Stdout", "WriteEvent", chars, new_length);
|
||||
ASSERT(res == nullptr);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue