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.md file. | 3 // BSD-style license that can be found in the LICENSE.md file. |
4 | 4 |
5 library testing.chain; | 5 library testing.chain; |
6 | 6 |
7 import 'dart:async' show | 7 import 'dart:async' show Future, Stream; |
8 Future, | |
9 Stream; | |
10 | 8 |
11 import 'dart:convert' show | 9 import 'dart:convert' show JSON, JsonEncoder; |
12 JSON, | |
13 JsonEncoder; | |
14 | 10 |
15 import 'dart:io' show | 11 import 'dart:io' show Directory, File, FileSystemEntity, exitCode; |
16 Directory, | |
17 File, | |
18 FileSystemEntity, | |
19 exitCode; | |
20 | 12 |
21 import 'suite.dart' show | 13 import 'suite.dart' show Suite; |
22 Suite; | |
23 | 14 |
24 import '../testing.dart' show | 15 import '../testing.dart' show TestDescription; |
25 TestDescription; | |
26 | 16 |
27 import 'test_dart/status_file_parser.dart' show | 17 import 'test_dart/status_file_parser.dart' |
28 ReadTestExpectations, | 18 show ReadTestExpectations, TestExpectations; |
29 TestExpectations; | |
30 | 19 |
31 import 'zone_helper.dart' show | 20 import 'zone_helper.dart' show runGuarded; |
32 runGuarded; | |
33 | 21 |
34 import 'error_handling.dart' show | 22 import 'error_handling.dart' show withErrorHandling; |
35 withErrorHandling; | |
36 | 23 |
37 import 'log.dart' show | 24 import 'log.dart' |
38 logMessage, | 25 show |
39 logStepComplete, | 26 logMessage, |
40 logStepStart, | 27 logStepComplete, |
41 logSuiteComplete, | 28 logStepStart, |
42 logTestComplete, | 29 logSuiteComplete, |
43 logUnexpectedResult, | 30 logTestComplete, |
44 splitLines; | 31 logUnexpectedResult, |
| 32 splitLines; |
45 | 33 |
46 import 'multitest.dart' show | 34 import 'multitest.dart' show MultitestTransformer, isError; |
47 MultitestTransformer, | |
48 isError; | |
49 | 35 |
50 import 'expectation.dart' show | 36 import 'expectation.dart' show Expectation, ExpectationSet; |
51 Expectation, | |
52 ExpectationSet; | |
53 | 37 |
54 typedef Future<ChainContext> CreateContext( | 38 typedef Future<ChainContext> CreateContext( |
55 Chain suite, Map<String, String> environment); | 39 Chain suite, Map<String, String> environment); |
56 | 40 |
57 /// A test suite for tool chains, for example, a compiler. | 41 /// A test suite for tool chains, for example, a compiler. |
58 class Chain extends Suite { | 42 class Chain extends Suite { |
59 final Uri source; | 43 final Uri source; |
60 | 44 |
61 final Uri uri; | 45 final Uri uri; |
62 | 46 |
63 final List<RegExp> pattern; | 47 final List<RegExp> pattern; |
64 | 48 |
65 final List<RegExp> exclude; | 49 final List<RegExp> exclude; |
66 | 50 |
67 final bool processMultitests; | 51 final bool processMultitests; |
68 | 52 |
69 Chain(String name, String kind, this.source, this.uri, Uri statusFile, | 53 Chain(String name, String kind, this.source, this.uri, Uri statusFile, |
70 this.pattern, this.exclude, this.processMultitests) | 54 this.pattern, this.exclude, this.processMultitests) |
71 : super(name, kind, statusFile); | 55 : super(name, kind, statusFile); |
72 | 56 |
73 factory Chain.fromJsonMap(Uri base, Map json, String name, String kind) { | 57 factory Chain.fromJsonMap(Uri base, Map json, String name, String kind) { |
74 Uri source = base.resolve(json["source"]); | 58 Uri source = base.resolve(json["source"]); |
75 Uri uri = base.resolve(json["path"]); | 59 Uri uri = base.resolve(json["path"]); |
76 Uri statusFile = base.resolve(json["status"]); | 60 Uri statusFile = base.resolve(json["status"]); |
77 List<RegExp> pattern = new List<RegExp>.from( | 61 List<RegExp> pattern = |
78 json["pattern"].map((String p) => new RegExp(p))); | 62 new List<RegExp>.from(json["pattern"].map((String p) => new RegExp(p))); |
79 List<RegExp> exclude = new List<RegExp>.from( | 63 List<RegExp> exclude = |
80 json["exclude"].map((String p) => new RegExp(p))); | 64 new List<RegExp>.from(json["exclude"].map((String p) => new RegExp(p))); |
81 bool processMultitests = json["process-multitests"] ?? false; | 65 bool processMultitests = json["process-multitests"] ?? false; |
82 return new Chain(name, kind, source, uri, statusFile, pattern, exclude, | 66 return new Chain(name, kind, source, uri, statusFile, pattern, exclude, |
83 processMultitests); | 67 processMultitests); |
84 } | 68 } |
85 | 69 |
86 void writeImportOn(StringSink sink) { | 70 void writeImportOn(StringSink sink) { |
87 sink.write("import '"); | 71 sink.write("import '"); |
88 sink.write(source); | 72 sink.write(source); |
89 sink.write("' as "); | 73 sink.write("' as "); |
90 sink.write(name); | 74 sink.write(name); |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 logTestComplete(++completed, unexpectedResults.length, | 212 logTestComplete(++completed, unexpectedResults.length, |
229 descriptions.length, suite, description); | 213 descriptions.length, suite, description); |
230 }); | 214 }); |
231 if (isAsync) { | 215 if (isAsync) { |
232 futures.add(future); | 216 futures.add(future); |
233 return null; | 217 return null; |
234 } else { | 218 } else { |
235 return future; | 219 return future; |
236 } | 220 } |
237 } | 221 } |
| 222 |
238 // The input of the first step is [description]. | 223 // The input of the first step is [description]. |
239 await doStep(description); | 224 await doStep(description); |
240 } | 225 } |
241 await Future.wait(futures); | 226 await Future.wait(futures); |
242 logSuiteComplete(); | 227 logSuiteComplete(); |
243 if (unexpectedResults.isNotEmpty) { | 228 if (unexpectedResults.isNotEmpty) { |
244 unexpectedResults.forEach((TestDescription description, Result result) { | 229 unexpectedResults.forEach((TestDescription description, Result result) { |
245 logUnexpectedResult(suite, description, result, | 230 logUnexpectedResult( |
246 unexpectedOutcomes[description]); | 231 suite, description, result, unexpectedOutcomes[description]); |
247 }); | 232 }); |
248 print("${unexpectedResults.length} failed:"); | 233 print("${unexpectedResults.length} failed:"); |
249 unexpectedResults.forEach((TestDescription description, Result result) { | 234 unexpectedResults.forEach((TestDescription description, Result result) { |
250 print("${suite.name}/${description.shortName}: ${result.outcome}"); | 235 print("${suite.name}/${description.shortName}: ${result.outcome}"); |
251 }); | 236 }); |
252 } | 237 } |
253 } | 238 } |
254 | 239 |
255 Stream<TestDescription> list(Chain suite) async* { | 240 Stream<TestDescription> list(Chain suite) async* { |
256 Directory testRoot = new Directory.fromUri(suite.uri); | 241 Directory testRoot = new Directory.fromUri(suite.uri); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
322 final Expectation outcome; | 307 final Expectation outcome; |
323 | 308 |
324 final error; | 309 final error; |
325 | 310 |
326 final StackTrace trace; | 311 final StackTrace trace; |
327 | 312 |
328 final List<String> logs = <String>[]; | 313 final List<String> logs = <String>[]; |
329 | 314 |
330 Result(this.output, this.outcome, this.error, this.trace); | 315 Result(this.output, this.outcome, this.error, this.trace); |
331 | 316 |
332 Result.pass(O output) | 317 Result.pass(O output) : this(output, Expectation.Pass, null, null); |
333 : this(output, Expectation.Pass, null, null); | |
334 | 318 |
335 Result.crash(error, StackTrace trace) | 319 Result.crash(error, StackTrace trace) |
336 : this(null, Expectation.Crash, error, trace); | 320 : this(null, Expectation.Crash, error, trace); |
337 | 321 |
338 Result.fail(O output, [error, StackTrace trace]) | 322 Result.fail(O output, [error, StackTrace trace]) |
339 : this(output, Expectation.Fail, error, trace); | 323 : this(output, Expectation.Fail, error, trace); |
340 | 324 |
341 String get log => logs.join(); | 325 String get log => logs.join(); |
342 | 326 |
343 void addLog(String log) { | 327 void addLog(String log) { |
344 logs.add(log); | 328 logs.add(log); |
345 } | 329 } |
346 | 330 |
347 Result<O> copyWithOutcome(Expectation outcome) { | 331 Result<O> copyWithOutcome(Expectation outcome) { |
348 return new Result<O>(output, outcome, error, trace) | 332 return new Result<O>(output, outcome, error, trace)..logs.addAll(logs); |
349 ..logs.addAll(logs); | |
350 } | 333 } |
351 } | 334 } |
352 | 335 |
353 /// This is called from generated code. | 336 /// This is called from generated code. |
354 Future<Null> runChain( | 337 Future<Null> runChain(CreateContext f, Map<String, String> environment, |
355 CreateContext f, Map<String, String> environment, Set<String> selectors, | 338 Set<String> selectors, String json) { |
356 String json) { | |
357 return withErrorHandling(() async { | 339 return withErrorHandling(() async { |
358 Chain suite = new Suite.fromJsonMap(Uri.base, JSON.decode(json)); | 340 Chain suite = new Suite.fromJsonMap(Uri.base, JSON.decode(json)); |
359 print("Running ${suite.name}"); | 341 print("Running ${suite.name}"); |
360 ChainContext context = await f(suite, environment); | 342 ChainContext context = await f(suite, environment); |
361 return context.run(suite, selectors); | 343 return context.run(suite, selectors); |
362 }); | 344 }); |
363 } | 345 } |
OLD | NEW |