Skip to content

Commit

Permalink
[dds/dap] Don't include empty output events when output ends with \n
Browse files Browse the repository at this point in the history
Empty output events are harmless but unnecessary. The stack frame parsing code would always send one with the output ended with \n which until recently was only for stderr, but recently was enabled for stdout.

The extra events broke some Flutter tests that were not expecting them.

See flutter/flutter#147250 (comment)

Change-Id: I13624f763d57a089d6b2d2c9e794cafb6a2f0023
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/364340
Commit-Queue: Ben Konyi <bkonyi@google.com>
Commit-Queue: Helin Shiah <helinx@google.com>
Reviewed-by: Ben Konyi <bkonyi@google.com>
Reviewed-by: Helin Shiah <helinx@google.com>
  • Loading branch information
DanTup authored and Commit Queue committed Apr 24, 2024
1 parent 8d5794a commit f7451f7
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
7 changes: 7 additions & 0 deletions pkg/dds/lib/src/dap/adapters/dart.dart
Expand Up @@ -2265,6 +2265,13 @@ abstract class DartDebugAdapter<TL extends LaunchRequestArguments,
final lineEnd = i != lines.length - 1 ? '\n' : '';
final output = '$linePrefix$line$lineSuffix$lineEnd';

// If the output is empty (for example the output ended with \n so after
// splitting by \n, the last iteration is empty) then we don't need
// to add any event.
if (output.isEmpty) {
continue;
}

final clientPath =
fileLikeUri != null ? toClientPathOrUri(fileLikeUri) : null;
events.add(
Expand Down
21 changes: 21 additions & 0 deletions pkg/dds/test/dap/integration/debug_test.dart
Expand Up @@ -50,6 +50,27 @@ main() {
]);
});

test('does not include empty output events when output ends with a newline',
() async {
final testFile = dap.createTestFile(simpleArgPrintingProgram);

final outputEvents = await dap.client.collectOutput(
launch: () => dap.client.launch(
testFile.path,
args: ['one', 'two'],
),
);

// The sample application uses `print()` which includes newlines on
// each output. Output is split by `\n` when scanning for stack frames
// and previously would include empty output events at the end if the
// content ended with a newline.
// https://github.com/flutter/flutter/pull/147250#issuecomment-2075128834
for (var output in outputEvents) {
expect(output.output, isNotEmpty);
}
});

test('runs a simple script using runInTerminal request', () async {
final testFile = dap.createTestFile(emptyProgram);

Expand Down

0 comments on commit f7451f7

Please sign in to comment.