10
10
/// * individual .dart files, each file is considered a module. A
11
11
/// `main.dart` file is required as the entry point of the test.
12
12
/// * subfolders: each considered a module with multiple files
13
- /// * (optional) a .packages file:
14
- /// * if this is not specified, the test will use [defaultPackagesInput]
15
- /// instead.
16
- /// * if specified, it will be extended with the definitions in
17
- /// [defaultPackagesInput]. The list of packages provided is expected to
18
- /// be disjoint with those in [defaultPackagesInput].
19
13
/// * a modules.yaml file: a specification of dependencies between modules.
20
14
/// The format is described in `test_specification_parser.dart`.
21
15
import 'dart:io' ;
22
- import 'dart:convert' ;
23
- import 'dart:typed_data' ;
24
16
import 'suite.dart' ;
25
17
import 'test_specification_parser.dart' ;
26
18
import 'find_sdk_root.dart' ;
27
19
28
- import 'package:package_config/src/packages_file.dart' as packages_file;
29
-
30
20
/// Returns the [ModularTest] associated with a folder under [uri] .
31
21
///
32
22
/// After scanning the contents of the folder, this method creates a
@@ -38,13 +28,12 @@ Future<ModularTest> loadTest(Uri uri) async {
38
28
var folder = Directory .fromUri (uri);
39
29
var testUri = folder.uri; // normalized in case the trailing '/' was missing.
40
30
Uri root = await findRoot ();
41
- Map < String , Uri > defaultPackages =
42
- _parseDotPackagesBytesToLibMap (_defaultPackagesInput, root );
31
+ final defaultTestSpecification = parseTestSpecification (_defaultPackagesSpec);
32
+ Set < String > defaultPackages = defaultTestSpecification.packages.keys. toSet ( );
43
33
Module sdkModule = await _createSdkModule (root);
44
34
Map <String , Module > modules = {'sdk' : sdkModule};
45
35
String specString;
46
36
Module mainModule;
47
- Map <String , Uri > packages = {};
48
37
var entries = folder.listSync (recursive: false ).toList ()
49
38
// Sort to avoid dependency on file system order.
50
39
..sort (_compareFileSystemEntity);
@@ -59,7 +48,7 @@ Future<ModularTest> loadTest(Uri uri) async {
59
48
"'$moduleName ' which conflicts with the sdk module "
60
49
"that is provided by default." );
61
50
}
62
- if (defaultPackages.containsKey (moduleName)) {
51
+ if (defaultPackages.contains (moduleName)) {
63
52
return _invalidTest ("The file '$fileName ' defines a module called "
64
53
"'$moduleName ' which conflicts with a package by the same name "
65
54
"that is provided by default." );
@@ -75,9 +64,6 @@ Future<ModularTest> loadTest(Uri uri) async {
75
64
packageBase: Uri .parse ('.' ));
76
65
if (isMain) mainModule = module;
77
66
modules[moduleName] = module;
78
- } else if (fileName == '.packages' ) {
79
- List <int > packagesBytes = await entry.readAsBytes ();
80
- packages = _parseDotPackagesBytesToLibMap (packagesBytes, entryUri);
81
67
} else if (fileName == 'modules.yaml' ) {
82
68
specString = await entry.readAsString ();
83
69
}
@@ -90,7 +76,7 @@ Future<ModularTest> loadTest(Uri uri) async {
90
76
"which conflicts with the sdk module "
91
77
"that is provided by default." );
92
78
}
93
- if (defaultPackages.containsKey (moduleName)) {
79
+ if (defaultPackages.contains (moduleName)) {
94
80
return _invalidTest ("The folder '$moduleName ' defines a module "
95
81
"which conflicts with a package by the same name "
96
82
"that is provided by default." );
@@ -110,12 +96,17 @@ Future<ModularTest> loadTest(Uri uri) async {
110
96
return _invalidTest ("main module is missing" );
111
97
}
112
98
113
- _addDefaultPackageEntries (packages, defaultPackages);
114
- await _addModulePerPackage (packages, modules);
115
99
TestSpecification spec = parseTestSpecification (specString);
100
+ for (final name in defaultPackages) {
101
+ if (spec.packages.containsKey (name)) {
102
+ _invalidTest (
103
+ ".packages file defines a conflicting entry for package '$name '." );
104
+ }
105
+ }
106
+ await _addModulePerPackage (defaultTestSpecification.packages, root, modules);
107
+ await _addModulePerPackage (spec.packages, testUri, modules);
116
108
_attachDependencies (spec.dependencies, modules);
117
- _attachDependencies (
118
- parseTestSpecification (_defaultPackagesSpec).dependencies, modules);
109
+ _attachDependencies (defaultTestSpecification.dependencies, modules);
119
110
_addSdkDependencies (modules, sdkModule);
120
111
_detectCyclesAndRemoveUnreachable (modules, mainModule);
121
112
var sortedModules = modules.values.toList ()
@@ -170,33 +161,21 @@ void _addSdkDependencies(Map<String, Module> modules, Module sdkModule) {
170
161
}
171
162
}
172
163
173
- void _addDefaultPackageEntries (
174
- Map <String , Uri > packages, Map <String , Uri > defaultPackages) {
175
- for (var name in defaultPackages.keys) {
176
- var existing = packages[name];
177
- if (existing != null && existing != defaultPackages[name]) {
178
- _invalidTest (
179
- ".packages file defines an conflicting entry for package '$name '." );
180
- }
181
- packages[name] = defaultPackages[name];
182
- }
183
- }
184
-
185
164
/// Create a module for each package dependency.
186
- Future <void > _addModulePerPackage (
187
- Map <String , Uri > packages, Map < String , Module > modules) async {
165
+ Future <void > _addModulePerPackage (Map < String , String > packages, Uri configRoot,
166
+ Map <String , Module > modules) async {
188
167
for (var packageName in packages.keys) {
189
168
var module = modules[packageName];
190
169
if (module != null ) {
191
170
module.isPackage = true ;
192
171
} else {
193
- var packageLibUri = packages[packageName];
194
- var rootUri = Directory .fromUri (packageLibUri).parent.uri;
172
+ var packageLibUri = configRoot. resolve ( packages[packageName]) ;
173
+ var packageRootUri = Directory .fromUri (packageLibUri).parent.uri;
195
174
var sources = await _listModuleSources (packageLibUri);
196
175
// TODO(sigmund): validate that we don't use a different alias for a
197
176
// module that is part of the test (package name and module name should
198
177
// match).
199
- modules[packageName] = Module (packageName, [], rootUri , sources,
178
+ modules[packageName] = Module (packageName, [], packageRootUri , sources,
200
179
isPackage: true , packageBase: Uri .parse ('lib/' ), isShared: true );
201
180
}
202
181
}
@@ -249,15 +228,6 @@ _detectCyclesAndRemoveUnreachable(Map<String, Module> modules, Module main) {
249
228
toRemove.forEach (modules.remove);
250
229
}
251
230
252
- /// Default entries for a .packages file with paths relative to the SDK root.
253
- List <int > _defaultPackagesInput = utf8.encode ('''
254
- expect:pkg/expect/lib
255
- smith:pkg/smith/lib
256
- async_helper:pkg/async_helper/lib
257
- meta:pkg/meta/lib
258
- collection:third_party/pkg/collection/lib
259
- ''' );
260
-
261
231
/// Specifies the dependencies of all packages in [_defaultPackagesInput] . This
262
232
/// string needs to be updated if dependencies between those packages changes
263
233
/// (which is rare).
@@ -270,6 +240,12 @@ dependencies:
270
240
meta: []
271
241
async_helper: []
272
242
collection: []
243
+ packages:
244
+ expect: pkg/expect/lib
245
+ smith: pkg/smith/lib
246
+ async_helper: pkg/async_helper/lib
247
+ meta: pkg/meta/lib
248
+ collection: third_party/pkg/collection/lib
273
249
''' ;
274
250
275
251
/// Report an conflict error.
@@ -316,15 +292,3 @@ int _compareFileSystemEntity(FileSystemEntity a, FileSystemEntity b) {
316
292
}
317
293
}
318
294
}
319
-
320
- /// Parse [bytes] representing a `.packages` file into the map of package names
321
- /// to URIs of their `lib` locations.
322
- Map <String , Uri > _parseDotPackagesBytesToLibMap (Uint8List bytes, Uri baseUri) {
323
- var map = < String , Uri > {};
324
- var packageConfig =
325
- packages_file.parse (bytes, baseUri, (error) => throw error);
326
- for (var package in packageConfig.packages) {
327
- map[package.name] = package.packageUriRoot;
328
- }
329
- return map;
330
- }
0 commit comments