Chromium Code Reviews| Index: tools/testing/dart/status_file.dart |
| diff --git a/tools/testing/dart/status_file.dart b/tools/testing/dart/status_file.dart |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..3416d3240a9290b58309d8701b6ca4876fdb1b8a |
| --- /dev/null |
| +++ b/tools/testing/dart/status_file.dart |
| @@ -0,0 +1,83 @@ |
| +// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
| +// for details. All rights reserved. Use of this source code is governed by a |
| +// BSD-style license that can be found in the LICENSE file. |
| + |
| +#library("status_file"); |
|
Mads Ager (google)
2011/10/31 16:05:20
status_file_parser maybe?
Bill Hesse
2011/11/02 10:15:44
Done.
|
| + |
| + |
| +#import("status_expression.dart"); |
| + |
| +final RegExp StripComment = const RegExp("^[^#]*"); |
| +final RegExp HeaderPattern = const RegExp(@"\[([^\]]+)\]"); |
| +final RegExp RulePattern = const RegExp(@"\s*([^: ]*)\s*:(.*)"); |
| +final RegExp PrefixPattern = const RegExp(@"^\s*prefix\s+([\w\_\.\-\/]+)\s*$"); |
| + |
| +// TODO(whesse): Implement configuration_info library that contains data |
| +// structures for test configuration, including Section. |
| +class Section { |
| + BooleanExpression condition; |
| + |
| + Section.always() : condition = null; |
| + Section(this.condition); |
| +} |
| + |
| + |
| +// Helper method to be able to run the test from the runtime |
| +// directory, or the top directory. |
| +String getFilename(String path) => |
| + new File(path).existsSync() ? path : '../$path'; |
| + |
| +String SplitPath(String path) => path; |
|
Mads Ager (google)
2011/10/31 16:05:20
Could you comment on this identity function. Is th
Bill Hesse
2011/11/02 10:15:44
Done.
|
| + |
| +void ReadConfigurationInto(path, sections) { |
| + File file = new File(getFilename(path)); |
| + Expect.isTrue(file.existsSync()); // TODO(whesse): Handle missing file. |
| + FileInputStream file_stream = file.openInputStream(); |
| + StringInputStream lines = new StringInputStream(file_stream); |
| + |
| + Section current = new Section.always(); |
| + sections.add(current); |
| + String prefix = ""; |
| + |
|
Mads Ager (google)
2011/10/31 16:05:20
Remove extra blank line?
Bill Hesse
2011/11/02 10:15:44
Done.
|
| + |
| + while (true) { |
|
Mads Ager (google)
2011/10/31 16:05:20
We could do something like:
String line;
while ((
Bill Hesse
2011/11/02 10:15:44
Done.
|
| + String line = lines.readLine(); |
| + if (line == null) break; |
| + Match match = StripComment.firstMatch(line); |
| + line = (match == null) ? "" : match[0]; |
| + line = line.trim(); |
| + if (line == "") continue; |
| + |
| + match = HeaderPattern.firstMatch(line); |
| + if (match != null) { |
| + String condition_string = match[1].trim(); |
| + List<String> tokens = new Tokenizer(condition_string).tokenize(); |
| + ExpressionParser parser = new ExpressionParser(new Scanner(tokens)); |
| + current = new Section(parser.parseBooleanExpression()); |
| + sections.add(current); |
| + continue; |
| + } |
| + |
| + match = RulePattern.firstMatch(line); |
| + if (match != null) { |
| + String path = prefix + SplitPath(match[1].trim()); |
|
Mads Ager (google)
2011/10/31 16:05:20
Since SplitPath is the identify function, I would
Bill Hesse
2011/11/02 10:15:44
Done.
|
| + String expression_string = match[2].trim(); |
| + List<String> tokens = new Tokenizer(expression_string).tokenize(); |
| + SetExpression expression = |
| + new ExpressionParser(new Scanner(tokens)).parseSetExpression(); |
| + // TODO(whesse): Save rule in configuration data structure. |
| + continue; |
| + } |
| + |
| + match = PrefixPattern.firstMatch(line); |
| + if (match != null) { |
| + prefix = SplitPath(match[1]); |
|
Mads Ager (google)
2011/10/31 16:05:20
Add a TODO here as well?
Bill Hesse
2011/11/02 10:15:44
Done.
|
| + continue; |
| + } |
| + |
| + print("unmatched line: $line"); |
| + } |
| + |
| + file_stream.close(); |
| +} |
| + |