| 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. Unlike typical unit tests, most pub | 5 /// Test infrastructure for testing pub. Unlike typical unit tests, most pub |
| 6 /// tests are integration tests that stage some stuff on the file system, run | 6 /// tests are integration tests that stage some stuff on the file system, run |
| 7 /// pub, and then validate the results. This library provides an API to build | 7 /// pub, and then validate the results. This library provides an API to build |
| 8 /// tests like that. | 8 /// tests like that. |
| 9 library test_pub; | 9 library test_pub; |
| 10 | 10 |
| (...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 364 } | 364 } |
| 365 | 365 |
| 366 // Find the main pub entrypoint. | 366 // Find the main pub entrypoint. |
| 367 var pubPath = path.join(testDirectory, '..', 'bin', 'pub.dart'); | 367 var pubPath = path.join(testDirectory, '..', 'bin', 'pub.dart'); |
| 368 | 368 |
| 369 var dartArgs = ['--package-root=$_packageRoot/', '--checked', pubPath, | 369 var dartArgs = ['--package-root=$_packageRoot/', '--checked', pubPath, |
| 370 '--verbose']; | 370 '--verbose']; |
| 371 dartArgs.addAll(args); | 371 dartArgs.addAll(args); |
| 372 | 372 |
| 373 if (tokenEndpoint == null) tokenEndpoint = new Future.value(); | 373 if (tokenEndpoint == null) tokenEndpoint = new Future.value(); |
| 374 var optionsFuture = tokenEndpoint.then((tokenEndpoint) { | 374 var environmentFuture = tokenEndpoint.then((tokenEndpoint) { |
| 375 var options = new ProcessOptions(); | |
| 376 options.workingDirectory = pathInSandbox(appPath); | |
| 377 // TODO(nweiz): remove this when issue 9294 is fixed. | 375 // TODO(nweiz): remove this when issue 9294 is fixed. |
| 378 options.environment = new Map.from(Platform.environment); | 376 var environment = new Map.from(Platform.environment); |
| 379 options.environment['_PUB_TESTING'] = 'true'; | 377 environment['_PUB_TESTING'] = 'true'; |
| 380 options.environment['PUB_CACHE'] = pathInSandbox(cachePath); | 378 environment['PUB_CACHE'] = pathInSandbox(cachePath); |
| 381 options.environment['DART_SDK'] = pathInSandbox(sdkPath); | 379 environment['DART_SDK'] = pathInSandbox(sdkPath); |
| 382 if (tokenEndpoint != null) { | 380 if (tokenEndpoint != null) { |
| 383 options.environment['_PUB_TEST_TOKEN_ENDPOINT'] = | 381 environment['_PUB_TEST_TOKEN_ENDPOINT'] = |
| 384 tokenEndpoint.toString(); | 382 tokenEndpoint.toString(); |
| 385 } | 383 } |
| 386 return options; | 384 return environment; |
| 387 }); | 385 }); |
| 388 | 386 |
| 389 return new PubProcess.start(dartBin, dartArgs, options: optionsFuture, | 387 return new PubProcess.start(dartBin, dartArgs, environment: environmentFuture, |
| 388 workingDirectory: pathInSandbox(appPath), |
| 390 description: args.isEmpty ? 'pub' : 'pub ${args.first}'); | 389 description: args.isEmpty ? 'pub' : 'pub ${args.first}'); |
| 391 } | 390 } |
| 392 | 391 |
| 393 /// A subclass of [ScheduledProcess] that parses pub's verbose logging output | 392 /// A subclass of [ScheduledProcess] that parses pub's verbose logging output |
| 394 /// and makes [nextLine], [nextErrLine], [remainingStdout], and | 393 /// and makes [nextLine], [nextErrLine], [remainingStdout], and |
| 395 /// [remainingStderr] work as though pub weren't running in verbose mode. | 394 /// [remainingStderr] work as though pub weren't running in verbose mode. |
| 396 class PubProcess extends ScheduledProcess { | 395 class PubProcess extends ScheduledProcess { |
| 397 Stream<Pair<log.Level, String>> _log; | 396 Stream<Pair<log.Level, String>> _log; |
| 398 Stream<String> _stdout; | 397 Stream<String> _stdout; |
| 399 Stream<String> _stderr; | 398 Stream<String> _stderr; |
| 400 | 399 |
| 401 PubProcess.start(executable, arguments, | 400 PubProcess.start(executable, arguments, |
| 402 {options, String description, Encoding encoding: Encoding.UTF_8}) | 401 {workingDirectory, environment, String description, |
| 402 Encoding encoding: Encoding.UTF_8}) |
| 403 : super.start(executable, arguments, | 403 : super.start(executable, arguments, |
| 404 options: options, | 404 workingDirectory: workingDirectory, |
| 405 environment: environment, |
| 405 description: description, | 406 description: description, |
| 406 encoding: encoding); | 407 encoding: encoding); |
| 407 | 408 |
| 408 Stream<Pair<log.Level, String>> _logStream() { | 409 Stream<Pair<log.Level, String>> _logStream() { |
| 409 if (_log == null) { | 410 if (_log == null) { |
| 410 _log = mergeStreams( | 411 _log = mergeStreams( |
| 411 _outputToLog(super.stdoutStream(), log.Level.MESSAGE), | 412 _outputToLog(super.stdoutStream(), log.Level.MESSAGE), |
| 412 _outputToLog(super.stderrStream(), log.Level.ERROR)); | 413 _outputToLog(super.stderrStream(), log.Level.ERROR)); |
| 413 } | 414 } |
| 414 | 415 |
| (...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 682 bool matches(item, MatchState matchState) { | 683 bool matches(item, MatchState matchState) { |
| 683 if (item is! Pair) return false; | 684 if (item is! Pair) return false; |
| 684 return _firstMatcher.matches(item.first, matchState) && | 685 return _firstMatcher.matches(item.first, matchState) && |
| 685 _lastMatcher.matches(item.last, matchState); | 686 _lastMatcher.matches(item.last, matchState); |
| 686 } | 687 } |
| 687 | 688 |
| 688 Description describe(Description description) { | 689 Description describe(Description description) { |
| 689 description.addAll("(", ", ", ")", [_firstMatcher, _lastMatcher]); | 690 description.addAll("(", ", ", ")", [_firstMatcher, _lastMatcher]); |
| 690 } | 691 } |
| 691 } | 692 } |
| OLD | NEW |