Skip to content

Commit d49de8b

Browse files
jensjohacommit-bot@chromium.org
authored andcommitted
succinct option for id testing
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]>
1 parent 60f646a commit d49de8b

File tree

4 files changed

+65
-34
lines changed

4 files changed

+65
-34
lines changed

pkg/analyzer/test/util/id_testing_helper.dart

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ Future<bool> checkTests<T>(
5252
Map<String, MemberAnnotations<IdValue>> expectedMaps = {
5353
marker: new MemberAnnotations<IdValue>(),
5454
};
55-
computeExpectedMap(testFileUri, code, expectedMaps, onFailure: onFailure);
55+
computeExpectedMap(testFileUri, testFileName, code, expectedMaps,
56+
onFailure: onFailure);
5657
Map<Uri, AnnotatedCode> codeMap = {testFileUri: code};
5758
var libFileNames = <String>[];
5859
var testData = TestData(testFileUri, testFileUri, memorySourceFiles, codeMap,
@@ -92,7 +93,7 @@ Future<bool> runTest<T>(TestData testData, DataComputer<T> dataComputer,
9293
RunTestFunction runTestFor<T>(
9394
DataComputer<T> dataComputer, List<TestConfig> testedConfigs) {
9495
return (TestData testData,
95-
{bool testAfterFailures, bool verbose, bool printCode}) {
96+
{bool testAfterFailures, bool verbose, bool succinct, bool printCode}) {
9697
return runTest(testData, dataComputer, testedConfigs,
9798
testAfterFailures: testAfterFailures, onFailure: onFailure);
9899
};
@@ -199,7 +200,8 @@ class AnalyzerCompiledData<T> extends CompiledData<T> {
199200
}
200201

201202
@override
202-
void reportError(Uri uri, int offset, String message) {
203+
void reportError(Uri uri, int offset, String message,
204+
{bool succinct: false}) {
203205
print('$offset: $message');
204206
}
205207
}

pkg/front_end/lib/src/testing/id_testing.dart

Lines changed: 37 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ class MemberAnnotations<DataType> {
150150
/// corresponding test configuration. Otherwise it is expected for all
151151
/// configurations.
152152
// TODO(johnniwinther): Support an empty marker set.
153-
void computeExpectedMap(Uri sourceUri, AnnotatedCode code,
153+
void computeExpectedMap(Uri sourceUri, String filename, AnnotatedCode code,
154154
Map<String, MemberAnnotations<IdValue>> maps,
155155
{void onFailure(String message)}) {
156156
List<String> mapKeys = maps.keys.toList();
@@ -165,13 +165,15 @@ void computeExpectedMap(Uri sourceUri, AnnotatedCode code,
165165
IdValue idValue = IdValue.decode(sourceUri, annotation.offset, text);
166166
if (idValue.id.isGlobal) {
167167
if (fileAnnotations.globalData.containsKey(idValue.id)) {
168-
onFailure("Duplicate annotations for ${idValue.id} in $marker: "
168+
onFailure("Error in test '$filename': "
169+
"Duplicate annotations for ${idValue.id} in $marker: "
169170
"${idValue} and ${fileAnnotations.globalData[idValue.id]}.");
170171
}
171172
fileAnnotations.globalData[idValue.id] = idValue;
172173
} else {
173174
if (expectedValues.containsKey(idValue.id)) {
174-
onFailure("Duplicate annotations for ${idValue.id} in $marker: "
175+
onFailure("Error in test '$filename': "
176+
"Duplicate annotations for ${idValue.id} in $marker: "
175177
"${idValue} and ${expectedValues[idValue.id]}.");
176178
}
177179
expectedValues[idValue.id] = idValue;
@@ -198,7 +200,8 @@ TestData computeTestData(File testFile, Directory testLibDirectory,
198200
for (String testMarker in supportedMarkers) {
199201
expectedMaps[testMarker] = new MemberAnnotations<IdValue>();
200202
}
201-
computeExpectedMap(entryPoint, code[entryPoint], expectedMaps,
203+
computeExpectedMap(entryPoint, testFile.uri.pathSegments.last,
204+
code[entryPoint], expectedMaps,
202205
onFailure: onFailure);
203206
Map<String, String> memorySourceFiles = {
204207
entryPoint.path: code[entryPoint].sourceCode
@@ -219,7 +222,8 @@ TestData computeTestData(File testFile, Directory testLibDirectory,
219222
new AnnotatedCode.fromText(libCode, commentStart, commentEnd);
220223
memorySourceFiles[libFileUri.path] = annotatedLibCode.sourceCode;
221224
code[libFileUri] = annotatedLibCode;
222-
computeExpectedMap(libFileUri, annotatedLibCode, expectedMaps,
225+
computeExpectedMap(
226+
libFileUri, libFileName, annotatedLibCode, expectedMaps,
223227
onFailure: onFailure);
224228
}
225229
}
@@ -303,7 +307,7 @@ abstract class CompiledData<T> {
303307

304308
int getOffsetFromId(Id id, Uri uri);
305309

306-
void reportError(Uri uri, int offset, String message);
310+
void reportError(Uri uri, int offset, String message, {bool succinct: false});
307311
}
308312

309313
/// Interface used for interpreting annotations.
@@ -444,6 +448,7 @@ Future<bool> checkCode<T>(
444448
DataInterpreter<T> dataValidator,
445449
{bool filterActualData(IdValue expected, ActualData<T> actualData),
446450
bool fatalErrors: true,
451+
bool succinct: false,
447452
void onFailure(String message)}) async {
448453
IdData<T> data = new IdData<T>(code, expectedMaps, compiledData);
449454
bool hasFailure = false;
@@ -463,10 +468,13 @@ Future<bool> checkCode<T>(
463468
compiledData.reportError(
464469
actualData.uri,
465470
actualData.offset,
466-
'EXTRA $modeName DATA for ${id.descriptor}:\n '
467-
'object : ${actualData.objectText}\n '
468-
'actual : ${colorizeActual(actualValueText)}\n '
469-
'Data was expected for these ids: ${expectedMap.keys}');
471+
succinct
472+
? 'EXTRA $modeName DATA for ${id.descriptor}'
473+
: 'EXTRA $modeName DATA for ${id.descriptor}:\n '
474+
'object : ${actualData.objectText}\n '
475+
'actual : ${colorizeActual(actualValueText)}\n '
476+
'Data was expected for these ids: ${expectedMap.keys}',
477+
succinct: succinct);
470478
if (filterActualData == null || filterActualData(null, actualData)) {
471479
hasLocalFailure = true;
472480
}
@@ -480,11 +488,14 @@ Future<bool> checkCode<T>(
480488
compiledData.reportError(
481489
actualData.uri,
482490
actualData.offset,
483-
'UNEXPECTED $modeName DATA for ${id.descriptor}:\n '
484-
'detail : ${colorizeMessage(unexpectedMessage)}\n '
485-
'object : ${actualData.objectText}\n '
486-
'expected: ${colorizeExpected('$expected')}\n '
487-
'actual : ${colorizeActual(actualValueText)}');
491+
succinct
492+
? 'UNEXPECTED $modeName DATA for ${id.descriptor}'
493+
: 'UNEXPECTED $modeName DATA for ${id.descriptor}:\n '
494+
'detail : ${colorizeMessage(unexpectedMessage)}\n '
495+
'object : ${actualData.objectText}\n '
496+
'expected: ${colorizeExpected('$expected')}\n '
497+
'actual : ${colorizeActual(actualValueText)}',
498+
succinct: succinct);
488499
if (filterActualData == null ||
489500
filterActualData(expected, actualData)) {
490501
hasLocalFailure = true;
@@ -516,7 +527,8 @@ Future<bool> checkCode<T>(
516527
'Expected ${colorizeExpected('$expected')}';
517528
if (uri != null) {
518529
compiledData.reportError(
519-
uri, compiledData.getOffsetFromId(id, uri), message);
530+
uri, compiledData.getOffsetFromId(id, uri), message,
531+
succinct: succinct);
520532
} else {
521533
print(message);
522534
}
@@ -531,10 +543,12 @@ Future<bool> checkCode<T>(
531543
checkMissing(expectedMap, data.actualMaps[uri], uri);
532544
});
533545
checkMissing(data.expectedMaps.globalData, data.actualMaps.globalData);
534-
for (Uri uri in neededDiffs) {
535-
print('--annotations diff [${uri.pathSegments.last}]-------------');
536-
print(data.diffCode(uri, dataValidator));
537-
print('----------------------------------------------------------');
546+
if (!succinct) {
547+
for (Uri uri in neededDiffs) {
548+
print('--annotations diff [${uri.pathSegments.last}]-------------');
549+
print(data.diffCode(uri, dataValidator));
550+
print('----------------------------------------------------------');
551+
}
538552
}
539553
if (missingIds.isNotEmpty) {
540554
print("MISSING ids: ${missingIds}.");
@@ -547,7 +561,7 @@ Future<bool> checkCode<T>(
547561
}
548562

549563
typedef Future<bool> RunTestFunction(TestData testData,
550-
{bool testAfterFailures, bool verbose, bool printCode});
564+
{bool testAfterFailures, bool verbose, bool succinct, bool printCode});
551565

552566
/// Check code for all test files int [data] using [computeFromAst] and
553567
/// [computeFromKernel] from the respective front ends. If [skipForKernel]
@@ -572,6 +586,7 @@ Future runTests(Directory dataDir,
572586
// TODO(johnniwinther): Support --show to show actual data for an input.
573587
args = args.toList();
574588
bool verbose = args.remove('-v');
589+
bool succinct = args.remove('-s');
575590
bool shouldContinue = args.remove('-c');
576591
bool testAfterFailures = args.remove('-a');
577592
bool printCode = args.remove('-p');
@@ -613,6 +628,7 @@ Future runTests(Directory dataDir,
613628
if (await runTest(testData,
614629
testAfterFailures: testAfterFailures,
615630
verbose: verbose,
631+
succinct: succinct,
616632
printCode: printCode)) {
617633
hasFailures = true;
618634
}

pkg/front_end/lib/src/testing/id_testing_helper.dart

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,11 @@ class CfeCompiledData<T> extends CompiledData<T> {
137137
}
138138

139139
@override
140-
void reportError(Uri uri, int offset, String message) {
140+
void reportError(Uri uri, int offset, String message,
141+
{bool succinct: false}) {
141142
printMessageInLocation(
142-
compilerResult.component.uriToSource, uri, offset, message);
143+
compilerResult.component.uriToSource, uri, offset, message,
144+
succinct: succinct);
143145
}
144146
}
145147

@@ -170,10 +172,11 @@ void onFailure(String message) => throw new StateError(message);
170172
RunTestFunction runTestFor<T>(
171173
DataComputer<T> dataComputer, List<TestConfig> testedConfigs) {
172174
return (TestData testData,
173-
{bool testAfterFailures, bool verbose, bool printCode}) {
175+
{bool testAfterFailures, bool verbose, bool succinct, bool printCode}) {
174176
return runTest(testData, dataComputer, testedConfigs,
175177
testAfterFailures: testAfterFailures,
176178
verbose: verbose,
179+
succinct: succinct,
177180
printCode: printCode,
178181
onFailure: onFailure);
179182
};
@@ -186,6 +189,7 @@ Future<bool> runTest<T>(TestData testData, DataComputer<T> dataComputer,
186189
List<TestConfig> testedConfigs,
187190
{bool testAfterFailures,
188191
bool verbose,
192+
bool succinct,
189193
bool printCode,
190194
bool forUserLibrariesOnly: true,
191195
Iterable<Id> globalIds: const <Id>[],
@@ -196,6 +200,7 @@ Future<bool> runTest<T>(TestData testData, DataComputer<T> dataComputer,
196200
fatalErrors: !testAfterFailures,
197201
onFailure: onFailure,
198202
verbose: verbose,
203+
succinct: succinct,
199204
printCode: printCode)) {
200205
hasFailures = true;
201206
}
@@ -210,6 +215,7 @@ Future<bool> runTestForConfig<T>(
210215
TestData testData, DataComputer<T> dataComputer, TestConfig config,
211216
{bool fatalErrors,
212217
bool verbose,
218+
bool succinct,
213219
bool printCode,
214220
bool forUserLibrariesOnly: true,
215221
Iterable<Id> globalIds: const <Id>[],
@@ -223,7 +229,7 @@ Future<bool> runTestForConfig<T>(
223229
if (message is FormattedMessage && message.severity == Severity.error) {
224230
errors.add(message);
225231
}
226-
printDiagnosticMessage(message, print);
232+
if (!succinct) printDiagnosticMessage(message, print);
227233
};
228234
options.debugDump = printCode;
229235
options.experimentalFlags.addAll(config.experimentalFlags);
@@ -376,11 +382,12 @@ Future<bool> runTestForConfig<T>(
376382

377383
return checkCode(config.name, testData.testFileUri, testData.code,
378384
memberAnnotations, compiledData, dataComputer.dataValidator,
379-
fatalErrors: fatalErrors, onFailure: onFailure);
385+
fatalErrors: fatalErrors, succinct: succinct, onFailure: onFailure);
380386
}
381387

382388
void printMessageInLocation(
383-
Map<Uri, Source> uriToSource, Uri uri, int offset, String message) {
389+
Map<Uri, Source> uriToSource, Uri uri, int offset, String message,
390+
{bool succinct: false}) {
384391
if (uri == null) {
385392
print(message);
386393
} else {
@@ -391,8 +398,10 @@ void printMessageInLocation(
391398
if (offset != null) {
392399
Location location = source.getLocation(uri, offset);
393400
print('$location: $message');
394-
print(source.getTextLine(location.line));
395-
print(' ' * (location.column - 1) + '^');
401+
if (!succinct) {
402+
print(source.getTextLine(location.line));
403+
print(' ' * (location.column - 1) + '^');
404+
}
396405
} else {
397406
print('$uri: $message');
398407
}

tests/compiler/dart2js/equivalence/id_equivalence_helper.dart

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,8 @@ class Dart2jsCompiledData<T> extends CompiledData<T> {
347347
}
348348

349349
@override
350-
void reportError(Uri uri, int offset, String message) {
350+
void reportError(Uri uri, int offset, String message,
351+
{bool succinct: false}) {
351352
compiler.reporter.reportErrorMessage(
352353
computeSourceSpanFromUriOffset(uri, offset),
353354
MessageKind.GENERIC,
@@ -407,7 +408,10 @@ Future checkTests<T>(Directory dataDir, DataComputer<T> dataComputer,
407408
dataComputer.setup();
408409

409410
Future<bool> checkTest(TestData testData,
410-
{bool testAfterFailures, bool verbose, bool printCode}) async {
411+
{bool testAfterFailures,
412+
bool verbose,
413+
bool succinct,
414+
bool printCode}) async {
411415
bool hasFailures = false;
412416
String name = testData.name;
413417
List<String> testOptions = options.toList();

0 commit comments

Comments
 (0)