Chromium Code Reviews| 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 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 362 } | 362 } |
| 363 | 363 |
| 364 // Find the main pub entrypoint. | 364 // Find the main pub entrypoint. |
| 365 var pubPath = path.join(testDirectory, '..', 'bin', 'pub.dart'); | 365 var pubPath = path.join(testDirectory, '..', 'bin', 'pub.dart'); |
| 366 | 366 |
| 367 var dartArgs = ['--package-root=$_packageRoot/', '--checked', pubPath, | 367 var dartArgs = ['--package-root=$_packageRoot/', '--checked', pubPath, |
| 368 '--verbose']; | 368 '--verbose']; |
| 369 dartArgs.addAll(args); | 369 dartArgs.addAll(args); |
| 370 | 370 |
| 371 if (tokenEndpoint == null) tokenEndpoint = new Future.value(); | 371 if (tokenEndpoint == null) tokenEndpoint = new Future.value(); |
| 372 var optionsFuture = tokenEndpoint.then((tokenEndpoint) { | 372 var environmentFuture = tokenEndpoint.then((tokenEndpoint) { |
| 373 var options = new ProcessOptions(); | |
| 374 options.workingDirectory = pathInSandbox(appPath); | |
| 375 // TODO(nweiz): remove this when issue 9294 is fixed. | 373 // TODO(nweiz): remove this when issue 9294 is fixed. |
| 376 options.environment = new Map.from(Platform.environment); | 374 var environment = new Map.from(Platform.environment); |
|
nweiz
2013/07/22 20:15:11
Since 9294 is fixed, this should just be initializ
| |
| 377 options.environment['_PUB_TESTING'] = 'true'; | 375 environment['_PUB_TESTING'] = 'true'; |
| 378 options.environment['PUB_CACHE'] = pathInSandbox(cachePath); | 376 environment['PUB_CACHE'] = pathInSandbox(cachePath); |
| 379 options.environment['DART_SDK'] = pathInSandbox(sdkPath); | 377 environment['DART_SDK'] = pathInSandbox(sdkPath); |
| 380 if (tokenEndpoint != null) { | 378 if (tokenEndpoint != null) { |
| 381 options.environment['_PUB_TEST_TOKEN_ENDPOINT'] = | 379 environment['_PUB_TEST_TOKEN_ENDPOINT'] = |
| 382 tokenEndpoint.toString(); | 380 tokenEndpoint.toString(); |
| 383 } | 381 } |
| 384 return options; | 382 return environment; |
| 385 }); | 383 }); |
| 386 | 384 |
| 387 return new PubProcess.start(dartBin, dartArgs, options: optionsFuture, | 385 return new PubProcess.start(dartBin, dartArgs, environment: environmentFuture, |
| 386 workingDirectory: pathInSandbox(appPath), | |
| 388 description: args.isEmpty ? 'pub' : 'pub ${args.first}'); | 387 description: args.isEmpty ? 'pub' : 'pub ${args.first}'); |
| 389 } | 388 } |
| 390 | 389 |
| 391 /// A subclass of [ScheduledProcess] that parses pub's verbose logging output | 390 /// A subclass of [ScheduledProcess] that parses pub's verbose logging output |
| 392 /// and makes [nextLine], [nextErrLine], [remainingStdout], and | 391 /// and makes [nextLine], [nextErrLine], [remainingStdout], and |
| 393 /// [remainingStderr] work as though pub weren't running in verbose mode. | 392 /// [remainingStderr] work as though pub weren't running in verbose mode. |
| 394 class PubProcess extends ScheduledProcess { | 393 class PubProcess extends ScheduledProcess { |
| 395 Stream<Pair<log.Level, String>> _log; | 394 Stream<Pair<log.Level, String>> _log; |
| 396 Stream<String> _stdout; | 395 Stream<String> _stdout; |
| 397 Stream<String> _stderr; | 396 Stream<String> _stderr; |
| 398 | 397 |
| 399 PubProcess.start(executable, arguments, | 398 PubProcess.start(executable, arguments, |
| 400 {options, String description, Encoding encoding: Encoding.UTF_8}) | 399 {workingDirectory, environment, String description, |
| 400 Encoding encoding: Encoding.UTF_8}) | |
| 401 : super.start(executable, arguments, | 401 : super.start(executable, arguments, |
| 402 options: options, | 402 workingDirectory: workingDirectory, |
| 403 environment: environment, | |
| 403 description: description, | 404 description: description, |
| 404 encoding: encoding); | 405 encoding: encoding); |
| 405 | 406 |
| 406 Stream<Pair<log.Level, String>> _logStream() { | 407 Stream<Pair<log.Level, String>> _logStream() { |
| 407 if (_log == null) { | 408 if (_log == null) { |
| 408 _log = mergeStreams( | 409 _log = mergeStreams( |
| 409 _outputToLog(super.stdoutStream(), log.Level.MESSAGE), | 410 _outputToLog(super.stdoutStream(), log.Level.MESSAGE), |
| 410 _outputToLog(super.stderrStream(), log.Level.ERROR)); | 411 _outputToLog(super.stderrStream(), log.Level.ERROR)); |
| 411 } | 412 } |
| 412 | 413 |
| (...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 680 bool matches(item, MatchState matchState) { | 681 bool matches(item, MatchState matchState) { |
| 681 if (item is! Pair) return false; | 682 if (item is! Pair) return false; |
| 682 return _firstMatcher.matches(item.first, matchState) && | 683 return _firstMatcher.matches(item.first, matchState) && |
| 683 _lastMatcher.matches(item.last, matchState); | 684 _lastMatcher.matches(item.last, matchState); |
| 684 } | 685 } |
| 685 | 686 |
| 686 Description describe(Description description) { | 687 Description describe(Description description) { |
| 687 description.addAll("(", ", ", ")", [_firstMatcher, _lastMatcher]); | 688 description.addAll("(", ", ", ")", [_firstMatcher, _lastMatcher]); |
| 688 } | 689 } |
| 689 } | 690 } |
| OLD | NEW |