OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 library unittest.runner.loader; | 5 library unittest.runner.loader; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:io'; | 8 import 'dart:io'; |
9 import 'dart:isolate'; | 9 import 'dart:isolate'; |
10 | 10 |
| 11 import 'package:analyzer/analyzer.dart'; |
11 import 'package:path/path.dart' as p; | 12 import 'package:path/path.dart' as p; |
12 | 13 |
| 14 import '../backend/metadata.dart'; |
13 import '../backend/suite.dart'; | 15 import '../backend/suite.dart'; |
14 import '../backend/test_platform.dart'; | 16 import '../backend/test_platform.dart'; |
15 import '../util/dart.dart'; | 17 import '../util/dart.dart'; |
16 import '../util/io.dart'; | 18 import '../util/io.dart'; |
17 import '../util/remote_exception.dart'; | 19 import '../util/remote_exception.dart'; |
18 import '../utils.dart'; | 20 import '../utils.dart'; |
19 import 'browser/server.dart'; | 21 import 'browser/server.dart'; |
20 import 'load_exception.dart'; | 22 import 'load_exception.dart'; |
| 23 import 'parse_metadata.dart'; |
21 import 'vm/isolate_test.dart'; | 24 import 'vm/isolate_test.dart'; |
22 | 25 |
23 /// A class for finding test files and loading them into a runnable form. | 26 /// A class for finding test files and loading them into a runnable form. |
24 class Loader { | 27 class Loader { |
25 /// All platforms for which tests should be loaded. | 28 /// All platforms for which tests should be loaded. |
26 final List<TestPlatform> _platforms; | 29 final List<TestPlatform> _platforms; |
27 | 30 |
28 /// Whether to enable colors for Dart compilation. | 31 /// Whether to enable colors for Dart compilation. |
29 final bool _color; | 32 final bool _color; |
30 | 33 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 // TODO(nweiz): Provide a way for the caller to gracefully handle some | 78 // TODO(nweiz): Provide a way for the caller to gracefully handle some |
76 // suites failing to load without stopping the rest. | 79 // suites failing to load without stopping the rest. |
77 return loadFile(entry.path); | 80 return loadFile(entry.path); |
78 })).then((suites) => flatten(suites)); | 81 })).then((suites) => flatten(suites)); |
79 } | 82 } |
80 | 83 |
81 /// Loads a test suite from the file at [path]. | 84 /// Loads a test suite from the file at [path]. |
82 /// | 85 /// |
83 /// This will throw a [LoadException] if the file fails to load. | 86 /// This will throw a [LoadException] if the file fails to load. |
84 Future<List<Suite>> loadFile(String path) { | 87 Future<List<Suite>> loadFile(String path) { |
| 88 var metadata; |
| 89 try { |
| 90 metadata = parseMetadata(path); |
| 91 } on AnalyzerErrorGroup catch (_) { |
| 92 // Ignore the analyzer's error, since its formatting is much worse than |
| 93 // the VM's or dart2js's. |
| 94 metadata = new Metadata(); |
| 95 } on FormatException catch (error) { |
| 96 throw new LoadException(path, error); |
| 97 } |
| 98 |
85 return Future.wait(_platforms.map((platform) { | 99 return Future.wait(_platforms.map((platform) { |
86 if (platform == TestPlatform.chrome) return _loadBrowserFile(path); | 100 return new Future.sync(() { |
87 assert(platform == TestPlatform.vm); | 101 if (!metadata.testOn.evaluate(platform, os: currentOS)) return null; |
88 return _loadVmFile(path); | 102 |
89 })); | 103 if (platform == TestPlatform.chrome) return _loadBrowserFile(path); |
| 104 assert(platform == TestPlatform.vm); |
| 105 return _loadVmFile(path); |
| 106 }).then((suite) => |
| 107 suite == null ? null : suite.change(metadata: metadata)); |
| 108 })).then((suites) => suites.where((suite) => suite != null).toList()); |
90 } | 109 } |
91 | 110 |
92 /// Load the test suite at [path] in a browser. | 111 /// Load the test suite at [path] in a browser. |
93 Future<Suite> _loadBrowserFile(String path) => | 112 Future<Suite> _loadBrowserFile(String path) => |
94 _browserServer.then((browserServer) => browserServer.loadSuite(path)); | 113 _browserServer.then((browserServer) => browserServer.loadSuite(path)); |
95 | 114 |
96 /// Load the test suite at [path] in VM isolate. | 115 /// Load the test suite at [path] in VM isolate. |
97 Future<Suite> _loadVmFile(String path) { | 116 Future<Suite> _loadVmFile(String path) { |
98 var packageRoot = packageRootFor(path, _packageRoot); | 117 var packageRoot = packageRootFor(path, _packageRoot); |
99 var receivePort = new ReceivePort(); | 118 var receivePort = new ReceivePort(); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 Future close() { | 154 Future close() { |
136 for (var isolate in _isolates) { | 155 for (var isolate in _isolates) { |
137 isolate.kill(); | 156 isolate.kill(); |
138 } | 157 } |
139 _isolates.clear(); | 158 _isolates.clear(); |
140 | 159 |
141 if (_browserServerCompleter == null) return new Future.value(); | 160 if (_browserServerCompleter == null) return new Future.value(); |
142 return _browserServer.then((browserServer) => browserServer.close()); | 161 return _browserServer.then((browserServer) => browserServer.close()); |
143 } | 162 } |
144 } | 163 } |
OLD | NEW |