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

Side by Side Diff: lib/src/util/io.dart

Issue 979513002: pkg/unittest: Add a server for serving test assets to browsers. (Closed) Base URL: git@github.com:dart-lang/unittest@master
Patch Set: Fix libDir. Created 5 years, 9 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) 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 unittest.util.io; 5 library unittest.util.io;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:io'; 8 import 'dart:io';
9 import 'dart:mirrors';
9 10
10 import 'package:path/path.dart' as p; 11 import 'package:path/path.dart' as p;
11 12
13 import '../runner/load_exception.dart';
14
12 /// The root directory of the Dart SDK. 15 /// The root directory of the Dart SDK.
13 final String sdkDir = _computeSdkDir(); 16 final String sdkDir =
14 String _computeSdkDir() => p.dirname(p.dirname(Platform.executable)); 17 p.dirname(p.dirname(Platform.executable));
18
19 /// The path to the `lib` directory of the `unittest` package.
20 String libDir({String packageRoot}) {
21 var pathToIo = libraryPath(#unittest.util.io, packageRoot: packageRoot);
22 return p.dirname(p.dirname(p.dirname(pathToIo)));
23 }
15 24
16 /// Returns whether the current Dart version supports [Isolate.kill]. 25 /// Returns whether the current Dart version supports [Isolate.kill].
17 final bool supportsIsolateKill = _supportsIsolateKill; 26 final bool supportsIsolateKill = _supportsIsolateKill;
18 bool get _supportsIsolateKill { 27 bool get _supportsIsolateKill {
19 // This isn't 100% accurate, since early 1.9 dev releases didn't support 28 // This isn't 100% accurate, since early 1.9 dev releases didn't support
20 // Isolate.kill(), but it's very unlikely anyone will be using them. 29 // Isolate.kill(), but it's very unlikely anyone will be using them.
21 // TODO(nweiz): remove this when we no longer support older Dart versions. 30 // TODO(nweiz): remove this when we no longer support older Dart versions.
22 var path = p.join(p.dirname(p.dirname(Platform.executable)), 'version'); 31 var path = p.join(p.dirname(p.dirname(Platform.executable)), 'version');
23 return new File(path).readAsStringSync().startsWith('1.9'); 32 return new File(path).readAsStringSync().startsWith('1.9');
24 } 33 }
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 } 69 }
61 70
62 // IPv6 addresses in URLs need to be enclosed in square brackets to avoid 71 // IPv6 addresses in URLs need to be enclosed in square brackets to avoid
63 // URL ambiguity with the ":" in the address. 72 // URL ambiguity with the ":" in the address.
64 if (address.type == InternetAddressType.IP_V6) { 73 if (address.type == InternetAddressType.IP_V6) {
65 return new Uri(scheme: "http", host: "[${address.address}]", port: port); 74 return new Uri(scheme: "http", host: "[${address.address}]", port: port);
66 } 75 }
67 76
68 return new Uri(scheme: "http", host: address.address, port: port); 77 return new Uri(scheme: "http", host: address.address, port: port);
69 } 78 }
79
80 /// Returns the package root for a Dart entrypoint at [path].
81 ///
82 /// If [override] is passed, that's used. If the package root doesn't exist, a
83 /// [LoadException] is thrown.
84 String packageRootFor(String path, [String override]) {
85 var packageRoot = override == null
86 ? p.join(p.dirname(path), 'packages')
87 : override;
88
89 if (!new Directory(packageRoot).existsSync()) {
90 throw new LoadException(path, "Directory $packageRoot does not exist.");
91 }
92
93 return packageRoot;
94 }
95
96 /// The library name must be globally unique, or the wrong library path may be
97 /// returned.
98 String libraryPath(Symbol libraryName, {String packageRoot}) {
99 var lib = currentMirrorSystem().findLibrary(libraryName);
100 if (lib.uri.scheme != 'package') return p.fromUri(lib.uri);
101
102 // TODO(nweiz): is there a way to avoid assuming this is being run next to a
103 // packages directory?.
104 if (packageRoot == null) packageRoot = p.absolute('packages');
105 return p.join(packageRoot, p.fromUri(lib.uri.path));
106 }
OLDNEW
« lib/src/runner/loader.dart ('K') | « lib/src/runner/loader.dart ('k') | pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698