| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 import 'dart:async'; | 5 import 'dart:async'; |
| 6 import 'dart:convert'; | 6 import 'dart:convert'; |
| 7 import 'dart:io'; | 7 import 'dart:io'; |
| 8 import 'dart:isolate'; | 8 import 'dart:isolate'; |
| 9 | 9 |
| 10 import 'package:path/path.dart' as p; | 10 import 'package:path/path.dart' as p; |
| 11 import 'package:stack_trace/stack_trace.dart'; | 11 import 'package:stack_trace/stack_trace.dart'; |
| 12 import 'package:test/test.dart'; | 12 import 'package:test/test.dart'; |
| 13 | 13 |
| 14 import 'package:package_resolver/package_resolver.dart'; | 14 import 'package:package_resolver/package_resolver.dart'; |
| 15 import 'package:package_resolver/src/utils.dart'; |
| 15 | 16 |
| 16 void main() { | 17 void main() { |
| 17 // It's important to test these, because they use PackageConfig.current and | 18 // It's important to test these, because they use PackageConfig.current and |
| 18 // they're used to verify the output of the inner isolate's | 19 // they're used to verify the output of the inner isolate's |
| 19 // PackageConfig.current. | 20 // PackageConfig.current. |
| 20 test("_packageResolverLibUri is correct", () async { | 21 test("_packageResolverLibUri is correct", () async { |
| 21 var libPath = p.fromUri(await _packageResolverLibUri); | 22 var libPath = p.fromUri(await _packageResolverLibUri); |
| 22 expect(new File(p.join(libPath, 'package_resolver.dart')).exists(), | 23 expect(new File(p.join(libPath, 'package_resolver.dart')).exists(), |
| 23 completion(isTrue)); | 24 completion(isTrue)); |
| 24 }); | 25 }); |
| 25 | 26 |
| 26 test("_pathLibUri is correct", () async { | 27 test("_pathLibUri is correct", () async { |
| 27 var libPath = p.fromUri(await _pathLibUri); | 28 var libPath = p.fromUri(await _pathLibUri); |
| 28 expect(new File(p.join(libPath, 'path.dart')).exists(), completion(isTrue)); | 29 expect(new File(p.join(libPath, 'path.dart')).exists(), completion(isTrue)); |
| 29 }); | 30 }); |
| 30 | 31 |
| 31 group("with a package config", () { | 32 group("with a package config", () { |
| 32 var resolver; | 33 var resolver; |
| 33 setUp(() async { | 34 setUp(() async { |
| 34 var map; | 35 var map; |
| 35 var currentIsolateMap = await PackageResolver.current.packageConfigMap; | 36 var currentIsolateMap = await PackageResolver.current.packageConfigMap; |
| 36 if (currentIsolateMap != null) { | 37 if (currentIsolateMap != null) { |
| 37 map = new Map.from(currentIsolateMap); | 38 map = new Map.from(currentIsolateMap); |
| 38 } else { | 39 } else { |
| 39 // If the isolate running this test isn't using package config, create | 40 // If the isolate running this test isn't using package config, create |
| 40 // one from scratch with the same resolution semantics. | 41 // one from scratch with the same resolution semantics. |
| 41 var map = {}; | 42 map = {}; |
| 42 var root = p.fromUri(await PackageResolver.current.packageRoot); | 43 var root = p.fromUri(await PackageResolver.current.packageRoot); |
| 43 await for (var link in new Directory(root).list(followLinks: false)) { | 44 await for (var link in new Directory(root).list(followLinks: false)) { |
| 44 assert(link is Link); | 45 assert(link is Link); |
| 45 map[p.basename(link.path)] = | 46 map[p.basename(link.path)] = |
| 46 p.toUri(await link.resolveSymbolicLinks()); | 47 ensureTrailingSlash(p.toUri((await link.resolveSymbolicLinks()))); |
| 47 } | 48 } |
| 48 } | 49 } |
| 49 | 50 |
| 50 // Ensure that we have at least one URI that ends with "/" and one that | 51 // Ensure that we have at least one URI that ends with "/" and one that |
| 51 // doesn't. Both of these cases need to be tested. | 52 // doesn't. Both of these cases need to be tested. |
| 52 expect(map["package_resolver"].path, endsWith("/")); | 53 expect(map["package_resolver"].path, endsWith("/")); |
| 53 map["path"] = Uri.parse(p.url.normalize(map["path"].toString())); | 54 map["path"] = Uri.parse(p.url.normalize(map["path"].toString())); |
| 54 expect(map["path"].path, isNot(endsWith("/"))); | 55 expect(map["path"].path, isNot(endsWith("/"))); |
| 55 | 56 |
| 56 resolver = new PackageResolver.config(map); | 57 resolver = new PackageResolver.config(map); |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 return false; | 182 return false; |
| 182 } on FormatException catch (_) { | 183 } on FormatException catch (_) { |
| 183 return true; | 184 return true; |
| 184 } | 185 } |
| 185 }()""", resolver), isTrue); | 186 }()""", resolver), isTrue); |
| 186 }); | 187 }); |
| 187 }); | 188 }); |
| 188 }); | 189 }); |
| 189 } | 190 } |
| 190 | 191 |
| 191 Future<String> get _packageResolverLibUri async => | 192 Future<String> get _packageResolverLibUri => _urlForPackage('package_resolver'); |
| 192 (await PackageResolver.current.urlFor("package_resolver")).toString(); | |
| 193 | 193 |
| 194 Future<String> get _pathLibUri async => | 194 Future<String> get _pathLibUri => _urlForPackage('path'); |
| 195 (await PackageResolver.current.urlFor("path")).toString(); | 195 |
| 196 Future<String> _urlForPackage(String package) async { |
| 197 var uri = await PackageResolver.current.urlFor(package); |
| 198 if (await PackageResolver.current.packageConfigMap != null) { |
| 199 return uri.toString(); |
| 200 } |
| 201 |
| 202 // If we're using a package root, we resolve the symlinks in the test code so |
| 203 // we need to resolve them here as well to ensure we're testing against the |
| 204 // same values. |
| 205 var resolved = new Directory(p.fromUri(uri)).resolveSymbolicLinksSync(); |
| 206 return ensureTrailingSlash(p.toUri(resolved)).toString(); |
| 207 } |
| 196 | 208 |
| 197 Future _spawn(String expression, PackageResolver packageResolver) async { | 209 Future _spawn(String expression, PackageResolver packageResolver) async { |
| 198 var data = new UriData.fromString(""" | 210 var data = new UriData.fromString(""" |
| 199 import 'dart:convert'; | 211 import 'dart:convert'; |
| 200 import 'dart:isolate'; | 212 import 'dart:isolate'; |
| 201 | 213 |
| 202 import 'package:package_resolver/package_resolver.dart'; | 214 import 'package:package_resolver/package_resolver.dart'; |
| 203 | 215 |
| 204 main(_, SendPort message) async { | 216 main(_, SendPort message) async { |
| 205 message.send(await ($expression)); | 217 message.send(await ($expression)); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 224 isolate.resume(isolate.pauseCapability); | 236 isolate.resume(isolate.pauseCapability); |
| 225 | 237 |
| 226 var value = await receivePort.first; | 238 var value = await receivePort.first; |
| 227 isolate.kill(); | 239 isolate.kill(); |
| 228 return value; | 240 return value; |
| 229 } finally { | 241 } finally { |
| 230 errorPort.close(); | 242 errorPort.close(); |
| 231 receivePort.close(); | 243 receivePort.close(); |
| 232 } | 244 } |
| 233 } | 245 } |
| OLD | NEW |