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

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

Issue 2984203002: Move the status file parser into its own package. (Closed)
Patch Set: Created 3 years, 5 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
« no previous file with comments | « tools/testing/dart/environment.dart ('k') | tools/testing/dart/expectation_set.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 ///
126 /// Prefer this over timeout since this avoids wasting CPU resources running
127 /// a test we know won't complete.
128 static final Expectation skipSlow =
129 new Expectation._('SkipSlow', isMeta: true, group: skip);
130
131 /// Skips this test because it is not intended to be meaningful for a certain
132 /// reason or on some configuration.
133 ///
134 /// For example, tests that use dart:io are SkipByDesign on the browser since
135 /// dart:io isn't supported there.
136 static final Expectation skipByDesign =
137 new Expectation._('SkipByDesign', isMeta: true);
138
139 /// Can be returned by the test runner to say the result should be ignored,
140 /// and assumed to meet the expectations, due to an infrastructure failure.
141 ///
142 /// This should not appear in status files.
143 static final Expectation ignore = new Expectation._('Ignore');
144
145 /// Used by pkg/front_end/lib/src/fasta/testing, but not used by test.dart.
146 /// Included here so that we can parse .status files that contain it.
147 static final Expectation verificationError =
148 new Expectation._('VerificationError');
149
150 /// Maps case-insensitive names to expectations.
151 static Map<String, Expectation> _all = new Map.fromIterable(<Expectation>[
152 pass,
153 crash,
154 timeout,
155 fail,
156 runtimeError,
157 compileTimeError,
158 missingRuntimeError,
159 missingCompileTimeError,
160 staticWarning,
161 missingStaticWarning,
162 pubGetError,
163 nonUtf8Error,
164 dartkCrash,
165 dartkTimeout,
166 dartkCompileTimeError,
167 ok,
168 slow,
169 skip,
170 skipSlow,
171 skipByDesign,
172 ignore,
173 verificationError,
174 ], key: (Expectation expectation) => expectation._name.toLowerCase());
175
176 /// Looks up the expectation with [name].
177 static Expectation find(String name) {
178 var expectation = _all[name.toLowerCase()];
179 if (expectation == null) {
180 throw new ArgumentError("Could not find an expectation named '$name'.");
181 }
182
183 return expectation;
184 }
185
186 final String _name;
187 final Expectation _group;
188
189 /// Whether this expectation is a test outcome. If not, it's a "meta marker".
190 final bool isOutcome;
191
192 Expectation._(this._name, {Expectation group, bool isMeta: false})
193 : _group = group,
194 isOutcome = !isMeta;
195
196 bool canBeOutcomeOf(Expectation expectation) {
197 var outcome = this;
198 if (outcome == ignore) return true;
199
200 while (outcome != null) {
201 if (outcome == expectation) {
202 return true;
203 }
204 outcome = outcome._group;
205 }
206
207 return false;
208 }
209
210 String toString() => _name;
211 }
OLDNEW
« no previous file with comments | « tools/testing/dart/environment.dart ('k') | tools/testing/dart/expectation_set.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698