| 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 /// Test infrastructure for testing pub. | 5 /// Test infrastructure for testing pub. |
| 6 /// | 6 /// |
| 7 /// Unlike typical unit tests, most pub tests are integration tests that stage | 7 /// Unlike typical unit tests, most pub tests are integration tests that stage |
| 8 /// some stuff on the file system, run pub, and then validate the results. This | 8 /// some stuff on the file system, run pub, and then validate the results. This |
| 9 /// library provides an API to build tests like that. | 9 /// library provides an API to build tests like that. |
| 10 library test_pub; | 10 library test_pub; |
| (...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 476 pub.writeLine("y"); | 476 pub.writeLine("y"); |
| 477 } | 477 } |
| 478 | 478 |
| 479 /// Gets the absolute path to [relPath], which is a relative path in the test | 479 /// Gets the absolute path to [relPath], which is a relative path in the test |
| 480 /// sandbox. | 480 /// sandbox. |
| 481 String _pathInSandbox(String relPath) { | 481 String _pathInSandbox(String relPath) { |
| 482 return p.join(p.absolute(sandboxDir), relPath); | 482 return p.join(p.absolute(sandboxDir), relPath); |
| 483 } | 483 } |
| 484 | 484 |
| 485 /// Gets the environment variables used to run pub in a test context. | 485 /// Gets the environment variables used to run pub in a test context. |
| 486 Map getPubTestEnvironment([Uri tokenEndpoint]) { | 486 Map getPubTestEnvironment([String tokenEndpoint]) { |
| 487 var environment = {}; | 487 var environment = {}; |
| 488 environment['_PUB_TESTING'] = 'true'; | 488 environment['_PUB_TESTING'] = 'true'; |
| 489 environment['PUB_CACHE'] = _pathInSandbox(cachePath); | 489 environment['PUB_CACHE'] = _pathInSandbox(cachePath); |
| 490 | 490 |
| 491 // Ensure a known SDK version is set for the tests that rely on that. | 491 // Ensure a known SDK version is set for the tests that rely on that. |
| 492 environment['_PUB_TEST_SDK_VERSION'] = "0.1.2+3"; | 492 environment['_PUB_TEST_SDK_VERSION'] = "0.1.2+3"; |
| 493 | 493 |
| 494 if (tokenEndpoint != null) { | 494 if (tokenEndpoint != null) { |
| 495 environment['_PUB_TEST_TOKEN_ENDPOINT'] = | 495 environment['_PUB_TEST_TOKEN_ENDPOINT'] = tokenEndpoint.toString(); |
| 496 tokenEndpoint.toString(); | |
| 497 } | 496 } |
| 498 | 497 |
| 499 return environment; | 498 return environment; |
| 500 } | 499 } |
| 501 | 500 |
| 502 /// Starts a Pub process and returns a [ScheduledProcess] that supports | 501 /// Starts a Pub process and returns a [ScheduledProcess] that supports |
| 503 /// interaction with that process. | 502 /// interaction with that process. |
| 504 /// | 503 /// |
| 505 /// Any futures in [args] will be resolved before the process is started. | 504 /// Any futures in [args] will be resolved before the process is started. |
| 506 ScheduledProcess startPub({List args, Future<Uri> tokenEndpoint}) { | 505 ScheduledProcess startPub({List args, Future<String> tokenEndpoint}) { |
| 507 ensureDir(_pathInSandbox(appPath)); | 506 ensureDir(_pathInSandbox(appPath)); |
| 508 | 507 |
| 509 // Find a Dart executable we can use to spawn. Use the same one that was | 508 // Find a Dart executable we can use to spawn. Use the same one that was |
| 510 // used to run this script itself. | 509 // used to run this script itself. |
| 511 var dartBin = Platform.executable; | 510 var dartBin = Platform.executable; |
| 512 | 511 |
| 513 // If the executable looks like a path, get its full path. That way we | 512 // If the executable looks like a path, get its full path. That way we |
| 514 // can still find it when we spawn it with a different working directory. | 513 // can still find it when we spawn it with a different working directory. |
| 515 if (dartBin.contains(Platform.pathSeparator)) { | 514 if (dartBin.contains(Platform.pathSeparator)) { |
| 516 dartBin = p.absolute(dartBin); | 515 dartBin = p.absolute(dartBin); |
| (...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 968 _lastMatcher.matches(item.last, matchState); | 967 _lastMatcher.matches(item.last, matchState); |
| 969 } | 968 } |
| 970 | 969 |
| 971 Description describe(Description description) { | 970 Description describe(Description description) { |
| 972 return description.addAll("(", ", ", ")", [_firstMatcher, _lastMatcher]); | 971 return description.addAll("(", ", ", ")", [_firstMatcher, _lastMatcher]); |
| 973 } | 972 } |
| 974 } | 973 } |
| 975 | 974 |
| 976 /// A [StreamMatcher] that matches multiple lines of output. | 975 /// A [StreamMatcher] that matches multiple lines of output. |
| 977 StreamMatcher emitsLines(String output) => inOrder(output.split("\n")); | 976 StreamMatcher emitsLines(String output) => inOrder(output.split("\n")); |
| OLD | NEW |