OLD | NEW |
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 /// Helper functionality to make working with IO easier. | 5 /// Helper functionality to make working with IO easier. |
6 library pub.io; | 6 library pub.io; |
7 | 7 |
8 import 'dart:async'; | 8 import 'dart:async'; |
9 import 'dart:collection'; | 9 import 'dart:collection'; |
10 import 'dart:convert'; | 10 import 'dart:convert'; |
(...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
475 createSymlink(target, symlink, relative: relative); | 475 createSymlink(target, symlink, relative: relative); |
476 } | 476 } |
477 | 477 |
478 /// Whether the current process is one of pub's test files. | 478 /// Whether the current process is one of pub's test files. |
479 /// | 479 /// |
480 /// This works because an actual pub executable that imports this will always | 480 /// This works because an actual pub executable that imports this will always |
481 /// start with "pub". | 481 /// start with "pub". |
482 final bool runningAsTest = | 482 final bool runningAsTest = |
483 !path.url.basename(Platform.script.path).startsWith('pub.'); | 483 !path.url.basename(Platform.script.path).startsWith('pub.'); |
484 | 484 |
| 485 // TODO(nweiz): Use the test API when test#48 is fixed. |
| 486 /// Whether the current process is one of pub's test files being run through the |
| 487 /// test package's test runner. |
| 488 /// |
| 489 /// The test runner starts all tests from an entrypoint called |
| 490 /// "runInIsolate.dart'> |
| 491 final bool runningAsTestRunner = |
| 492 path.url.basename(Platform.script.path).startsWith('runInIsolate.dart'); |
| 493 |
485 /// Whether the current process is a pub subprocess being run from a test. | 494 /// Whether the current process is a pub subprocess being run from a test. |
486 /// | 495 /// |
487 /// The "_PUB_TESTING" variable is automatically set for all the test code's | 496 /// The "_PUB_TESTING" variable is automatically set for all the test code's |
488 /// invocations of pub. | 497 /// invocations of pub. |
489 final bool runningFromTest = Platform.environment.containsKey('_PUB_TESTING'); | 498 final bool runningFromTest = Platform.environment.containsKey('_PUB_TESTING'); |
490 | 499 |
491 /// Whether pub is running from within the Dart SDK, as opposed to from the Dart | 500 /// Whether pub is running from within the Dart SDK, as opposed to from the Dart |
492 /// source repository. | 501 /// source repository. |
493 final bool runningFromSdk = | 502 final bool runningFromSdk = |
494 !runningFromTest && Platform.script.path.endsWith('.snapshot'); | 503 !runningFromTest && Platform.script.path.endsWith('.snapshot'); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
528 } | 537 } |
529 | 538 |
530 /// The path to the root of pub's sources in the pub repo. | 539 /// The path to the root of pub's sources in the pub repo. |
531 /// | 540 /// |
532 /// This throws a [StateError] if it's called when running pub from the SDK. | 541 /// This throws a [StateError] if it's called when running pub from the SDK. |
533 final String pubRoot = (() { | 542 final String pubRoot = (() { |
534 if (runningFromSdk) { | 543 if (runningFromSdk) { |
535 throw new StateError("Can't get pub's root from the SDK."); | 544 throw new StateError("Can't get pub's root from the SDK."); |
536 } | 545 } |
537 | 546 |
| 547 // The test runner always runs from the working directory. |
| 548 if (runningAsTestRunner) return path.current; |
| 549 |
538 var script = path.fromUri(Platform.script); | 550 var script = path.fromUri(Platform.script); |
539 if (runningAsTest) { | 551 if (runningAsTest) { |
540 // Running from "test/../some_test.dart". | 552 // Running from "test/../some_test.dart". |
541 var components = path.split(script); | 553 var components = path.split(script); |
542 var testIndex = components.indexOf("test"); | 554 var testIndex = components.indexOf("test"); |
543 if (testIndex == -1) throw new StateError("Can't find pub's root."); | 555 if (testIndex == -1) throw new StateError("Can't find pub's root."); |
544 return path.joinAll(components.take(testIndex)); | 556 return path.joinAll(components.take(testIndex)); |
545 } | 557 } |
546 | 558 |
547 // Pub is either run from ".pub/pub.test.snapshot" or "bin/pub.dart". | 559 // Pub is either run from ".pub/pub.test.snapshot" or "bin/pub.dart". |
(...skipping 517 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1065 | 1077 |
1066 // TODO(rnystrom): Remove this and change to returning one string. | 1078 // TODO(rnystrom): Remove this and change to returning one string. |
1067 static List<String> _toLines(String output) { | 1079 static List<String> _toLines(String output) { |
1068 var lines = splitLines(output); | 1080 var lines = splitLines(output); |
1069 if (!lines.isEmpty && lines.last == "") lines.removeLast(); | 1081 if (!lines.isEmpty && lines.last == "") lines.removeLast(); |
1070 return lines; | 1082 return lines; |
1071 } | 1083 } |
1072 | 1084 |
1073 bool get success => exitCode == exit_codes.SUCCESS; | 1085 bool get success => exitCode == exit_codes.SUCCESS; |
1074 } | 1086 } |
OLD | NEW |