From 716f82763aa6a147fa14c7947e0b4f45d6198a62 Mon Sep 17 00:00:00 2001 From: godofredoc Date: Fri, 22 Mar 2024 18:04:05 -0700 Subject: [PATCH] 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: https://github.com/flutter/flutter/issues/145553 --- dev/bots/tool_subsharding.dart | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/dev/bots/tool_subsharding.dart b/dev/bots/tool_subsharding.dart index 769517f80a2b..9fe70bd581f4 100644 --- a/dev/bots/tool_subsharding.dart +++ b/dev/bots/tool_subsharding.dart @@ -49,7 +49,14 @@ class TestFileReporterResults { final List errors = []; for (final String metric in metrics.readAsLinesSync()) { - final Map entry = json.decode(metric) as Map; + /// Using print within a test adds the printed content to the json file report + /// as \u0000 making the file parsing step fail. The content of the json file + /// is expected to be a json dictionary per line and the following line removes + /// all the additional content at the beginning of the line until it finds the + /// first opening curly bracket. + // TODO(godofredoc): remove when https://github.com/flutter/flutter/issues/145553 is fixed. + final String sanitizedMetric = metric.replaceAll(RegExp(r'$.*{'), '{'); + final Map entry = json.decode(sanitizedMetric) as Map; if (entry.containsKey('suite')) { final Map suite = entry['suite']! as Map; addTestSpec(suite, entry['time']! as int, testSpecs);