Parser machine logs (#118707)

* remove file reporter optional

* decouple stack trace from metric collections

* update tests; add collect metrics option

* add failed tests property

* add test for multiple stack failed

* change path on result

* create factory method

* throw exception when test file failed to generate

* remove catch of file exception

* handle when no stacktrace on file reporter
This commit is contained in:
Jesús S Guerrero
2023-02-02 14:04:06 -06:00
committed by GitHub
parent d4b6898478
commit d63987f71d
3 changed files with 98 additions and 42 deletions

View File

@@ -1802,6 +1802,7 @@ Future<void> _runDartTest(String workingDirectory, {
final List<String> args = <String>[
'run',
'test',
'--file-reporter=json:${metricFile.path}',
if (shuffleTests) '--test-randomize-ordering-seed=$shuffleSeed',
'-j$cpus',
if (!hasColor)
@@ -1813,8 +1814,6 @@ Future<void> _runDartTest(String workingDirectory, {
if (testPaths != null)
for (final String testPath in testPaths)
testPath,
if (collectMetrics)
'--file-reporter=json:${metricFile.path}',
];
final Map<String, String> environment = <String, String>{
'FLUTTER_ROOT': flutterRoot,
@@ -1840,19 +1839,24 @@ Future<void> _runDartTest(String workingDirectory, {
removeLine: useBuildRunner ? (String line) => line.startsWith('[INFO]') : null,
);
final TestFileReporterResults test = TestFileReporterResults.fromFile(metricFile); // --file-reporter name
final File info = fileSystem.file(path.join(flutterRoot, 'error.log'));
info.writeAsStringSync(json.encode(test.errors));
if (collectMetrics) {
try {
final List<String> testList = <String>[];
final Map<int, TestSpecs> allTestSpecs = generateMetrics(metricFile);
final Map<int, TestSpecs> allTestSpecs = test.allTestSpecs;
for (final TestSpecs testSpecs in allTestSpecs.values) {
testList.add(testSpecs.toJson());
}
if (testList.isNotEmpty) {
final String testJson = json.encode(testList);
final File testResults = fileSystem.file(path.join(flutterRoot, 'test_results.json'));
final File testResults = fileSystem.file(
path.join(flutterRoot, 'test_results.json'));
testResults.writeAsStringSync(testJson);
}
} on fs.FileSystemException catch (e){
} on fs.FileSystemException catch (e) {
print('Failed to generate metrics: $e');
}
}