Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(186)

Side by Side Diff: lib/src/runner/configuration/load.dart

Issue 1668573003: Add configuration support for choosing test paths. (Closed) Base URL: git@github.com:dart-lang/test@master
Patch Set: cr Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « lib/src/runner/configuration.dart ('k') | lib/src/runner/configuration/values.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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:glob/glob.dart';
7 import 'package:path/path.dart' as p; 8 import 'package:path/path.dart' as p;
8 import 'package:source_span/source_span.dart'; 9 import 'package:source_span/source_span.dart';
9 import 'package:yaml/yaml.dart'; 10 import 'package:yaml/yaml.dart';
10 11
11 import '../../utils.dart'; 12 import '../../utils.dart';
12 import '../../frontend/timeout.dart'; 13 import '../../frontend/timeout.dart';
13 import '../../backend/test_platform.dart'; 14 import '../../backend/test_platform.dart';
14 import '../configuration.dart'; 15 import '../configuration.dart';
15 import 'values.dart'; 16 import 'values.dart';
16 17
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 TestPlatform.all.map((platform) => platform.identifier).toSet(); 64 TestPlatform.all.map((platform) => platform.identifier).toSet();
64 var platforms = _getList("platforms", (platformNode) { 65 var platforms = _getList("platforms", (platformNode) {
65 _validate(platformNode, "Platforms must be strings.", 66 _validate(platformNode, "Platforms must be strings.",
66 (value) => value is String); 67 (value) => value is String);
67 _validate(platformNode, 'Unknown platform "${platformNode.value}".', 68 _validate(platformNode, 'Unknown platform "${platformNode.value}".',
68 allPlatformIdentifiers.contains); 69 allPlatformIdentifiers.contains);
69 70
70 return TestPlatform.find(platformNode.value); 71 return TestPlatform.find(platformNode.value);
71 }); 72 });
72 73
73 // TODO(nweiz): Add support for using globs to define defaults paths to run. 74 var paths = _getList("paths", (pathNode) {
75 _validate(pathNode, "Paths must be strings.", (value) => value is String);
76 _validate(pathNode, "Paths must be relative.", p.url.isRelative);
77
78 return _parseNode(pathNode, "path", p.fromUri);
79 });
80
81 var filename = _parseValue("filename", (value) => new Glob(value));
74 82
75 return new Configuration( 83 return new Configuration(
76 verboseTrace: verboseTrace, 84 verboseTrace: verboseTrace,
77 jsTrace: jsTrace, 85 jsTrace: jsTrace,
78 reporter: reporter, 86 reporter: reporter,
79 pubServePort: pubServePort, 87 pubServePort: pubServePort,
80 concurrency: concurrency, 88 concurrency: concurrency,
81 timeout: timeout, 89 timeout: timeout,
82 platforms: platforms); 90 platforms: platforms,
91 paths: paths,
92 filename: filename);
83 } 93 }
84 94
85 /// Throws an exception with [message] if [test] returns `false` when passed 95 /// Throws an exception with [message] if [test] returns `false` when passed
86 /// [node]'s value. 96 /// [node]'s value.
87 void _validate(YamlNode node, String message, bool test(value)) { 97 void _validate(YamlNode node, String message, bool test(value)) {
88 if (test(node.value)) return; 98 if (test(node.value)) return;
89 throw new SourceSpanFormatException(message, node.span, _source); 99 throw new SourceSpanFormatException(message, node.span, _source);
90 } 100 }
91 101
92 /// Returns the value of the node at [field]. 102 /// Returns the value of the node at [field].
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 /// Asserts that [field] is a list and runs [forElement] for each element it 135 /// Asserts that [field] is a list and runs [forElement] for each element it
126 /// contains. 136 /// contains.
127 /// 137 ///
128 /// Returns a list of values returned by [forElement]. 138 /// Returns a list of values returned by [forElement].
129 List _getList(String field, forElement(YamlNode elementNode)) { 139 List _getList(String field, forElement(YamlNode elementNode)) {
130 var node = _getNode(field, "list", (value) => value is List); 140 var node = _getNode(field, "list", (value) => value is List);
131 if (node == null) return []; 141 if (node == null) return [];
132 return node.nodes.map(forElement).toList(); 142 return node.nodes.map(forElement).toList();
133 } 143 }
134 144
145 /// Asserts that [node] is a string, passes its value to [parse], and returns
146 /// the result.
147 ///
148 /// If [parse] throws a [FormatException], it's wrapped to include [node]'s
149 /// span.
150 _parseNode(YamlNode node, String name, parse(String value)) {
151 _validate(node, "$name must be a string.", (value) => value is String);
152
153 try {
154 return parse(node.value);
155 } on FormatException catch (error) {
156 throw new SourceSpanFormatException(
157 'Invalid $name: ${error.message}', node.span, _source);
158 }
159 }
160
135 /// Asserts that [field] is a string, passes it to [parse], and returns the 161 /// Asserts that [field] is a string, passes it to [parse], and returns the
136 /// result. 162 /// result.
137 /// 163 ///
138 /// If [parse] throws a [FormatException], it's wrapped to include [field]'s 164 /// If [parse] throws a [FormatException], it's wrapped to include [field]'s
139 /// span. 165 /// span.
140 _parseValue(String field, parse(value)) { 166 _parseValue(String field, parse(String value)) {
141 var value = _getString(field); 167 var node = _document.nodes[field];
142 if (value == null) return null; 168 if (node == null) return null;
143 169 return _parseNode(node, field, parse);
144 try {
145 return parse(value);
146 } on FormatException catch (error) {
147 _error('Invalid $field: ${error.message}', field);
148 }
149 } 170 }
150 171
151 /// Throws a [SourceSpanFormatException] with [message] about [field]. 172 /// Throws a [SourceSpanFormatException] with [message] about [field].
152 void _error(String message, String field) { 173 void _error(String message, String field) {
153 throw new SourceSpanFormatException( 174 throw new SourceSpanFormatException(
154 message, _document.nodes[field].span, _source); 175 message, _document.nodes[field].span, _source);
155 } 176 }
156 } 177 }
OLDNEW
« no previous file with comments | « lib/src/runner/configuration.dart ('k') | lib/src/runner/configuration/values.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698