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

Unified Diff: pkg/testing/lib/src/expectation.dart

Issue 2623413003: Implement custom status file expectations. (Closed)
Patch Set: Address review comments. Created 3 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/testing/lib/src/chain.dart ('k') | pkg/testing/lib/src/log.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/testing/lib/src/expectation.dart
diff --git a/pkg/testing/lib/src/expectation.dart b/pkg/testing/lib/src/expectation.dart
new file mode 100644
index 0000000000000000000000000000000000000000..0900c525a475527ec761fd4015d66dd7b189cbb9
--- /dev/null
+++ b/pkg/testing/lib/src/expectation.dart
@@ -0,0 +1,120 @@
+// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE.md file.
+
+library testing.expectation;
+
+/// An expectation represents the expected outcome of a test (or if it should
+/// be skipped).
+///
+/// An expectation belongs to a group, for example, [ExpectationGroup.Fail].
+///
+/// Each expectation group has a canonical expectation, defined below. You can
+/// use the canonical expectation instead of a more specific one. Note this
+/// isn't implemented yet.
+class Expectation {
+ static const Expectation Pass =
+ const Expectation("Pass", ExpectationGroup.Pass);
+
+ static const Expectation Crash =
+ const Expectation("Crash", ExpectationGroup.Crash);
+
+ static const Expectation Timeout =
+ const Expectation("Timeout", ExpectationGroup.Timeout);
+
+ static const Expectation Fail =
+ const Expectation("Fail", ExpectationGroup.Fail);
+
+ static const Expectation Skip =
+ const Expectation("Skip", ExpectationGroup.Skip);
+
+ final String name;
+
+ final ExpectationGroup group;
+
+ const Expectation(this.name, this.group);
+
+ String toString() => name;
+}
+
+class ExpectationSet {
+ static const ExpectationSet Default = const ExpectationSet(
+ const <String, Expectation>{
+ "pass": Expectation.Pass,
+ "crash": Expectation.Crash,
+ "timeout": Expectation.Timeout,
+ "fail": Expectation.Fail,
+ "skip": Expectation.Skip,
+ "missingcompiletimeerror":
+ const Expectation("MissingCompileTimeError", ExpectationGroup.Fail),
+ "missingruntimeerror":
+ const Expectation("MissingRuntimeError", ExpectationGroup.Fail),
+ });
+
+ final Map<String, Expectation> internalMap;
+
+ const ExpectationSet(this.internalMap);
+
+ operator[] (String name) {
+ return internalMap[name.toLowerCase()]
+ ?? (throw "No expectation named: '$name'.");
+ }
+
+ factory ExpectationSet.fromJsonList(List data) {
+ Map<String, Expectation> internalMap =
+ new Map<String, Expectation>.from(Default.internalMap);
+ for (Map map in data) {
+ String name;
+ String group;
+ map.forEach((String key, String value) {
+ switch (key) {
+ case "name":
+ name = value;
+ break;
+
+ case "group":
+ group = value;
+ break;
+
+ default:
+ throw "Unrecoginized key: '$key' in '$map'.";
+ }
+ });
+ if (name == null) {
+ throw "No name provided in '$map'";
+ }
+ if (group == null) {
+ throw "No group provided in '$map'";
+ }
+ Expectation expectation = new Expectation(name, groupFromString(group));
+ name = name.toLowerCase();
+ if (internalMap.containsKey(name)) {
+ throw "Duplicated expectation name: '$name'.";
+ }
+ internalMap[name] = expectation;
+ }
+ return new ExpectationSet(internalMap);
+ }
+}
+
+enum ExpectationGroup {
+ Crash,
+ Fail,
+ Meta,
+ Pass,
+ Skip,
+ Timeout,
+}
+
+ExpectationGroup groupFromString(String name) {
+ switch (name) {
+ case "Crash": return ExpectationGroup.Crash;
+ case "Fail": return ExpectationGroup.Fail;
+ case "Meta": return ExpectationGroup.Meta;
+ case "Pass": return ExpectationGroup.Pass;
+ case "Skip": return ExpectationGroup.Skip;
+ case "Timeout": return ExpectationGroup.Timeout;
+ default:
+ throw "Unrecognized group: '$name'.";
+ }
+}
« no previous file with comments | « pkg/testing/lib/src/chain.dart ('k') | pkg/testing/lib/src/log.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698