Skip to content

Commit

Permalink
[tool] Dartfuzz use string matcher to output a diff
Browse files Browse the repository at this point in the history
Before this CL the fuzzer would give a truncated output of stdout of
both invocations on a divergence.
This was not helpful for cases where the divergence is after the
truncation.

Instead, use package:matcher to report the diff between the strings.

Bug: dart-lang#53972
Change-Id: I1eb1a5a35b5a5082fdacbca881498a61eb9cca1f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/334440
Reviewed-by: Martin Kustermann <[email protected]>
Commit-Queue: Daco Harkes <[email protected]>
  • Loading branch information
dcharkes authored and Commit Queue committed Nov 7, 2023
1 parent dae322d commit 7fdd032
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
22 changes: 12 additions & 10 deletions runtime/tools/dartfuzz/dartfuzz_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'dart:isolate';
import 'dart:math';

import 'package:args/args.dart';
import 'package:matcher/matcher.dart';

import 'dartfuzz.dart';

Expand Down Expand Up @@ -464,9 +465,15 @@ class DartFuzzTest {
}
}

void printDivergenceOutput(String string, int numLines) {
final lines = string.split('\n');
print(lines.sublist(0, min(lines.length, numLines)).join('\n'));
void reportStringDifference(String a, String b) {
final matcher = equals(a);
final matches = matcher.matches(b, {});
if (matches) {
print('Strings are not different.');
return;
}
final mismatch = matcher.describeMismatch(b, StringDescription(), {}, true);
print(mismatch.toString());
}

void reportDivergence(TestResult result1, TestResult result2) {
Expand All @@ -475,13 +482,8 @@ class DartFuzzTest {
print('\n$isolate: !DIVERGENCE! $version:$seed ($report)');
if (result1.exitCode == result2.exitCode) {
if (numOutputLines > 0) {
// Only report the actual output divergence details up to
// numOutputLines, since this output may be lengthy and should be
// reproducible anyway.
print('\nout1:\n');
printDivergenceOutput(result1.output, numOutputLines);
print('\nout2:\n');
printDivergenceOutput(result2.output, numOutputLines);
print('\nout1 and out2 are different:\n');
reportStringDifference(result1.output, result2.output);
}
} else {
// For any other divergence, always report what went wrong.
Expand Down
1 change: 1 addition & 0 deletions runtime/tools/dartfuzz/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ environment:
dependencies:
analyzer: any
args: any
matcher: any

dev_dependencies:
lints: any

0 comments on commit 7fdd032

Please sign in to comment.