| OLD | NEW |
| 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. | 10 // Possible outcomes of running a test. |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 // Helper method to be able to run the test from the runtime | 38 // Helper method to be able to run the test from the runtime |
| 39 // directory, or the top directory. | 39 // directory, or the top directory. |
| 40 String getFilename(String path) => | 40 String getFilename(String path) => |
| 41 new File(path).existsSync() ? path : '../$path'; | 41 new File(path).existsSync() ? path : '../$path'; |
| 42 | 42 |
| 43 String getDirname(String path) => | 43 String getDirname(String path) => |
| 44 new Directory(path).existsSync() ? path : '../$path'; | 44 new Directory(path).existsSync() ? path : '../$path'; |
| 45 | 45 |
| 46 void ReadTestExpectationsInto(TestExpectations expectations, | 46 void ReadTestExpectationsInto(TestExpectations expectations, |
| 47 String statusFilePath, | 47 String statusFilePath, |
| 48 environment) { | 48 environment, |
| 49 onDone) { |
| 49 List<Section> sections = new List<Section>(); | 50 List<Section> sections = new List<Section>(); |
| 50 ReadConfigurationInto(statusFilePath, sections); | |
| 51 | 51 |
| 52 for (Section section in sections) { | 52 void sectionsRead() { |
| 53 if (section.isEnabled(environment)) { | 53 for (Section section in sections) { |
| 54 for (var rule in section.testRules) { | 54 if (section.isEnabled(environment)) { |
| 55 expectations.addRule(rule, environment); | 55 for (var rule in section.testRules) { |
| 56 expectations.addRule(rule, environment); |
| 57 } |
| 56 } | 58 } |
| 57 } | 59 } |
| 60 onDone(); |
| 58 } | 61 } |
| 62 |
| 63 ReadConfigurationInto(statusFilePath, sections, sectionsRead); |
| 59 } | 64 } |
| 60 | 65 |
| 61 void ReadConfigurationInto(path, sections) { | 66 void ReadConfigurationInto(path, sections, onDone) { |
| 62 File file = new File(getFilename(path)); | 67 File file = new File(getFilename(path)); |
| 63 if (!file.existsSync()) return; // TODO(whesse): Handle missing file. | 68 if (!file.existsSync()) return; // TODO(whesse): Handle missing file. |
| 64 FileInputStream file_stream = file.openInputStream(); | 69 FileInputStream file_stream = file.openInputStream(); |
| 65 StringInputStream lines = new StringInputStream(file_stream); | 70 StringInputStream lines = new StringInputStream(file_stream); |
| 66 | 71 |
| 67 Section current = new Section.always(); | 72 Section current = new Section.always(); |
| 68 sections.add(current); | 73 sections.add(current); |
| 69 String prefix = ""; | 74 String prefix = ""; |
| 70 | 75 |
| 71 String line; | 76 lines.lineHandler = () { |
| 72 while ((line = lines.readLine()) != null) { | 77 String line; |
| 73 Match match = StripComment.firstMatch(line); | 78 while ((line = lines.readLine()) != null) { |
| 74 line = (match == null) ? "" : match[0]; | 79 Match match = StripComment.firstMatch(line); |
| 75 line = line.trim(); | 80 line = (match == null) ? "" : match[0]; |
| 76 if (line.isEmpty()) continue; | 81 line = line.trim(); |
| 82 if (line.isEmpty()) continue; |
| 77 | 83 |
| 78 match = HeaderPattern.firstMatch(line); | 84 match = HeaderPattern.firstMatch(line); |
| 79 if (match != null) { | 85 if (match != null) { |
| 80 String condition_string = match[1].trim(); | 86 String condition_string = match[1].trim(); |
| 81 List<String> tokens = new Tokenizer(condition_string).tokenize(); | 87 List<String> tokens = new Tokenizer(condition_string).tokenize(); |
| 82 ExpressionParser parser = new ExpressionParser(new Scanner(tokens)); | 88 ExpressionParser parser = new ExpressionParser(new Scanner(tokens)); |
| 83 current = new Section(parser.parseBooleanExpression()); | 89 current = new Section(parser.parseBooleanExpression()); |
| 84 sections.add(current); | 90 sections.add(current); |
| 85 continue; | 91 continue; |
| 92 } |
| 93 |
| 94 match = RulePattern.firstMatch(line); |
| 95 if (match != null) { |
| 96 String name = match[1].trim(); |
| 97 // TODO(whesse): Handle test names ending in a wildcard (*). |
| 98 String expression_string = match[2].trim(); |
| 99 List<String> tokens = new Tokenizer(expression_string).tokenize(); |
| 100 SetExpression expression = |
| 101 new ExpressionParser(new Scanner(tokens)).parseSetExpression(); |
| 102 current.testRules.add(new TestRule(name, expression)); |
| 103 continue; |
| 104 } |
| 105 |
| 106 match = PrefixPattern.firstMatch(line); |
| 107 if (match != null) { |
| 108 prefix = match[1]; |
| 109 continue; |
| 110 } |
| 111 |
| 112 print("unmatched line: $line"); |
| 86 } | 113 } |
| 114 }; |
| 87 | 115 |
| 88 match = RulePattern.firstMatch(line); | 116 lines.closeHandler = () { |
| 89 if (match != null) { | 117 file_stream.close(); |
| 90 String name = match[1].trim(); | 118 onDone(); |
| 91 // TODO(whesse): Handle test names ending in a wildcard (*). | 119 }; |
| 92 String expression_string = match[2].trim(); | |
| 93 List<String> tokens = new Tokenizer(expression_string).tokenize(); | |
| 94 SetExpression expression = | |
| 95 new ExpressionParser(new Scanner(tokens)).parseSetExpression(); | |
| 96 current.testRules.add(new TestRule(name, expression)); | |
| 97 continue; | |
| 98 } | |
| 99 | |
| 100 match = PrefixPattern.firstMatch(line); | |
| 101 if (match != null) { | |
| 102 prefix = match[1]; | |
| 103 continue; | |
| 104 } | |
| 105 | |
| 106 print("unmatched line: $line"); | |
| 107 } | |
| 108 | |
| 109 file_stream.close(); | |
| 110 } | 120 } |
| 111 | 121 |
| 112 | 122 |
| 113 class TestRule { | 123 class TestRule { |
| 114 String name; | 124 String name; |
| 115 SetExpression expression; | 125 SetExpression expression; |
| 116 | 126 |
| 117 TestRule(this.name, this.expression); | 127 TestRule(this.name, this.expression); |
| 118 } | 128 } |
| 119 | 129 |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 } | 244 } |
| 235 regExps[i] = regExp; | 245 regExps[i] = regExp; |
| 236 } | 246 } |
| 237 _keyToRegExps[key] = regExps; | 247 _keyToRegExps[key] = regExps; |
| 238 }); | 248 }); |
| 239 | 249 |
| 240 _regExpCache = null; | 250 _regExpCache = null; |
| 241 _preprocessed = true; | 251 _preprocessed = true; |
| 242 } | 252 } |
| 243 } | 253 } |
| OLD | NEW |