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