Skip to content

Commit

Permalink
succinct option for id testing
Browse files Browse the repository at this point in the history
Add a "-s" (succinct) option to have a more dense output.
Meant for use together with "-a" so one can get a quick overview of how
many tests fail, e.g.
out/ReleaseX64/dart pkg/front_end/test/id_testing/id_testing_test.dart -a -s

Change-Id: I9e1d91694be76e6c66bf0f3c9168783f920a5bf4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/110914
Commit-Queue: Jens Johansen <[email protected]>
Reviewed-by: Johnni Winther <[email protected]>
  • Loading branch information
jensjoha authored and [email protected] committed Aug 1, 2019
1 parent 60f646a commit d49de8b
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 34 deletions.
8 changes: 5 additions & 3 deletions pkg/analyzer/test/util/id_testing_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ Future<bool> checkTests<T>(
Map<String, MemberAnnotations<IdValue>> expectedMaps = {
marker: new MemberAnnotations<IdValue>(),
};
computeExpectedMap(testFileUri, code, expectedMaps, onFailure: onFailure);
computeExpectedMap(testFileUri, testFileName, code, expectedMaps,
onFailure: onFailure);
Map<Uri, AnnotatedCode> codeMap = {testFileUri: code};
var libFileNames = <String>[];
var testData = TestData(testFileUri, testFileUri, memorySourceFiles, codeMap,
Expand Down Expand Up @@ -92,7 +93,7 @@ Future<bool> runTest<T>(TestData testData, DataComputer<T> dataComputer,
RunTestFunction runTestFor<T>(
DataComputer<T> dataComputer, List<TestConfig> testedConfigs) {
return (TestData testData,
{bool testAfterFailures, bool verbose, bool printCode}) {
{bool testAfterFailures, bool verbose, bool succinct, bool printCode}) {
return runTest(testData, dataComputer, testedConfigs,
testAfterFailures: testAfterFailures, onFailure: onFailure);
};
Expand Down Expand Up @@ -199,7 +200,8 @@ class AnalyzerCompiledData<T> extends CompiledData<T> {
}

@override
void reportError(Uri uri, int offset, String message) {
void reportError(Uri uri, int offset, String message,
{bool succinct: false}) {
print('$offset: $message');
}
}
Expand Down
58 changes: 37 additions & 21 deletions pkg/front_end/lib/src/testing/id_testing.dart
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ class MemberAnnotations<DataType> {
/// corresponding test configuration. Otherwise it is expected for all
/// configurations.
// TODO(johnniwinther): Support an empty marker set.
void computeExpectedMap(Uri sourceUri, AnnotatedCode code,
void computeExpectedMap(Uri sourceUri, String filename, AnnotatedCode code,
Map<String, MemberAnnotations<IdValue>> maps,
{void onFailure(String message)}) {
List<String> mapKeys = maps.keys.toList();
Expand All @@ -165,13 +165,15 @@ void computeExpectedMap(Uri sourceUri, AnnotatedCode code,
IdValue idValue = IdValue.decode(sourceUri, annotation.offset, text);
if (idValue.id.isGlobal) {
if (fileAnnotations.globalData.containsKey(idValue.id)) {
onFailure("Duplicate annotations for ${idValue.id} in $marker: "
onFailure("Error in test '$filename': "
"Duplicate annotations for ${idValue.id} in $marker: "
"${idValue} and ${fileAnnotations.globalData[idValue.id]}.");
}
fileAnnotations.globalData[idValue.id] = idValue;
} else {
if (expectedValues.containsKey(idValue.id)) {
onFailure("Duplicate annotations for ${idValue.id} in $marker: "
onFailure("Error in test '$filename': "
"Duplicate annotations for ${idValue.id} in $marker: "
"${idValue} and ${expectedValues[idValue.id]}.");
}
expectedValues[idValue.id] = idValue;
Expand All @@ -198,7 +200,8 @@ TestData computeTestData(File testFile, Directory testLibDirectory,
for (String testMarker in supportedMarkers) {
expectedMaps[testMarker] = new MemberAnnotations<IdValue>();
}
computeExpectedMap(entryPoint, code[entryPoint], expectedMaps,
computeExpectedMap(entryPoint, testFile.uri.pathSegments.last,
code[entryPoint], expectedMaps,
onFailure: onFailure);
Map<String, String> memorySourceFiles = {
entryPoint.path: code[entryPoint].sourceCode
Expand All @@ -219,7 +222,8 @@ TestData computeTestData(File testFile, Directory testLibDirectory,
new AnnotatedCode.fromText(libCode, commentStart, commentEnd);
memorySourceFiles[libFileUri.path] = annotatedLibCode.sourceCode;
code[libFileUri] = annotatedLibCode;
computeExpectedMap(libFileUri, annotatedLibCode, expectedMaps,
computeExpectedMap(
libFileUri, libFileName, annotatedLibCode, expectedMaps,
onFailure: onFailure);
}
}
Expand Down Expand Up @@ -303,7 +307,7 @@ abstract class CompiledData<T> {

int getOffsetFromId(Id id, Uri uri);

void reportError(Uri uri, int offset, String message);
void reportError(Uri uri, int offset, String message, {bool succinct: false});
}

/// Interface used for interpreting annotations.
Expand Down Expand Up @@ -444,6 +448,7 @@ Future<bool> checkCode<T>(
DataInterpreter<T> dataValidator,
{bool filterActualData(IdValue expected, ActualData<T> actualData),
bool fatalErrors: true,
bool succinct: false,
void onFailure(String message)}) async {
IdData<T> data = new IdData<T>(code, expectedMaps, compiledData);
bool hasFailure = false;
Expand All @@ -463,10 +468,13 @@ Future<bool> checkCode<T>(
compiledData.reportError(
actualData.uri,
actualData.offset,
'EXTRA $modeName DATA for ${id.descriptor}:\n '
'object : ${actualData.objectText}\n '
'actual : ${colorizeActual(actualValueText)}\n '
'Data was expected for these ids: ${expectedMap.keys}');
succinct
? 'EXTRA $modeName DATA for ${id.descriptor}'
: 'EXTRA $modeName DATA for ${id.descriptor}:\n '
'object : ${actualData.objectText}\n '
'actual : ${colorizeActual(actualValueText)}\n '
'Data was expected for these ids: ${expectedMap.keys}',
succinct: succinct);
if (filterActualData == null || filterActualData(null, actualData)) {
hasLocalFailure = true;
}
Expand All @@ -480,11 +488,14 @@ Future<bool> checkCode<T>(
compiledData.reportError(
actualData.uri,
actualData.offset,
'UNEXPECTED $modeName DATA for ${id.descriptor}:\n '
'detail : ${colorizeMessage(unexpectedMessage)}\n '
'object : ${actualData.objectText}\n '
'expected: ${colorizeExpected('$expected')}\n '
'actual : ${colorizeActual(actualValueText)}');
succinct
? 'UNEXPECTED $modeName DATA for ${id.descriptor}'
: 'UNEXPECTED $modeName DATA for ${id.descriptor}:\n '
'detail : ${colorizeMessage(unexpectedMessage)}\n '
'object : ${actualData.objectText}\n '
'expected: ${colorizeExpected('$expected')}\n '
'actual : ${colorizeActual(actualValueText)}',
succinct: succinct);
if (filterActualData == null ||
filterActualData(expected, actualData)) {
hasLocalFailure = true;
Expand Down Expand Up @@ -516,7 +527,8 @@ Future<bool> checkCode<T>(
'Expected ${colorizeExpected('$expected')}';
if (uri != null) {
compiledData.reportError(
uri, compiledData.getOffsetFromId(id, uri), message);
uri, compiledData.getOffsetFromId(id, uri), message,
succinct: succinct);
} else {
print(message);
}
Expand All @@ -531,10 +543,12 @@ Future<bool> checkCode<T>(
checkMissing(expectedMap, data.actualMaps[uri], uri);
});
checkMissing(data.expectedMaps.globalData, data.actualMaps.globalData);
for (Uri uri in neededDiffs) {
print('--annotations diff [${uri.pathSegments.last}]-------------');
print(data.diffCode(uri, dataValidator));
print('----------------------------------------------------------');
if (!succinct) {
for (Uri uri in neededDiffs) {
print('--annotations diff [${uri.pathSegments.last}]-------------');
print(data.diffCode(uri, dataValidator));
print('----------------------------------------------------------');
}
}
if (missingIds.isNotEmpty) {
print("MISSING ids: ${missingIds}.");
Expand All @@ -547,7 +561,7 @@ Future<bool> checkCode<T>(
}

typedef Future<bool> RunTestFunction(TestData testData,
{bool testAfterFailures, bool verbose, bool printCode});
{bool testAfterFailures, bool verbose, bool succinct, bool printCode});

/// Check code for all test files int [data] using [computeFromAst] and
/// [computeFromKernel] from the respective front ends. If [skipForKernel]
Expand All @@ -572,6 +586,7 @@ Future runTests(Directory dataDir,
// TODO(johnniwinther): Support --show to show actual data for an input.
args = args.toList();
bool verbose = args.remove('-v');
bool succinct = args.remove('-s');
bool shouldContinue = args.remove('-c');
bool testAfterFailures = args.remove('-a');
bool printCode = args.remove('-p');
Expand Down Expand Up @@ -613,6 +628,7 @@ Future runTests(Directory dataDir,
if (await runTest(testData,
testAfterFailures: testAfterFailures,
verbose: verbose,
succinct: succinct,
printCode: printCode)) {
hasFailures = true;
}
Expand Down
25 changes: 17 additions & 8 deletions pkg/front_end/lib/src/testing/id_testing_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,11 @@ class CfeCompiledData<T> extends CompiledData<T> {
}

@override
void reportError(Uri uri, int offset, String message) {
void reportError(Uri uri, int offset, String message,
{bool succinct: false}) {
printMessageInLocation(
compilerResult.component.uriToSource, uri, offset, message);
compilerResult.component.uriToSource, uri, offset, message,
succinct: succinct);
}
}

Expand Down Expand Up @@ -170,10 +172,11 @@ void onFailure(String message) => throw new StateError(message);
RunTestFunction runTestFor<T>(
DataComputer<T> dataComputer, List<TestConfig> testedConfigs) {
return (TestData testData,
{bool testAfterFailures, bool verbose, bool printCode}) {
{bool testAfterFailures, bool verbose, bool succinct, bool printCode}) {
return runTest(testData, dataComputer, testedConfigs,
testAfterFailures: testAfterFailures,
verbose: verbose,
succinct: succinct,
printCode: printCode,
onFailure: onFailure);
};
Expand All @@ -186,6 +189,7 @@ Future<bool> runTest<T>(TestData testData, DataComputer<T> dataComputer,
List<TestConfig> testedConfigs,
{bool testAfterFailures,
bool verbose,
bool succinct,
bool printCode,
bool forUserLibrariesOnly: true,
Iterable<Id> globalIds: const <Id>[],
Expand All @@ -196,6 +200,7 @@ Future<bool> runTest<T>(TestData testData, DataComputer<T> dataComputer,
fatalErrors: !testAfterFailures,
onFailure: onFailure,
verbose: verbose,
succinct: succinct,
printCode: printCode)) {
hasFailures = true;
}
Expand All @@ -210,6 +215,7 @@ Future<bool> runTestForConfig<T>(
TestData testData, DataComputer<T> dataComputer, TestConfig config,
{bool fatalErrors,
bool verbose,
bool succinct,
bool printCode,
bool forUserLibrariesOnly: true,
Iterable<Id> globalIds: const <Id>[],
Expand All @@ -223,7 +229,7 @@ Future<bool> runTestForConfig<T>(
if (message is FormattedMessage && message.severity == Severity.error) {
errors.add(message);
}
printDiagnosticMessage(message, print);
if (!succinct) printDiagnosticMessage(message, print);
};
options.debugDump = printCode;
options.experimentalFlags.addAll(config.experimentalFlags);
Expand Down Expand Up @@ -376,11 +382,12 @@ Future<bool> runTestForConfig<T>(

return checkCode(config.name, testData.testFileUri, testData.code,
memberAnnotations, compiledData, dataComputer.dataValidator,
fatalErrors: fatalErrors, onFailure: onFailure);
fatalErrors: fatalErrors, succinct: succinct, onFailure: onFailure);
}

void printMessageInLocation(
Map<Uri, Source> uriToSource, Uri uri, int offset, String message) {
Map<Uri, Source> uriToSource, Uri uri, int offset, String message,
{bool succinct: false}) {
if (uri == null) {
print(message);
} else {
Expand All @@ -391,8 +398,10 @@ void printMessageInLocation(
if (offset != null) {
Location location = source.getLocation(uri, offset);
print('$location: $message');
print(source.getTextLine(location.line));
print(' ' * (location.column - 1) + '^');
if (!succinct) {
print(source.getTextLine(location.line));
print(' ' * (location.column - 1) + '^');
}
} else {
print('$uri: $message');
}
Expand Down
8 changes: 6 additions & 2 deletions tests/compiler/dart2js/equivalence/id_equivalence_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,8 @@ class Dart2jsCompiledData<T> extends CompiledData<T> {
}

@override
void reportError(Uri uri, int offset, String message) {
void reportError(Uri uri, int offset, String message,
{bool succinct: false}) {
compiler.reporter.reportErrorMessage(
computeSourceSpanFromUriOffset(uri, offset),
MessageKind.GENERIC,
Expand Down Expand Up @@ -407,7 +408,10 @@ Future checkTests<T>(Directory dataDir, DataComputer<T> dataComputer,
dataComputer.setup();

Future<bool> checkTest(TestData testData,
{bool testAfterFailures, bool verbose, bool printCode}) async {
{bool testAfterFailures,
bool verbose,
bool succinct,
bool printCode}) async {
bool hasFailures = false;
String name = testData.name;
List<String> testOptions = options.toList();
Expand Down

0 comments on commit d49de8b

Please sign in to comment.