Skip to content

Commit

Permalink
[cfe] Add repro/regeneration command to macro test
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-by: Jens Johansen <[email protected]>
  • Loading branch information
johnniwinther authored and Commit Queue committed Jun 11, 2024
1 parent e7d3b78 commit 2820e96
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
6 changes: 3 additions & 3 deletions pkg/front_end/lib/src/testing/id_testing_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> extends DataComputer<T, CfeTestConfig,
Expand Down Expand Up @@ -229,7 +229,7 @@ Future<TestResult<T>> runTestForConfig<T>(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,
Expand Down
19 changes: 14 additions & 5 deletions pkg/front_end/test/macros/application/macro_application_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class MacroTestConfig extends CfeTestConfig {
}

@override
Future<void> onCompilationResult(
Future<void> onCompilationResult(MarkerOptions markerOptions,
TestData testData, CfeTestResultData testResultData) async {
Component component = testResultData.compilerResult.component!;
StringBuffer buffer = new StringBuffer();
Expand All @@ -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}
}));
}
}
}
Expand Down

0 comments on commit 2820e96

Please sign in to comment.