Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(23)

Side by Side Diff: test/descriptor/packages.dart

Issue 2377063002: Make "--no-packages-dir" the default. (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 /// Pub-specific scheduled_test descriptors. 5 /// Pub-specific scheduled_test descriptors.
6 import "dart:io" show File; 6 import "dart:io" show File;
7 import "dart:async" show Future; 7 import "dart:async" show Future;
8 import "dart:convert" show UTF8; 8 import "dart:convert" show UTF8;
9 9
10 import 'package:package_config/packages_file.dart' as packages_file; 10 import 'package:package_config/packages_file.dart' as packages_file;
11 import 'package:path/path.dart' as p; 11 import 'package:path/path.dart' as p;
12 import 'package:pub_semver/pub_semver.dart';
12 import 'package:scheduled_test/descriptor.dart'; 13 import 'package:scheduled_test/descriptor.dart';
13 import 'package:scheduled_test/scheduled_test.dart'; 14 import 'package:scheduled_test/scheduled_test.dart';
14 15
15 import '../test_pub.dart'; 16 import '../test_pub.dart';
16 17
17 /// Describes a `.packages` file and its contents. 18 /// Describes a `.packages` file and its contents.
18 class PackagesFileDescriptor extends Descriptor { 19 class PackagesFileDescriptor extends Descriptor {
19 // RegExp recognizing semantic version numbers.
20 static final _semverRE =
21 new RegExp(r"^(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)"
22 r"(?:-[a-zA-Z\d-]+)?(?:\+[a-zA-Z\d-]+)?$");
23
24 /// A map from package names to strings describing where the packages are 20 /// A map from package names to strings describing where the packages are
25 /// located on disk. 21 /// located on disk.
26 final Map<String, String> _dependencies; 22 final Map<String, String> _dependencies;
27 23
28 /// Describes a `.packages` file with the given dependencies. 24 /// Describes a `.packages` file with the given dependencies.
29 /// 25 ///
30 /// [dependencies] maps package names to strings describing where the packages 26 /// [dependencies] maps package names to strings describing where the packages
31 /// are located on disk. 27 /// are located on disk.
32 PackagesFileDescriptor([this._dependencies]) : super('.packages'); 28 PackagesFileDescriptor([this._dependencies]) : super('.packages');
33 29
34 Future create([String parent]) => schedule(() { 30 Future create([String parent]) => schedule(() {
35 if (parent == null) parent = defaultRoot; 31 if (parent == null) parent = defaultRoot;
36 var contents = const <int>[]; 32 var contents = const <int>[];
37 if (_dependencies != null) { 33 if (_dependencies != null) {
38 var mapping = <String, Uri>{}; 34 var mapping = <String, Uri>{};
39 _dependencies.forEach((package, version) { 35 _dependencies.forEach((package, version) {
40 var packagePath; 36 var packagePath;
41 if (_semverRE.hasMatch(version)) { 37 try {
42 // If it's a semver, it's a cache reference. 38 // See if it's a semver.
39 new Version.parse(version);
nweiz 2016/09/28 20:01:21 Consider factoring this try/catch into an _isSemve
Bob Nystrom 2016/09/29 00:21:26 Done.
40
41 // If we get here, it's a cache reference.
43 packagePath = p.join(cachePath, "$package-$version"); 42 packagePath = p.join(cachePath, "$package-$version");
44 } else { 43 } on FormatException catch (_) {
45 // Otherwise it's a path relative to the pubspec file, 44 // Otherwise it's a path relative to the pubspec file,
46 // which is also relative to the .packages file. 45 // which is also relative to the .packages file.
47 packagePath = p.fromUri(version); 46 packagePath = p.fromUri(version);
48 } 47 }
49 mapping[package] = p.toUri(p.join(packagePath, "lib", "")); 48 mapping[package] = p.toUri(p.join(packagePath, "lib", ""));
50 }); 49 });
51 var buffer = new StringBuffer(); 50 var buffer = new StringBuffer();
52 packages_file.write(buffer, mapping); 51 packages_file.write(buffer, mapping);
53 contents = UTF8.encode(buffer.toString()); 52 contents = UTF8.encode(buffer.toString());
54 } 53 }
(...skipping 22 matching lines...) Expand all
77 // "." due to sdk#23809. 76 // "." due to sdk#23809.
78 var base = "/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p"; 77 var base = "/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p";
79 var map = packages_file.parse(binaryContents, Uri.parse(base)); 78 var map = packages_file.parse(binaryContents, Uri.parse(base));
80 79
81 for (var package in _dependencies.keys) { 80 for (var package in _dependencies.keys) {
82 if (!map.containsKey(package)) { 81 if (!map.containsKey(package)) {
83 fail(".packages does not contain $package entry"); 82 fail(".packages does not contain $package entry");
84 } 83 }
85 84
86 var description = _dependencies[package]; 85 var description = _dependencies[package];
87 if (_semverRE.hasMatch(description)) { 86 try {
87 // See if it's a semver.
88 new Version.parse(description);
89
88 if (!map[package].path.contains(description)) { 90 if (!map[package].path.contains(description)) {
89 fail(".packages of $package has incorrect version. " 91 fail(".packages of $package has incorrect version. "
90 "Expected $description, found location: ${map[package]}."); 92 "Expected $description, found location: ${map[package]}.");
91 } 93 }
92 } else { 94 } on FormatException catch (_) {
93 var expected = p.normalize(p.join(p.fromUri(description), 'lib')); 95 var expected = p.normalize(p.join(p.fromUri(description), 'lib'));
94 var actual = p.normalize(p.fromUri( 96 var actual = p.normalize(p.fromUri(
95 p.url.relative(map[package].toString(), from: p.dirname(base)))); 97 p.url.relative(map[package].toString(), from: p.dirname(base))));
96 98
97 if (expected != actual) { 99 if (expected != actual) {
98 fail("Relative path: Expected $expected, found $actual"); 100 fail("Relative path: Expected $expected, found $actual");
99 } 101 }
100 } 102 }
101 } 103 }
102 104
103 if (map.length != _dependencies.length) { 105 if (map.length != _dependencies.length) {
104 for (var key in map.keys) { 106 for (var key in map.keys) {
105 if (!_dependencies.containsKey(key)) { 107 if (!_dependencies.containsKey(key)) {
106 fail(".packages file contains unexpected entry: $key"); 108 fail(".packages file contains unexpected entry: $key");
107 } 109 }
108 } 110 }
109 } 111 }
110 } 112 }
111 113
112 String describe() => name; 114 String describe() => name;
113 } 115 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698