Skip to content

Commit 716f827

Browse files
authored
Add workaround for bug adding unicode strings to test reports. (#145607)
When print is used inside tests its content is added to the test report as a string of unicode \u0000 making the test reporting parser fail. This PR cleans removes non json content every line of the report. Bug: flutter/flutter#145553
1 parent 42d6f71 commit 716f827

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

dev/bots/tool_subsharding.dart

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,14 @@ class TestFileReporterResults {
4949
final List<String> errors = <String>[];
5050

5151
for (final String metric in metrics.readAsLinesSync()) {
52-
final Map<String, Object?> entry = json.decode(metric) as Map<String, Object?>;
52+
/// Using print within a test adds the printed content to the json file report
53+
/// as \u0000 making the file parsing step fail. The content of the json file
54+
/// is expected to be a json dictionary per line and the following line removes
55+
/// all the additional content at the beginning of the line until it finds the
56+
/// first opening curly bracket.
57+
// TODO(godofredoc): remove when https://github.com/flutter/flutter/issues/145553 is fixed.
58+
final String sanitizedMetric = metric.replaceAll(RegExp(r'$.*{'), '{');
59+
final Map<String, Object?> entry = json.decode(sanitizedMetric) as Map<String, Object?>;
5360
if (entry.containsKey('suite')) {
5461
final Map<String, Object?> suite = entry['suite']! as Map<String, Object?>;
5562
addTestSpec(suite, entry['time']! as int, testSpecs);

0 commit comments

Comments
 (0)