OLD | NEW |
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 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 | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
| 5 import 'dart:io'; |
| 6 |
| 7 import 'package:status_file/expectation.dart'; |
| 8 import 'package:status_file/status_file.dart'; |
| 9 |
5 import 'configuration.dart'; | 10 import 'configuration.dart'; |
6 import 'environment.dart'; | 11 import 'environment.dart'; |
7 import 'expectation.dart'; | |
8 import 'status_file.dart'; | |
9 | 12 |
10 /// Tracks the [Expectation]s associated with a set of file paths. | 13 /// Tracks the [Expectation]s associated with a set of file paths. |
11 /// | 14 /// |
12 /// For any given file path, returns the expected test results for that file. | 15 /// For any given file path, returns the expected test results for that file. |
13 /// A set can be loaded from a collection of status files. A file path may | 16 /// A set can be loaded from a collection of status files. A file path may |
14 /// exist in multiple files (or even multiple sections within the file). When | 17 /// exist in multiple files (or even multiple sections within the file). When |
15 /// that happens, all of the expectations of every entry are combined. | 18 /// that happens, all of the expectations of every entry are combined. |
16 class ExpectationSet { | 19 class ExpectationSet { |
17 /// Reads the expectations defined by the status files at [statusFilePaths] | 20 /// Reads the expectations defined by the status files at [statusFilePaths] |
18 /// when in [configuration]. | 21 /// when in [configuration]. |
19 static ExpectationSet read( | 22 static ExpectationSet read( |
20 List<String> statusFilePaths, Configuration configuration) { | 23 List<String> statusFilePaths, Configuration configuration) { |
21 var environment = new Environment(configuration); | 24 try { |
22 var expectations = new ExpectationSet._(); | 25 var environment = new ConfigurationEnvironment(configuration); |
23 for (var path in statusFilePaths) { | 26 var expectations = new ExpectationSet._(); |
24 var file = new StatusFile.read(path); | 27 for (var path in statusFilePaths) { |
25 for (var section in file.sections) { | 28 var file = new StatusFile.read(path); |
26 if (section.isEnabled(environment)) { | 29 file.validate(environment); |
27 for (var entry in section.entries) { | 30 for (var section in file.sections) { |
28 expectations.addEntry(entry); | 31 if (section.isEnabled(environment)) { |
| 32 for (var entry in section.entries) { |
| 33 expectations.addEntry(entry); |
| 34 } |
29 } | 35 } |
30 } | 36 } |
31 } | 37 } |
| 38 |
| 39 return expectations; |
| 40 } on SyntaxError catch (error) { |
| 41 stderr.writeln(error.toString()); |
| 42 exit(1); |
| 43 |
| 44 throw "unreachable"; |
32 } | 45 } |
33 | |
34 return expectations; | |
35 } | 46 } |
36 | 47 |
37 // Only create one copy of each Set<Expectation>. | 48 // Only create one copy of each Set<Expectation>. |
38 // We just use .toString as a key, so we may make a few | 49 // We just use .toString as a key, so we may make a few |
39 // sets that only differ in their toString element order. | 50 // sets that only differ in their toString element order. |
40 static Map<String, Set<Expectation>> _cachedSets = {}; | 51 static Map<String, Set<Expectation>> _cachedSets = {}; |
41 | 52 |
42 Map<String, Set<Expectation>> _map = {}; | 53 Map<String, Set<Expectation>> _map = {}; |
43 Map<String, List<RegExp>> _keyToRegExps; | 54 Map<String, List<RegExp>> _keyToRegExps; |
44 | 55 |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 var component = splitKey[i]; | 123 var component = splitKey[i]; |
113 var regExp = regExpCache.putIfAbsent(component, | 124 var regExp = regExpCache.putIfAbsent(component, |
114 () => new RegExp("^${splitKey[i]}\$".replaceAll('*', '.*'))); | 125 () => new RegExp("^${splitKey[i]}\$".replaceAll('*', '.*'))); |
115 regExps[i] = regExp; | 126 regExps[i] = regExp; |
116 } | 127 } |
117 | 128 |
118 _keyToRegExps[key] = regExps; | 129 _keyToRegExps[key] = regExps; |
119 }); | 130 }); |
120 } | 131 } |
121 } | 132 } |
OLD | NEW |