Skip to content

Commit 990b032

Browse files
johnniwinthercommit-bot@chromium.org
authored andcommitted
[cfe] Mention update_expectations.dart in failure log
Change-Id: I692e6aa8571c14817831b7c6a135b2cd6ef0ed2b Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/178991 Reviewed-by: Jens Johansen <[email protected]> Commit-Queue: Johnni Winther <[email protected]>
1 parent 716a43e commit 990b032

File tree

7 files changed

+49
-17
lines changed

7 files changed

+49
-17
lines changed

pkg/front_end/test/fasta/testing/suite.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,9 @@ class FastaContext extends ChainContext with MatchContext {
294294
@override
295295
String get updateExpectationsOption => '${UPDATE_EXPECTATIONS}=true';
296296

297+
@override
298+
bool get canBeFixWithUpdateExpectations => true;
299+
297300
@override
298301
final ExpectationSet expectationSet =
299302
new ExpectationSet.fromJsonList(jsonDecode(EXPECTATIONS));
@@ -1117,7 +1120,8 @@ class Outline extends Step<TestDescription, ComponentResult, FastaContext> {
11171120
description, p, userLibraries, options, sourceTarget),
11181121
context.expectationSet["InstrumentationMismatch"],
11191122
instrumentation.problemsAsString,
1120-
autoFixCommand: '${UPDATE_COMMENTS}=true');
1123+
autoFixCommand: '${UPDATE_COMMENTS}=true',
1124+
canBeFixWithUpdateExpectations: true);
11211125
}
11221126
}
11231127
}

pkg/front_end/test/fasta/textual_outline_suite.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ class Context extends ChainContext with MatchContext {
5959
@override
6060
String get updateExpectationsOption => '${UPDATE_EXPECTATIONS}=true';
6161

62+
@override
63+
bool get canBeFixWithUpdateExpectations => true;
64+
6265
Context(this.updateExpectations);
6366

6467
final List<Step> steps = const <Step>[

pkg/front_end/test/incremental_load_from_dill_suite.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1120,7 +1120,8 @@ Result<TestData> checkExpectFile(TestData data, int worldNum,
11201120
"${extra}Unexpected serialized representation. "
11211121
"Fix or update $uri to contain the below:\n\n"
11221122
"$actualSerialized",
1123-
autoFixCommand: "updateExpectations=true");
1123+
autoFixCommand: "updateExpectations=true",
1124+
canBeFixWithUpdateExpectations: true);
11241125
}
11251126
}
11261127
return null;

pkg/front_end/test/parser_suite.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ class Context extends ChainContext with MatchContext {
101101
@override
102102
String get updateExpectationsOption => '${UPDATE_EXPECTATIONS}=true';
103103

104+
@override
105+
bool get canBeFixWithUpdateExpectations => true;
106+
104107
final bool addTrace;
105108
final bool annotateLines;
106109
final String suiteName;

pkg/front_end/test/unit_test_suites.dart

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -138,24 +138,30 @@ class ResultLogger implements Logger {
138138
"matches": matchedExpectations,
139139
}));
140140
if (!matchedExpectations) {
141-
String failureLog = result.log;
141+
StringBuffer sb = new StringBuffer();
142+
sb.write(result.log);
142143
if (result.error != null) {
143-
failureLog = "$failureLog\n\n${result.error}";
144+
sb.write("\n\n${result.error}");
144145
}
145146
if (result.trace != null) {
146-
failureLog = "$failureLog\n\n${result.trace}";
147+
sb.write("\n\n${result.trace}");
147148
}
149+
sb.write("\n\nTo re-run this test, run:");
150+
sb.write("\n\n dart pkg/front_end/test/unit_test_suites.dart -p "
151+
"$testName");
148152
if (result.autoFixCommand != null) {
149-
failureLog = "$failureLog\n\n"
150-
"To re-run this test, run:\n\n"
151-
" dart pkg/front_end/test/unit_test_suites.dart -p $testName\n\n"
152-
"To automatically update the test expectations, run:\n\n"
153-
" dart pkg/front_end/test/unit_test_suites.dart -p $testName "
154-
"-D${result.autoFixCommand}\n";
155-
} else {
156-
failureLog = "$failureLog\n\nRe-run this test: dart "
157-
"pkg/front_end/test/unit_test_suites.dart -p $testName";
153+
sb.write("\n\nTo automatically update the test expectations, run:");
154+
sb.write("\n\n dart pkg/front_end/test/unit_test_suites.dart -p "
155+
"$testName -D${result.autoFixCommand}");
156+
if (result.canBeFixWithUpdateExpectations) {
157+
sb.write('\n\nTo update test expectations for all tests at once, '
158+
'run:');
159+
sb.write('\n\n dart pkg/front_end/tool/update_expectations.dart');
160+
sb.write('\n\nNote that this takes a long time and should only be '
161+
'used when many tests need updating.\n');
162+
}
158163
}
164+
String failureLog = sb.toString();
159165
String outcome = "${result.outcome}";
160166
logsPort.send(jsonEncode({
161167
"name": testName,

pkg/front_end/test/utils/kernel_chain.dart

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ abstract class MatchContext implements ChainContext {
6666

6767
String get updateExpectationsOption;
6868

69+
bool get canBeFixWithUpdateExpectations;
70+
6971
ExpectationSet get expectationSet;
7072

7173
Expectation get expectationFileMismatch =>
@@ -96,7 +98,10 @@ abstract class MatchContext implements ChainContext {
9698
output, onMismatch, "$uri doesn't match ${expectedFile.uri}\n$diff",
9799
autoFixCommand: onMismatch == expectationFileMismatch
98100
? updateExpectationsOption
99-
: null);
101+
: null,
102+
canBeFixWithUpdateExpectations:
103+
onMismatch == expectationFileMismatch &&
104+
canBeFixWithUpdateExpectations);
100105
} else {
101106
return new Result<O>.pass(output);
102107
}

pkg/testing/lib/src/chain.dart

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,8 +358,16 @@ class Result<O> {
358358
/// update the test to match new expectations.
359359
final String autoFixCommand;
360360

361+
/// If set, the test can be fixed by running
362+
///
363+
/// dart pkg/front_end/tool/update_expectations.dart
364+
///
365+
final bool canBeFixWithUpdateExpectations;
366+
361367
Result(this.output, this.outcome, this.error,
362-
{this.trace, this.autoFixCommand});
368+
{this.trace,
369+
this.autoFixCommand,
370+
this.canBeFixWithUpdateExpectations: false});
363371

364372
Result.pass(O output) : this(output, Expectation.Pass, null);
365373

@@ -384,7 +392,9 @@ class Result<O> {
384392

385393
Result<O2> copyWithOutput<O2>(O2 output) {
386394
return new Result<O2>(output, outcome, error,
387-
trace: trace, autoFixCommand: autoFixCommand)
395+
trace: trace,
396+
autoFixCommand: autoFixCommand,
397+
canBeFixWithUpdateExpectations: canBeFixWithUpdateExpectations)
388398
..logs.addAll(logs);
389399
}
390400
}

0 commit comments

Comments
 (0)