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

Side by Side Diff: pkg/testing/lib/src/run.dart

Issue 2693893004: Fix two problems with the analyzer suite: (Closed)
Patch Set: Created 3 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 | « no previous file | pkg/testing/lib/src/run_tests.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.md file. 3 // BSD-style license that can be found in the LICENSE.md file.
4 4
5 library testing.run; 5 library testing.run;
6 6
7 import 'dart:async' show 7 import 'dart:async' show
8 Future, 8 Future,
9 Stream; 9 Stream;
10 10
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 /// The optional argument [configurationPath] should be used when 112 /// The optional argument [configurationPath] should be used when
113 /// `testing.json` isn't located in the current working directory and is a path 113 /// `testing.json` isn't located in the current working directory and is a path
114 /// relative to `Uri.base`. 114 /// relative to `Uri.base`.
115 Future<Null> run( 115 Future<Null> run(
116 List<String> arguments, List<String> suiteNames, 116 List<String> arguments, List<String> suiteNames,
117 [String configurationPath]) { 117 [String configurationPath]) {
118 return withErrorHandling(() async { 118 return withErrorHandling(() async {
119 TestRoot root = await computeTestRoot(configurationPath, Uri.base); 119 TestRoot root = await computeTestRoot(configurationPath, Uri.base);
120 List<Suite> suites = root.suites.where( 120 List<Suite> suites = root.suites.where(
121 (Suite suite) => suiteNames.contains(suite.name)).toList(); 121 (Suite suite) => suiteNames.contains(suite.name)).toList();
122 SuiteRunner runner = new SuiteRunner(suites, <String, String>{}, null); 122 SuiteRunner runner = new SuiteRunner(suites, <String, String>{}, null,
123 new Set<String>(), new Set<String>());
123 String program = await runner.generateDartProgram(); 124 String program = await runner.generateDartProgram();
124 await runner.analyze(root.packages); 125 await runner.analyze(root.packages);
125 if (program != null) { 126 if (program != null) {
126 await runProgram(program, root.packages); 127 await runProgram(program, root.packages);
127 } 128 }
128 }); 129 });
129 } 130 }
130 131
131 Future<Null> runProgram(String program, Uri packages) async { 132 Future<Null> runProgram(String program, Uri packages) async {
132 logMessage("Running:"); 133 logMessage("Running:");
(...skipping 18 matching lines...) Expand all
151 : new Future<Null>.error(error[0], new StackTrace.fromString(error[1])); 152 : new Future<Null>.error(error[0], new StackTrace.fromString(error[1]));
152 } 153 }
153 154
154 class SuiteRunner { 155 class SuiteRunner {
155 final List<Suite> suites; 156 final List<Suite> suites;
156 157
157 final Map<String, String> environment; 158 final Map<String, String> environment;
158 159
159 final List<String> selectors; 160 final List<String> selectors;
160 161
161 List<Uri> testUris; 162 final Set<String> selectedSuites;
162 163
163 SuiteRunner(this.suites, this.environment, Iterable<String> selectors) 164 final Set<String> skippedSuites;
165
166 final List<Uri> testUris = <Uri>[];
167
168 SuiteRunner(this.suites, this.environment, Iterable<String> selectors,
169 this.selectedSuites, this.skippedSuites)
164 : selectors = selectors.toList(growable: false); 170 : selectors = selectors.toList(growable: false);
165 171
172 bool shouldRunSuite(Suite suite) {
173 return !skippedSuites.contains(suite.name) &&
174 (selectedSuites.isEmpty || selectedSuites.contains(suite.name));
175 }
176
166 Future<String> generateDartProgram() async { 177 Future<String> generateDartProgram() async {
167 List<TestDescription> descriptions = await list().toList(); 178 testUris.clear();
168 testUris = <Uri>[];
169 StringBuffer imports = new StringBuffer(); 179 StringBuffer imports = new StringBuffer();
170 StringBuffer dart = new StringBuffer(); 180 StringBuffer dart = new StringBuffer();
171 StringBuffer chain = new StringBuffer(); 181 StringBuffer chain = new StringBuffer();
182 bool hasRunnableTests = false;
172 183
173 for (TestDescription description in descriptions) { 184 await for (TestDescription description in listDescriptions()) {
174 testUris.add(await Isolate.resolvePackageUri(description.uri)); 185 hasRunnableTests = true;
175 description.writeImportOn(imports); 186 description.writeImportOn(imports);
176 description.writeClosureOn(dart); 187 description.writeClosureOn(dart);
177 } 188 }
178 189
179 for (Chain suite in suites.where((Suite suite) => suite is Chain)) { 190 await for (Chain suite in listChainSuites()) {
180 testUris.add(await Isolate.resolvePackageUri(suite.source)); 191 hasRunnableTests = true;
181 suite.writeImportOn(imports); 192 suite.writeImportOn(imports);
182 suite.writeClosureOn(chain); 193 suite.writeClosureOn(chain);
183 } 194 }
184 195
185 bool hasTestDartSuite = false; 196 bool isFirstTestDartSuite = true;
186 for (TestDart suite in suites.where((Suite suite) => suite is TestDart)) { 197 for (TestDart suite in listTestDartSuites()) {
187 if (!hasTestDartSuite) { 198 hasRunnableTests = true;
199 if (!isFirstTestDartSuite) {
188 suite.writeFirstImportOn(imports); 200 suite.writeFirstImportOn(imports);
189 } 201 }
190 hasTestDartSuite = true; 202 isFirstTestDartSuite = true;
191 suite.writeRunCommandOn(chain); 203 suite.writeRunCommandOn(chain);
192 } 204 }
193 205
194 if (testUris.isEmpty && !hasTestDartSuite) return null; 206 if (hasRunnableTests) return null;
195 207
196 return """ 208 return """
197 library testing.generated; 209 library testing.generated;
198 210
199 import 'dart:async' show Future; 211 import 'dart:async' show Future;
200 212
201 import 'dart:convert' show JSON; 213 import 'dart:convert' show JSON;
202 214
203 import 'package:testing/src/run_tests.dart' show runTests; 215 import 'package:testing/src/run_tests.dart' show runTests;
204 216
205 import 'package:testing/src/chain.dart' show runChain; 217 import 'package:testing/src/chain.dart' show runChain;
206 218
207 import 'package:testing/src/log.dart' show enableVerboseOutput, isVerbose; 219 import 'package:testing/src/log.dart' show enableVerboseOutput, isVerbose;
208 220
209 ${imports.toString().trim()} 221 ${imports.toString().trim()}
210 222
211 Future<Null> main() async { 223 Future<Null> main() async {
212 if ($isVerbose) enableVerboseOutput(); 224 if ($isVerbose) enableVerboseOutput();
213 Map<String, String> environment = JSON.decode('${JSON.encode(environment)}'); 225 Map<String, String> environment = JSON.decode('${JSON.encode(environment)}');
214 Set<String> selectors = JSON.decode('${JSON.encode(selectors)}').toSet(); 226 Set<String> selectors = JSON.decode('${JSON.encode(selectors)}').toSet();
215 await runTests(<String, Function> { 227 await runTests(<String, Function> {
216 ${splitLines(dart.toString().trim()).join(' ')} 228 ${splitLines(dart.toString().trim()).join(' ')}
217 }); 229 });
218 ${splitLines(chain.toString().trim()).join(' ')} 230 ${splitLines(chain.toString().trim()).join(' ')}
219 } 231 }
220 """; 232 """;
221 } 233 }
222 234
223 Future<Null> analyze(Uri packages) async { 235 Future<bool> analyze(Uri packages) async {
224 for (Analyze suite in suites.where((Suite suite) => suite is Analyze)) { 236 bool hasAnalyzerSuites = false;
237 for (Analyze suite in listAnalyzerSuites()) {
238 hasAnalyzerSuites = true;
225 await suite.run(packages, testUris); 239 await suite.run(packages, testUris);
226 } 240 }
241 return hasAnalyzerSuites;
227 } 242 }
228 243
229 Stream<TestDescription> list() async* { 244 Stream<TestDescription> listDescriptions() async* {
230 for (Dart suite in suites.where((Suite suite) => suite is Dart)) { 245 for (Dart suite in suites.where((Suite suite) => suite is Dart)) {
231 await for (TestDescription description in 246 await for (TestDescription description in
232 listTests(<Uri>[suite.uri], pattern: "")) { 247 listTests(<Uri>[suite.uri], pattern: "")) {
233 String path = description.file.uri.path; 248 testUris.add(await Isolate.resolvePackageUri(description.uri));
234 if (suite.exclude.any((RegExp r) => path.contains(r))) continue; 249 if (shouldRunSuite(suite)) {
235 if (suite.pattern.any((RegExp r) => path.contains(r))) { 250 String path = description.file.uri.path;
236 yield description; 251 if (suite.exclude.any((RegExp r) => path.contains(r))) continue;
252 if (suite.pattern.any((RegExp r) => path.contains(r))) {
253 yield description;
254 }
237 } 255 }
238 } 256 }
239 } 257 }
240 } 258 }
259
260 Stream<Chain> listChainSuites() async* {
261 for (Chain suite in suites.where((Suite suite) => suite is Chain)) {
262 testUris.add(await Isolate.resolvePackageUri(suite.source));
263 if (shouldRunSuite(suite)) {
264 yield suite;
265 }
266 }
267 }
268
269 Iterable<Suite> listTestDartSuites() {
270 return suites.where((Suite suite) => suite is TestDart);
271 }
272
273 Iterable<Suite> listAnalyzerSuites() {
274 return suites.where((Suite suite) => suite is Analyze);
275 }
241 } 276 }
OLDNEW
« no previous file with comments | « no previous file | pkg/testing/lib/src/run_tests.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698