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

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

Issue 8514003: tools/test.dart: Read test expectations from the status file, and pass them to the test runner. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Readdress comments. Created 9 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « tests/standalone/test_config.dart ('k') | tools/testing/dart/test_runner.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 #library("status_file_parser"); 5 #library("status_file_parser");
6 6
7 7
8 #import("status_expression.dart"); 8 #import("status_expression.dart");
9 9
10 // Possible outcomes of running a test.
11 final CRASH = "Crash";
12 final TIMEOUT = "Timeout";
13 final FAIL = "Fail";
14 final PASS = "Pass";
15 // An indication to skip the test. The caller is responsible for skipping it.
16 final SKIP = "Skip";
17
10 final RegExp StripComment = const RegExp("^[^#]*"); 18 final RegExp StripComment = const RegExp("^[^#]*");
11 final RegExp HeaderPattern = const RegExp(@"\[([^\]]+)\]"); 19 final RegExp HeaderPattern = const RegExp(@"^\[([^\]]+)\]");
12 final RegExp RulePattern = const RegExp(@"\s*([^: ]*)\s*:(.*)"); 20 final RegExp RulePattern = const RegExp(@"\s*([^: ]*)\s*:(.*)");
13 final RegExp PrefixPattern = const RegExp(@"^\s*prefix\s+([\w\_\.\-\/]+)\s*$"); 21 final RegExp PrefixPattern = const RegExp(@"^\s*prefix\s+([\w\_\.\-\/]+)\s*$");
14 22
15 // TODO(whesse): Implement configuration_info library that contains data 23 // TODO(whesse): Implement configuration_info library that contains data
16 // structures for test configuration, including Section. 24 // structures for test configuration, including Section.
17 class Section { 25 class Section {
18 BooleanExpression condition; 26 BooleanExpression condition;
19 Collection testSettings = const []; 27 List<TestRule> testRules;
20 28
21 Section.always() : condition = null; 29 Section.always() : condition = null, testRules = new List<TestRule>();
22 Section(this.condition); 30 Section(this.condition) : testRules = new List<TestRule>();
31
32 bool isEnabled(environment) =>
33 condition == null || condition.evaluate(environment);
23 } 34 }
24 35
25 36
26 // Helper method to be able to run the test from the runtime 37 // Helper method to be able to run the test from the runtime
27 // directory, or the top directory. 38 // directory, or the top directory.
28 String getFilename(String path) => 39 String getFilename(String path) =>
29 new File(path).existsSync() ? path : '../$path'; 40 new File(path).existsSync() ? path : '../$path';
30 41
31 String getDirname(String path) => 42 String getDirname(String path) =>
32 new Directory(path).existsSync() ? path : '../$path'; 43 new Directory(path).existsSync() ? path : '../$path';
44
45 TestExpectationsMap ReadTestExpectations(String statusFilePath, environment) {
46 List<Section> sections = new List<Section>();
47 ReadConfigurationInto(statusFilePath, sections);
33 48
34 49 TestExpectationsMap map = new TestExpectationsMap();
50 for (Section section in sections) {
51 if (section.isEnabled(environment)) {
52 for (var rule in section.testRules) {
53 map.addTest(rule, environment);
54 }
55 }
56 }
57 return map;
58 }
59
35 void ReadConfigurationInto(path, sections) { 60 void ReadConfigurationInto(path, sections) {
36 File file = new File(getFilename(path)); 61 File file = new File(getFilename(path));
37 if (!file.existsSync()) return; // TODO(whesse): Handle missing file. 62 if (!file.existsSync()) return; // TODO(whesse): Handle missing file.
38 FileInputStream file_stream = file.openInputStream(); 63 FileInputStream file_stream = file.openInputStream();
39 StringInputStream lines = new StringInputStream(file_stream); 64 StringInputStream lines = new StringInputStream(file_stream);
40 65
41 Section current = new Section.always(); 66 Section current = new Section.always();
42 sections.add(current); 67 sections.add(current);
43 String prefix = ""; 68 String prefix = "";
44 69
45 String line; 70 String line;
46 while ((line = lines.readLine()) != null) { 71 while ((line = lines.readLine()) != null) {
47 Match match = StripComment.firstMatch(line); 72 Match match = StripComment.firstMatch(line);
48 line = (match == null) ? "" : match[0]; 73 line = (match == null) ? "" : match[0];
49 line = line.trim(); 74 line = line.trim();
50 if (line == "") continue; 75 if (line == "") continue;
51 76
52 match = HeaderPattern.firstMatch(line); 77 match = HeaderPattern.firstMatch(line);
53 if (match != null) { 78 if (match != null) {
54 String condition_string = match[1].trim(); 79 String condition_string = match[1].trim();
55 List<String> tokens = new Tokenizer(condition_string).tokenize(); 80 List<String> tokens = new Tokenizer(condition_string).tokenize();
56 ExpressionParser parser = new ExpressionParser(new Scanner(tokens)); 81 ExpressionParser parser = new ExpressionParser(new Scanner(tokens));
57 current = new Section(parser.parseBooleanExpression()); 82 current = new Section(parser.parseBooleanExpression());
58 sections.add(current); 83 sections.add(current);
59 continue; 84 continue;
60 } 85 }
61 86
62 match = RulePattern.firstMatch(line); 87 match = RulePattern.firstMatch(line);
63 if (match != null) { 88 if (match != null) {
64 String path = prefix + match[1].trim(); 89 String name = match[1].trim();
90 // TODO(whesse): Handle test names ending in a wildcard (*).
65 String expression_string = match[2].trim(); 91 String expression_string = match[2].trim();
66 List<String> tokens = new Tokenizer(expression_string).tokenize(); 92 List<String> tokens = new Tokenizer(expression_string).tokenize();
67 SetExpression expression = 93 SetExpression expression =
68 new ExpressionParser(new Scanner(tokens)).parseSetExpression(); 94 new ExpressionParser(new Scanner(tokens)).parseSetExpression();
69 // TODO(whesse): Save rule in configuration data structure. 95 current.testRules.add(new TestRule(name, expression));
70 continue; 96 continue;
71 } 97 }
72 98
73 match = PrefixPattern.firstMatch(line); 99 match = PrefixPattern.firstMatch(line);
74 if (match != null) { 100 if (match != null) {
75 prefix = match[1]; 101 prefix = match[1];
76 continue; 102 continue;
77 } 103 }
78 104
79 print("unmatched line: $line"); 105 print("unmatched line: $line");
80 } 106 }
81 107
82 file_stream.close(); 108 file_stream.close();
83 } 109 }
84 110
111
112 class TestRule {
113 String name;
114 SetExpression expression;
115
116 TestRule(this.name, this.expression);
117 }
118
119
120 class TestExpectationsMap {
121 Map<String, Set<String>> map;
122
123 TestExpectationsMap() : map = new Map<String, Set<String>>();
124
125 void addTest(testRule, environment) {
126 map[testRule.name] = testRule.expression.evaluate(environment);
127 }
128
129 Set<String> expectations(String filename) {
130 var result = map[filename];
131 return result != null ? result : new Set.from([PASS]);
132 }
133 }
OLDNEW
« no previous file with comments | « tests/standalone/test_config.dart ('k') | tools/testing/dart/test_runner.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698