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

Unified Diff: lib/src/io.dart

Issue 1216163002: Fix tests to run in dart-lang/sdk. (Closed) Base URL: git@github.com:dart-lang/pub.git@master
Patch Set: cr Created 5 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | test/test_pub.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/io.dart
diff --git a/lib/src/io.dart b/lib/src/io.dart
index 45a26a11669bc644303ca70a8beae56bf35299e7..d24ede0203bd1b4c4aaebdd722e5bd904515ce3e 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 <repo>/third_party/pkg/pub.
+ 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)));
+ }
+
// 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(
« no previous file with comments | « no previous file | test/test_pub.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698