| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 import "dart:async"; | |
| 8 import "dart:io"; | 7 import "dart:io"; |
| 9 import "status_expression.dart"; | 8 import "status_expression.dart"; |
| 10 | 9 |
| 11 /** Possible outcomes of running a test. */ | 10 /** Possible outcomes of running a test. */ |
| 12 const CRASH = "crash"; | 11 const CRASH = "crash"; |
| 13 const TIMEOUT = "timeout"; | 12 const TIMEOUT = "timeout"; |
| 14 const FAIL = "fail"; | 13 const FAIL = "fail"; |
| 15 const PASS = "pass"; | 14 const PASS = "pass"; |
| 16 /** | 15 /** |
| 17 * An indication to skip the test. The caller is responsible for skipping it. | 16 * An indication to skip the test. The caller is responsible for skipping it. |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 } | 58 } |
| 60 | 59 |
| 61 ReadConfigurationInto(statusFilePath, sections, sectionsRead); | 60 ReadConfigurationInto(statusFilePath, sections, sectionsRead); |
| 62 } | 61 } |
| 63 | 62 |
| 64 void ReadConfigurationInto(path, sections, onDone) { | 63 void ReadConfigurationInto(path, sections, onDone) { |
| 65 File file = new File(path); | 64 File file = new File(path); |
| 66 if (!file.existsSync()) { | 65 if (!file.existsSync()) { |
| 67 throw new Exception('Cannot find test status file $path'); | 66 throw new Exception('Cannot find test status file $path'); |
| 68 } | 67 } |
| 69 Stream<String> lines = | 68 InputStream file_stream = file.openInputStream(); |
| 70 file.openRead() | 69 StringInputStream lines = new StringInputStream(file_stream); |
| 71 .transform(new StringDecoder()) | |
| 72 .transform(new LineTransformer()); | |
| 73 | 70 |
| 74 Section current = new Section.always(); | 71 Section current = new Section.always(); |
| 75 sections.add(current); | 72 sections.add(current); |
| 76 | 73 |
| 77 lines.listen((String line) { | 74 lines.onLine = () { |
| 78 Match match = StripComment.firstMatch(line); | 75 String line; |
| 79 line = (match == null) ? "" : match[0]; | 76 while ((line = lines.readLine()) != null) { |
| 80 line = line.trim(); | 77 Match match = StripComment.firstMatch(line); |
| 81 if (line.isEmpty) return; | 78 line = (match == null) ? "" : match[0]; |
| 79 line = line.trim(); |
| 80 if (line.isEmpty) continue; |
| 82 | 81 |
| 83 match = HeaderPattern.firstMatch(line); | 82 match = HeaderPattern.firstMatch(line); |
| 84 if (match != null) { | 83 if (match != null) { |
| 85 String condition_string = match[1].trim(); | 84 String condition_string = match[1].trim(); |
| 86 List<String> tokens = new Tokenizer(condition_string).tokenize(); | 85 List<String> tokens = new Tokenizer(condition_string).tokenize(); |
| 87 ExpressionParser parser = new ExpressionParser(new Scanner(tokens)); | 86 ExpressionParser parser = new ExpressionParser(new Scanner(tokens)); |
| 88 current = new Section(parser.parseBooleanExpression()); | 87 current = new Section(parser.parseBooleanExpression()); |
| 89 sections.add(current); | 88 sections.add(current); |
| 90 return; | 89 continue; |
| 90 } |
| 91 |
| 92 match = RulePattern.firstMatch(line); |
| 93 if (match != null) { |
| 94 String name = match[1].trim(); |
| 95 // TODO(whesse): Handle test names ending in a wildcard (*). |
| 96 String expression_string = match[2].trim(); |
| 97 List<String> tokens = new Tokenizer(expression_string).tokenize(); |
| 98 SetExpression expression = |
| 99 new ExpressionParser(new Scanner(tokens)).parseSetExpression(); |
| 100 current.testRules.add(new TestRule(name, expression)); |
| 101 continue; |
| 102 } |
| 103 |
| 104 print("unmatched line: $line"); |
| 91 } | 105 } |
| 106 }; |
| 92 | 107 |
| 93 match = RulePattern.firstMatch(line); | 108 lines.onClosed = () { |
| 94 if (match != null) { | 109 onDone(); |
| 95 String name = match[1].trim(); | 110 }; |
| 96 // TODO(whesse): Handle test names ending in a wildcard (*). | |
| 97 String expression_string = match[2].trim(); | |
| 98 List<String> tokens = new Tokenizer(expression_string).tokenize(); | |
| 99 SetExpression expression = | |
| 100 new ExpressionParser(new Scanner(tokens)).parseSetExpression(); | |
| 101 current.testRules.add(new TestRule(name, expression)); | |
| 102 return; | |
| 103 } | |
| 104 | |
| 105 print("unmatched line: $line"); | |
| 106 }, | |
| 107 onDone: onDone); | |
| 108 } | 111 } |
| 109 | 112 |
| 110 | 113 |
| 111 class TestRule { | 114 class TestRule { |
| 112 String name; | 115 String name; |
| 113 SetExpression expression; | 116 SetExpression expression; |
| 114 | 117 |
| 115 TestRule(this.name, this.expression); | 118 TestRule(this.name, this.expression); |
| 116 | 119 |
| 117 String toString() => 'TestRule($name, $expression)'; | 120 String toString() => 'TestRule($name, $expression)'; |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 } | 206 } |
| 204 regExps[i] = regExp; | 207 regExps[i] = regExp; |
| 205 } | 208 } |
| 206 _keyToRegExps[key] = regExps; | 209 _keyToRegExps[key] = regExps; |
| 207 }); | 210 }); |
| 208 | 211 |
| 209 _regExpCache = null; | 212 _regExpCache = null; |
| 210 _preprocessed = true; | 213 _preprocessed = true; |
| 211 } | 214 } |
| 212 } | 215 } |
| OLD | NEW |