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 15 matching lines...) Expand all Loading... |
26 import 'vm/isolate_test.dart'; | 26 import 'vm/isolate_test.dart'; |
27 | 27 |
28 /// A class for finding test files and loading them into a runnable form. | 28 /// A class for finding test files and loading them into a runnable form. |
29 class Loader { | 29 class Loader { |
30 /// All platforms for which tests should be loaded. | 30 /// All platforms for which tests should be loaded. |
31 final List<TestPlatform> _platforms; | 31 final List<TestPlatform> _platforms; |
32 | 32 |
33 /// Whether to enable colors for Dart compilation. | 33 /// Whether to enable colors for Dart compilation. |
34 final bool _color; | 34 final bool _color; |
35 | 35 |
| 36 /// Global metadata that applies to all test suites. |
| 37 final Metadata _metadata; |
| 38 |
36 /// The root directory that will be served for browser tests. | 39 /// The root directory that will be served for browser tests. |
37 final String _root; | 40 final String _root; |
38 | 41 |
39 /// The package root to use for loading tests. | 42 /// The package root to use for loading tests. |
40 final String _packageRoot; | 43 final String _packageRoot; |
41 | 44 |
42 /// The URL for the `pub serve` instance to use to load tests. | 45 /// The URL for the `pub serve` instance to use to load tests. |
43 /// | 46 /// |
44 /// This is `null` if tests should be loaded from the filesystem. | 47 /// This is `null` if tests should be loaded from the filesystem. |
45 final Uri _pubServeUrl; | 48 final Uri _pubServeUrl; |
(...skipping 25 matching lines...) Expand all Loading... |
71 /// defaults to the working directory. | 74 /// defaults to the working directory. |
72 /// | 75 /// |
73 /// If [packageRoot] is passed, it's used as the package root for all loaded | 76 /// If [packageRoot] is passed, it's used as the package root for all loaded |
74 /// tests. Otherwise, it's inferred from [root]. | 77 /// tests. Otherwise, it's inferred from [root]. |
75 /// | 78 /// |
76 /// If [pubServeUrl] is passed, tests will be loaded from the `pub serve` | 79 /// If [pubServeUrl] is passed, tests will be loaded from the `pub serve` |
77 /// instance at that URL rather than from the filesystem. | 80 /// instance at that URL rather than from the filesystem. |
78 /// | 81 /// |
79 /// If [color] is true, console colors will be used when compiling Dart. | 82 /// If [color] is true, console colors will be used when compiling Dart. |
80 /// | 83 /// |
| 84 /// [metadata] is the global metadata for all test suites. |
| 85 /// |
81 /// If the package root doesn't exist, throws an [ApplicationException]. | 86 /// If the package root doesn't exist, throws an [ApplicationException]. |
82 Loader(Iterable<TestPlatform> platforms, {String root, String packageRoot, | 87 Loader(Iterable<TestPlatform> platforms, {String root, String packageRoot, |
83 Uri pubServeUrl, bool color: false}) | 88 Uri pubServeUrl, bool color: false, Metadata metadata}) |
84 : _platforms = platforms.toList(), | 89 : _platforms = platforms.toList(), |
85 _pubServeUrl = pubServeUrl, | 90 _pubServeUrl = pubServeUrl, |
86 _root = root == null ? p.current : root, | 91 _root = root == null ? p.current : root, |
87 _packageRoot = packageRootFor(root, packageRoot), | 92 _packageRoot = packageRootFor(root, packageRoot), |
88 _color = color; | 93 _color = color, |
| 94 _metadata = metadata == null ? new Metadata() : metadata; |
89 | 95 |
90 /// Loads all test suites in [dir]. | 96 /// Loads all test suites in [dir]. |
91 /// | 97 /// |
92 /// This will load tests from files that end in "_test.dart". Any tests that | 98 /// This will load tests from files that end in "_test.dart". Any tests that |
93 /// fail to load will be emitted as [LoadException]s. | 99 /// fail to load will be emitted as [LoadException]s. |
94 Stream<Suite> loadDir(String dir) { | 100 Stream<Suite> loadDir(String dir) { |
95 return mergeStreams(new Directory(dir).listSync(recursive: true) | 101 return mergeStreams(new Directory(dir).listSync(recursive: true) |
96 .map((entry) { | 102 .map((entry) { |
97 if (entry is! File) return new Stream.fromIterable([]); | 103 if (entry is! File) return new Stream.fromIterable([]); |
98 | 104 |
(...skipping 17 matching lines...) Expand all Loading... |
116 try { | 122 try { |
117 suiteMetadata = parseMetadata(path); | 123 suiteMetadata = parseMetadata(path); |
118 } on AnalyzerErrorGroup catch (_) { | 124 } on AnalyzerErrorGroup catch (_) { |
119 // Ignore the analyzer's error, since its formatting is much worse than | 125 // Ignore the analyzer's error, since its formatting is much worse than |
120 // the VM's or dart2js's. | 126 // the VM's or dart2js's. |
121 suiteMetadata = new Metadata(); | 127 suiteMetadata = new Metadata(); |
122 } on FormatException catch (error, stackTrace) { | 128 } on FormatException catch (error, stackTrace) { |
123 return new Stream.fromFuture( | 129 return new Stream.fromFuture( |
124 new Future.error(new LoadException(path, error), stackTrace)); | 130 new Future.error(new LoadException(path, error), stackTrace)); |
125 } | 131 } |
| 132 suiteMetadata = _metadata.merge(suiteMetadata); |
126 | 133 |
127 var controller = new StreamController(); | 134 var controller = new StreamController(); |
128 Future.forEach(_platforms, (platform) { | 135 Future.forEach(_platforms, (platform) { |
129 if (!suiteMetadata.testOn.evaluate(platform, os: currentOS)) { | 136 if (!suiteMetadata.testOn.evaluate(platform, os: currentOS)) { |
130 return null; | 137 return null; |
131 } | 138 } |
132 | 139 |
133 var metadata = suiteMetadata.forPlatform(platform, os: currentOS); | 140 var metadata = suiteMetadata.forPlatform(platform, os: currentOS); |
134 | 141 |
135 // Don't load a skipped suite. | 142 // Don't load a skipped suite. |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 Future close() { | 247 Future close() { |
241 for (var isolate in _isolates) { | 248 for (var isolate in _isolates) { |
242 isolate.kill(); | 249 isolate.kill(); |
243 } | 250 } |
244 _isolates.clear(); | 251 _isolates.clear(); |
245 | 252 |
246 if (_browserServerCompleter == null) return new Future.value(); | 253 if (_browserServerCompleter == null) return new Future.value(); |
247 return _browserServer.then((browserServer) => browserServer.close()); | 254 return _browserServer.then((browserServer) => browserServer.close()); |
248 } | 255 } |
249 } | 256 } |
OLD | NEW |