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
This commit is contained in:
godofredoc 2024-03-22 18:04:05 -07:00 committed by GitHub
parent 42d6f719cb
commit 716f82763a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -49,7 +49,14 @@ class TestFileReporterResults {
final List<String> errors = <String>[];
for (final String metric in metrics.readAsLinesSync()) {
final Map<String, Object?> entry = json.decode(metric) as Map<String, Object?>;
/// 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<String, Object?> entry = json.decode(sanitizedMetric) as Map<String, Object?>;
if (entry.containsKey('suite')) {
final Map<String, Object?> suite = entry['suite']! as Map<String, Object?>;
addTestSpec(suite, entry['time']! as int, testSpecs);