From 2820e96b3cdb104c8368d3cdfb29e799fd8fb53e Mon Sep 17 00:00:00 2001 From: Johnni Winther Date: Tue, 11 Jun 2024 14:11:22 +0000 Subject: [PATCH] [cfe] Add repro/regeneration command to macro test This prints the commands needed to reproduce or generate expectations for the macro application test. Change-Id: Idf62ec8d8bdc846d2b043328b447f51839984c48 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/370883 Commit-Queue: Johnni Winther Reviewed-by: Jens Johansen --- .../lib/src/testing/id_testing_helper.dart | 6 +++--- .../application/macro_application_test.dart | 19 ++++++++++++++----- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/pkg/front_end/lib/src/testing/id_testing_helper.dart b/pkg/front_end/lib/src/testing/id_testing_helper.dart index d1b064ac46d1..75dcc27c8642 100644 --- a/pkg/front_end/lib/src/testing/id_testing_helper.dart +++ b/pkg/front_end/lib/src/testing/id_testing_helper.dart @@ -61,8 +61,8 @@ class CfeTestConfig extends TestConfig { /// Called after running test on [testData] with the resulting /// [testResultData]. - void onCompilationResult( - TestData testData, CfeTestResultData testResultData) {} + void onCompilationResult(MarkerOptions markerOptions, TestData testData, + CfeTestResultData testResultData) {} } abstract class CfeDataComputer extends DataComputer> runTestForConfig(MarkerOptions markerOptions, CfeTestResultData testResultData = new CfeTestResultData(config, customData, compilerResult); - config.onCompilationResult(testData, testResultData); + config.onCompilationResult(markerOptions, testData, testResultData); return processCompiledResult( markerOptions, testData, dataComputer, testResultData, errors, fatalErrors: fatalErrors, diff --git a/pkg/front_end/test/macros/application/macro_application_test.dart b/pkg/front_end/test/macros/application/macro_application_test.dart index 25a5d512dbf0..a071de051c69 100644 --- a/pkg/front_end/test/macros/application/macro_application_test.dart +++ b/pkg/front_end/test/macros/application/macro_application_test.dart @@ -71,7 +71,7 @@ class MacroTestConfig extends CfeTestConfig { } @override - Future onCompilationResult( + Future onCompilationResult(MarkerOptions markerOptions, TestData testData, CfeTestResultData testResultData) async { Component component = testResultData.compilerResult.component!; StringBuffer buffer = new StringBuffer(); @@ -95,19 +95,28 @@ class MacroTestConfig extends CfeTestConfig { file.writeAsStringSync(actual); } else { String diff = await runDiff(expectedUri, actual); - throw "${testData.name} don't match ${expectedUri}\n$diff"; + print("ERROR: ${testData.name} don't match ${expectedUri}\n$diff"); + onFailure(generateErrorMessage(markerOptions, mismatches: { + testData.name: {testResultData.config.marker} + })); } } } else if (generateExpectations) { file.writeAsStringSync(actual); } else { - throw 'Please use -g option to create file ${expectedUri} with this ' - 'content:\n$actual'; + print('Please use -g option to create file ${expectedUri} with this ' + 'content:\n$actual'); + onFailure(generateErrorMessage(markerOptions, errors: { + testData.name: {testResultData.config.marker} + })); } if (offsetErrors.isNotEmpty) { offsetErrors.forEach(print); offsetErrors.clear(); - throw "${testData.name} has macro offset errors."; + print("ERROR: ${testData.name} has macro offset errors."); + onFailure(generateErrorMessage(markerOptions, errors: { + testData.name: {testResultData.config.marker} + })); } } }