OLD | NEW |
| (Empty) |
1 // Copyright (c) 2016, the Dartino project authors. Please see the AUTHORS file | |
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. | |
4 | |
5 library tests.fletchc.incremental.common; | |
6 | |
7 export 'dart:async' show | |
8 Future; | |
9 | |
10 export 'feature_test.dart' show | |
11 NoArgFuture; | |
12 | |
13 export 'program_result.dart' show | |
14 EncodedResult; | |
15 | |
16 import 'dart:async' show | |
17 Future; | |
18 | |
19 import 'dart:isolate' show | |
20 ReceivePort; | |
21 | |
22 import 'feature_test.dart' show | |
23 NoArgFuture; | |
24 | |
25 import 'program_result.dart' show | |
26 EncodedResult, | |
27 computeTests; | |
28 | |
29 import 'tests_with_expectations.dart' as tests_with_expectations; | |
30 | |
31 abstract class IncrementalTestSuite { | |
32 final String suiteName; | |
33 | |
34 static final Map<String, EncodedResult> allTests = | |
35 computeTests(tests_with_expectations.tests); | |
36 | |
37 const IncrementalTestSuite(this.suiteName); | |
38 | |
39 Future<Map<String, NoArgFuture>> list() { | |
40 return new Future<Map<String, NoArgFuture>>.value(listSync()); | |
41 } | |
42 | |
43 Map<String, NoArgFuture> listSync() { | |
44 Map<String, NoArgFuture> result = <String, NoArgFuture>{}; | |
45 allTests.forEach((String testName, EncodedResult encodedResult) { | |
46 result["incremental/$suiteName/$testName"] = | |
47 () => run(testName, encodedResult); | |
48 }); | |
49 return result; | |
50 } | |
51 | |
52 Future<Null> run(String testName, EncodedResult encodedResult); | |
53 | |
54 Future<Null> runFromMain(List<String> arguments) { | |
55 Map<String, NoArgFuture> tests = listSync(); | |
56 if (arguments.isEmpty) { | |
57 arguments = tests.keys.toList(); | |
58 } | |
59 List<String> missingTests = <String>[]; | |
60 List<NoArgFuture> testsToRun = <NoArgFuture>[]; | |
61 for (String testName in arguments) { | |
62 if (testName.startsWith("$suiteName/")) { | |
63 testName = "incremental/$testName"; | |
64 } else if (!testName.startsWith("incremental/$suiteName/")) { | |
65 testName = "incremental/$suiteName/$testName"; | |
66 } | |
67 NoArgFuture testClosure = tests[testName]; | |
68 if (testClosure == null) { | |
69 missingTests.add(testName); | |
70 } else { | |
71 testsToRun.add(testClosure); | |
72 } | |
73 } | |
74 if (missingTests.isNotEmpty) { | |
75 throw "The following tests couldn't be found: ${missingTests.join(' ')}"; | |
76 } | |
77 Iterator testIterator = testsToRun.iterator; | |
78 if (testIterator.moveNext()) { | |
79 // Create a ReceivePort to ensure the Dart VM doesn't exit before all | |
80 // futures have completed. | |
81 ReceivePort done = new ReceivePort(); | |
82 return Future.doWhile(() async { | |
83 await (testIterator.current)(); | |
84 return testIterator.moveNext(); | |
85 }).whenComplete(() { | |
86 // The test is done, the Dart VM may exit. So we close the port. | |
87 done.close(); | |
88 }); | |
89 } else { | |
90 // This can't happen. | |
91 throw "No tests specified."; | |
92 } | |
93 } | |
94 } | |
OLD | NEW |