Chromium Code Reviews| 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 test.runner.loader; | 5 library test.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 |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 22 import '../utils.dart'; | 22 import '../utils.dart'; |
| 23 import 'configuration.dart'; | 23 import 'configuration.dart'; |
| 24 import 'browser/server.dart'; | 24 import 'browser/server.dart'; |
| 25 import 'load_exception.dart'; | 25 import 'load_exception.dart'; |
| 26 import 'load_suite.dart'; | 26 import 'load_suite.dart'; |
| 27 import 'parse_metadata.dart'; | 27 import 'parse_metadata.dart'; |
| 28 import 'runner_suite.dart'; | 28 import 'runner_suite.dart'; |
| 29 import 'vm/environment.dart'; | 29 import 'vm/environment.dart'; |
| 30 import 'vm/isolate_test.dart'; | 30 import 'vm/isolate_test.dart'; |
| 31 | 31 |
| 32 typedef Future<RunnerSuite> LoadVMFileHook(String path, Metadata metadata, | |
| 33 Configuration config); | |
| 34 | |
| 32 /// A class for finding test files and loading them into a runnable form. | 35 /// A class for finding test files and loading them into a runnable form. |
| 33 class Loader { | 36 class Loader { |
| 37 /// **Do not set or use this function without express permission from the test | |
| 38 /// package authors**. | |
| 39 /// | |
| 40 /// A function that overrides the loader's default behavior for loading test | |
| 41 /// suites on the Dart VM. This function takes the path to the file, the | |
| 42 /// file's metadata, and the test runner's configuration and returns a | |
| 43 /// [RunnerSuite] for that file. | |
| 44 static LoadVMFileHook loadVMFileHook; | |
|
Bob Nystrom
2015/08/20 22:04:47
Maybe put this in a separate scary-named library?
nweiz
2015/08/20 22:19:02
Done. Not attaching it to Loader will also make li
| |
| 45 | |
| 34 /// The test runner configuration. | 46 /// The test runner configuration. |
| 35 final Configuration _config; | 47 final Configuration _config; |
| 36 | 48 |
| 37 /// The root directory that will be served for browser tests. | 49 /// The root directory that will be served for browser tests. |
| 38 final String _root; | 50 final String _root; |
| 39 | 51 |
| 40 /// All suites that have been created by the loader. | 52 /// All suites that have been created by the loader. |
| 41 final _suites = new Set<RunnerSuite>(); | 53 final _suites = new Set<RunnerSuite>(); |
| 42 | 54 |
| 43 /// The server that serves browser test pages. | 55 /// The server that serves browser test pages. |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 137 /// | 149 /// |
| 138 /// [metadata] is the suite-level metadata for the test. | 150 /// [metadata] is the suite-level metadata for the test. |
| 139 Future<RunnerSuite> _loadBrowserFile(String path, TestPlatform platform, | 151 Future<RunnerSuite> _loadBrowserFile(String path, TestPlatform platform, |
| 140 Metadata metadata) async => | 152 Metadata metadata) async => |
| 141 (await _browserServer).loadSuite(path, platform, metadata); | 153 (await _browserServer).loadSuite(path, platform, metadata); |
| 142 | 154 |
| 143 /// Load the test suite at [path] in VM isolate. | 155 /// Load the test suite at [path] in VM isolate. |
| 144 /// | 156 /// |
| 145 /// [metadata] is the suite-level metadata for the test. | 157 /// [metadata] is the suite-level metadata for the test. |
| 146 Future<RunnerSuite> _loadVmFile(String path, Metadata metadata) async { | 158 Future<RunnerSuite> _loadVmFile(String path, Metadata metadata) async { |
| 159 if (Loader.loadVMFileHook != null) { | |
| 160 var suite = await Loader.loadVMFileHook(path, metadata, _config); | |
| 161 _suites.add(suite); | |
| 162 return suite; | |
| 163 } | |
| 164 | |
| 147 var receivePort = new ReceivePort(); | 165 var receivePort = new ReceivePort(); |
| 148 | 166 |
| 149 var isolate; | 167 var isolate; |
| 150 try { | 168 try { |
| 151 if (_config.pubServeUrl != null) { | 169 if (_config.pubServeUrl != null) { |
| 152 var url = _config.pubServeUrl.resolveUri( | 170 var url = _config.pubServeUrl.resolveUri( |
| 153 p.toUri(p.relative(path, from: 'test') + '.vm_test.dart')); | 171 p.toUri(p.relative(path, from: 'test') + '.vm_test.dart')); |
| 154 | 172 |
| 155 try { | 173 try { |
| 156 isolate = await Isolate.spawnUri(url, [], { | 174 isolate = await Isolate.spawnUri(url, [], { |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 238 Future close() { | 256 Future close() { |
| 239 return _closeMemo.runOnce(() async { | 257 return _closeMemo.runOnce(() async { |
| 240 await Future.wait(_suites.map((suite) => suite.close())); | 258 await Future.wait(_suites.map((suite) => suite.close())); |
| 241 _suites.clear(); | 259 _suites.clear(); |
| 242 | 260 |
| 243 if (!_browserServerMemo.hasRun) return; | 261 if (!_browserServerMemo.hasRun) return; |
| 244 await (await _browserServer).close(); | 262 await (await _browserServer).close(); |
| 245 }); | 263 }); |
| 246 } | 264 } |
| 247 } | 265 } |
| OLD | NEW |