Index: lib/src/io.dart |
diff --git a/lib/src/io.dart b/lib/src/io.dart |
index 45a26a11669bc644303ca70a8beae56bf35299e7..030c9ed28c1e331ca11a1db089d2dab73bf162b8 100644 |
--- a/lib/src/io.dart |
+++ b/lib/src/io.dart |
@@ -515,9 +515,19 @@ final _dartRepoRegExp = new RegExp( |
/// Whether pub is running from source in the Dart repo. |
/// |
-/// This can happen when building Observatory, for example. |
-final bool runningFromDartRepo = |
- Platform.script.path.contains(_dartRepoRegExp); |
+/// This can happen when running tests against the repo, as well as when |
+/// building Observatory. |
+final bool runningFromDartRepo = (() { |
+ if (runningAsTestRunner) { |
+ // When running from the test runner, we can't find our location via |
+ // Platform.script since the runner munges that. However, it guarantees that |
+ // the working directory is |
Bob Nystrom
2015/06/30 18:33:11
"is ..."
nweiz
2015/06/30 19:47:29
Done.
|
+ return path.current.contains( |
+ new RegExp(r"[/\\]third_party[/\\]pkg[/\\]pub$")); |
+ } else { |
+ return Platform.script.path.contains(_dartRepoRegExp); |
+ } |
+})(); |
/// Resolves [target] relative to the path to pub's `asset` directory. |
String assetPath(String target) => runningFromSdk |
@@ -569,6 +579,12 @@ final String dartRepoRoot = (() { |
throw new StateError("Not running from source in the Dart repo."); |
} |
+ if (runningAsTestRunner) { |
+ // When running in test code started by the test runner, the working |
+ // directory will always be <repo>/third_party/pkg/pub. |
+ return path.dirname(path.dirname(path.dirname(path.current))); |
Bob Nystrom
2015/06/30 18:33:11
Is there a reason to prefer chained dirnames over
nweiz
2015/06/30 19:47:29
Because path.join tries to avoid any unnecessary m
|
+ } |
+ |
// Get the URL of the repo root in a way that works when either both running |
// as a test or as a pub executable. |
var url = Platform.script.replace( |