| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 import 'dart:io'; | 5 import 'dart:io'; |
| 6 | 6 |
| 7 import 'package:boolean_selector/boolean_selector.dart'; | 7 import 'package:boolean_selector/boolean_selector.dart'; |
| 8 import 'package:glob/glob.dart'; | 8 import 'package:glob/glob.dart'; |
| 9 import 'package:path/path.dart' as p; | 9 import 'package:path/path.dart' as p; |
| 10 import 'package:source_span/source_span.dart'; | 10 import 'package:source_span/source_span.dart'; |
| 11 import 'package:yaml/yaml.dart'; | 11 import 'package:yaml/yaml.dart'; |
| 12 | 12 |
| 13 import '../../backend/operating_system.dart'; |
| 13 import '../../backend/platform_selector.dart'; | 14 import '../../backend/platform_selector.dart'; |
| 14 import '../../backend/test_platform.dart'; | 15 import '../../backend/test_platform.dart'; |
| 15 import '../../frontend/timeout.dart'; | 16 import '../../frontend/timeout.dart'; |
| 16 import '../../utils.dart'; | 17 import '../../utils.dart'; |
| 18 import '../../util/io.dart'; |
| 17 import '../configuration.dart'; | 19 import '../configuration.dart'; |
| 18 import 'values.dart'; | 20 import 'values.dart'; |
| 19 | 21 |
| 20 /// Loads configuration information from a YAML file at [path]. | 22 /// Loads configuration information from a YAML file at [path]. |
| 21 /// | 23 /// |
| 22 /// Throws a [FormatException] if the configuration is invalid, and a | 24 /// Throws a [FormatException] if the configuration is invalid, and a |
| 23 /// [FileSystemException] if it can't be read. | 25 /// [FileSystemException] if it can't be read. |
| 24 Configuration load(String path) { | 26 Configuration load(String path) { |
| 25 var source = new File(path).readAsStringSync(); | 27 var source = new File(path).readAsStringSync(); |
| 26 var document = loadYamlNode(source, sourceUrl: p.toUri(path)); | 28 var document = loadYamlNode(source, sourceUrl: p.toUri(path)); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 (value) => value.contains(anchoredHyphenatedIdentifier)); | 83 (value) => value.contains(anchoredHyphenatedIdentifier)); |
| 82 return tagNode.value; | 84 return tagNode.value; |
| 83 }); | 85 }); |
| 84 | 86 |
| 85 var tags = _getMap("tags", | 87 var tags = _getMap("tags", |
| 86 key: (keyNode) => _parseNode(keyNode, "tags key", | 88 key: (keyNode) => _parseNode(keyNode, "tags key", |
| 87 (value) => new BooleanSelector.parse(value)), | 89 (value) => new BooleanSelector.parse(value)), |
| 88 value: (valueNode) => | 90 value: (valueNode) => |
| 89 _nestedConfig(valueNode, "tag value", runnerConfig: false)); | 91 _nestedConfig(valueNode, "tag value", runnerConfig: false)); |
| 90 | 92 |
| 91 return new Configuration( | 93 var onPlatform = _getMap("on_platform", |
| 94 key: (keyNode) => _parseNode(keyNode, "on_platform key", |
| 95 (value) => new PlatformSelector.parse(value)), |
| 96 value: (valueNode) => |
| 97 _nestedConfig(valueNode, "on_platform value", runnerConfig: false)); |
| 98 |
| 99 var onOS = _getMap("on_os", key: (keyNode) { |
| 100 _validate(keyNode, "on_os key must be a string.", |
| 101 (value) => value is String); |
| 102 |
| 103 var os = OperatingSystem.find(keyNode.value); |
| 104 if (os != null) return os; |
| 105 |
| 106 throw new SourceSpanFormatException( |
| 107 'Invalid on_os key: No such operating system.', |
| 108 keyNode.span, _source); |
| 109 }, value: (valueNode) => _nestedConfig(valueNode, "on_os value")); |
| 110 |
| 111 var config = new Configuration( |
| 92 verboseTrace: verboseTrace, | 112 verboseTrace: verboseTrace, |
| 93 jsTrace: jsTrace, | 113 jsTrace: jsTrace, |
| 94 skip: skip, | 114 skip: skip, |
| 95 skipReason: skipReason, | 115 skipReason: skipReason, |
| 96 testOn: testOn, | 116 testOn: testOn, |
| 97 timeout: timeout, | 117 timeout: timeout, |
| 98 addTags: addTags, | 118 addTags: addTags, |
| 99 tags: tags); | 119 tags: tags, |
| 120 onPlatform: onPlatform); |
| 121 |
| 122 var osConfig = onOS[currentOS]; |
| 123 return osConfig == null ? config : config.merge(osConfig); |
| 100 } | 124 } |
| 101 | 125 |
| 102 /// Loads runner configuration (but not test configuration). | 126 /// Loads runner configuration (but not test configuration). |
| 103 /// | 127 /// |
| 104 /// If [_runnerConfig] is `false`, this will error if there are any | 128 /// If [_runnerConfig] is `false`, this will error if there are any |
| 105 /// runner-level configuration fields. | 129 /// runner-level configuration fields. |
| 106 Configuration _loadRunnerConfig() { | 130 Configuration _loadRunnerConfig() { |
| 107 if (!_runnerConfig) { | 131 if (!_runnerConfig) { |
| 108 _disallow("reporter"); | 132 _disallow("reporter"); |
| 109 _disallow("pub_serve"); | 133 _disallow("pub_serve"); |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 if (!_document.containsKey(field)) return; | 300 if (!_document.containsKey(field)) return; |
| 277 _error("$field isn't supported here.", field); | 301 _error("$field isn't supported here.", field); |
| 278 } | 302 } |
| 279 | 303 |
| 280 /// Throws a [SourceSpanFormatException] with [message] about [field]. | 304 /// Throws a [SourceSpanFormatException] with [message] about [field]. |
| 281 void _error(String message, String field) { | 305 void _error(String message, String field) { |
| 282 throw new SourceSpanFormatException( | 306 throw new SourceSpanFormatException( |
| 283 message, _document.nodes[field].span, _source); | 307 message, _document.nodes[field].span, _source); |
| 284 } | 308 } |
| 285 } | 309 } |
| OLD | NEW |