Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: tools/testing/dart/expectation.dart

Issue 2875203005: Refactor and clean up the status file parsing code. (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 /// The possible outcomes from running a test.
6 class Expectation {
7 /// The test completed normally and did what it intended to do.
8 static final Expectation pass = new Expectation._('Pass');
9
10 /// The process aborted in a way that is not a potential runtime error coming
11 /// from the test itself. This is not considered a failure. It means an
12 /// error happened so fundamental that success/failure could not be
13 /// determined. Includes:
14 ///
15 /// * The Dart VM itself crashes, but not from an unhandled exception in user
16 /// code.
17 ///
18 /// * When running dart2js on top of the VM to compile some code, the VM
19 /// exits with a non-zero exit code or uncaught exception -- meaning an
20 /// internal exception in dart2js itself.
21 ///
22 /// * The browser process crashes.
23 static final Expectation crash = new Expectation._('Crash');
24
25 /// The test did not complete (either successfully or unsuccessfully) in the
26 /// amount of time that the test runner gave it.
27 static final Expectation timeout = new Expectation._('Timeout');
28
29 /// The test completed but did not produce the intended output.
30 ///
31 /// This status is rarely used directly. Instead, most of the expectations
32 /// below refine this into more specific reasons *why* it failed.
33 static final Expectation fail = new Expectation._('Fail');
34
35 /// The test compiled and began executing but then threw an uncaught
36 /// exception or produced the wrong output.
37 static final Expectation runtimeError =
38 new Expectation._('RuntimeError', group: fail);
39
40 /// The test failed with an error at compile time and did not execute any
41 /// code.
42 ///
43 /// * For a VM test, means the VM exited with a "compile error" exit code 254.
44 /// * For an analyzer test, means the analyzer reported a static error.
45 /// * For a dart2js test, means dart2js reported a compile error.
46 static final Expectation compileTimeError =
47 new Expectation._('CompileTimeError', group: fail);
48
49 /// The test itself contains a comment with `@runtime-error` in it,
50 /// indicating it should have produced a runtime error when run. But when it
51 /// was run, the test completed without error.
52 static final Expectation missingRuntimeError =
53 new Expectation._('MissingRuntimeError', group: fail);
54
55 /// The test itself contains a comment with `@compile-error` in it,
56 /// indicating it should have produced an error when compiled. But when it
57 /// was compiled, no error was reported.
58 static final Expectation missingCompileTimeError =
59 new Expectation._('MissingCompileTimeError', group: fail);
60
61 /// When the test is processed by analyzer, a static warning should be
62 /// reported.
63 static final Expectation staticWarning =
64 new Expectation._('StaticWarning', group: fail);
65
66 /// The test itself contains a comment with `@static-warning` in it,
67 /// indicating analyzer should report a static warning when analyzing it, but
68 /// analysis did not produce any warnings.
69 static final Expectation missingStaticWarning =
70 new Expectation._('MissingStaticWarning', group: fail);
71
72 /// An invocation of "pub get" exited with a non-zero exit code.
73 // TODO(rnystrom): Is this still used? If not, remove.
74 static final Expectation pubGetError =
75 new Expectation._('PubGetError', group: fail);
76
77 /// The stdout or stderr produced by the test was not valid UTF-8 and could
78 /// not be decoded.
79 // TODO(rnystrom): The only test that uses this expectation is the one that
80 // tests that the test runner handles this expectation. Remove it?
81 static final Expectation nonUtf8Error =
82 new Expectation._('NonUtf8Output', group: fail);
83
84 /// The VM exited with the special exit code 252.
85 static final Expectation dartkCrash =
86 new Expectation._('DartkCrash', group: crash);
87
88 /// A timeout occurred in a test using the Kernel-based front end.
89 static final Expectation dartkTimeout =
90 new Expectation._('DartkTimeout', group: timeout);
91
92 /// A compile error was reported on a test compiled using the Kernel-based
93 /// front end.
94 static final Expectation dartkCompileTimeError =
95 new Expectation._('DartkCompileTimeError', group: compileTimeError);
96
97 // "meta expectations"
98 /// A marker applied to a test to indicate that the other non-pass
99 /// expectations are intentional and not a result of bugs or features that
100 /// have yet to be implemented.
101 ///
102 /// For example, a test marked "RuntimeError, Ok" means "This test is
103 /// *supposed* to fail at runtime."
104 // TODO(rnystrom): This is redundant with other mechanisms like
105 // `@runtime-error` and the markers in analyzer tests for stating where a
106 // static error should be reported. It leads to perpetually larger status
107 // files and means a reader of a test can't tell what the intended behavior
108 // actually is without knowing which status files mention it. Remove.
109 static final Expectation ok = new Expectation._('Ok', isMeta: true);
110
111 /// A marker that indicates the test takes longer to complete than most tests.
112 /// Tells the test runner to increase the timeout when running it.
113 static final Expectation slow = new Expectation._('Slow', isMeta: true);
114
115 /// Tells the test runner to not attempt to run the test.
116 ///
117 /// This means the test runner does not compare the test's actual results with
118 /// the expected results at all. This expectation should be avoided since it's
119 /// doesn't indicate *why* the test is being skipped and means we won't
120 /// notice if the actual behavior of the test changes.
121 static final Expectation skip = new Expectation._('Skip', isMeta: true);
122
123 /// Tells the test runner to skip the test because it takes too long to
124 /// complete.
125 // TODO(rnystrom): Why not use timeout for these?
Bill Hesse 2017/05/15 16:15:08 Because they then use a process for the amount of
Bob Nystrom 2017/05/15 22:42:51 Good to know! Updated the comment.
126 static final Expectation skipSlow =
127 new Expectation._('SkipSlow', isMeta: true, group: skip);
128
129 /// Skips this test because it is not intended to be meaningful for a certain
130 /// reason or on some configuration.
131 ///
132 /// For example, tests that use dart:io are SkipByDesign on the browser since
133 /// dart:io isn't supported there.
134 static final Expectation skipByDesign =
135 new Expectation._('SkipByDesign', isMeta: true);
136
137 /// Can be returned by the test runner to say the result should be ignored,
138 /// and assumed to meet the expectations, due to an infrastructure failure.
139 ///
140 /// This should not appear in status files.
141 static final Expectation ignore = new Expectation._('Ignore');
142
143 // TODO(rnystrom): What is this? It appears in some status files, but does
144 // not appear to be understood by test.dart.
Bill Hesse 2017/05/15 16:15:08 I don't know. Please find the author who added it
Bob Nystrom 2017/05/15 22:42:51 Looks like a pkg/front_end/lib/src/fasta/testing t
145 static final Expectation verificationError =
146 new Expectation._('VerificationError');
147
148 /// Maps case-insensitive names to expectations.
149 static Map<String, Expectation> _all = new Map.fromIterable(<Expectation>[
150 pass,
151 crash,
152 timeout,
153 fail,
154 runtimeError,
155 compileTimeError,
156 missingRuntimeError,
157 missingCompileTimeError,
158 staticWarning,
159 missingStaticWarning,
160 pubGetError,
161 nonUtf8Error,
162 dartkCrash,
163 dartkTimeout,
164 dartkCompileTimeError,
165 ok,
166 slow,
167 skip,
168 skipSlow,
169 skipByDesign,
170 ignore,
171 verificationError,
172 ], key: (Expectation expectation) => expectation._name.toLowerCase());
173
174 /// Looks up the expectation with [name].
175 static Expectation find(String name) {
176 var expectation = _all[name.toLowerCase()];
177 if (expectation == null) {
178 throw new ArgumentError("Could not find an expectation named '$name'.");
179 }
180
181 return expectation;
182 }
183
184 final String _name;
185 final Expectation _group;
186
187 /// Whether this expectation is a test outcome. If not, it's a "meta marker".
188 final bool isOutcome;
189
190 Expectation._(this._name, {Expectation group, bool isMeta: false})
191 : _group = group,
192 isOutcome = !isMeta;
193
194 bool canBeOutcomeOf(Expectation expectation) {
195 var outcome = this;
196 if (outcome == ignore) return true;
197
198 while (outcome != null) {
199 if (outcome == expectation) {
200 return true;
201 }
202 outcome = outcome._group;
203 }
204
205 return false;
206 }
207
208 String toString() => _name;
209 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698