| 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 |
| 11 import 'dart:async'; | 11 import 'dart:async'; |
| 12 import 'dart:collection' show Queue; | 12 import 'dart:collection' show Queue; |
| 13 import 'dart:io'; | 13 import 'dart:io'; |
| 14 import 'dart:json' as json; | 14 import 'dart:json' as json; |
| 15 import 'dart:math'; | 15 import 'dart:math'; |
| 16 import 'dart:uri'; | 16 import 'dart:uri'; |
| 17 import 'dart:utf'; | 17 import 'dart:utf'; |
| 18 | 18 |
| 19 import '../../../pkg/http/lib/testing.dart'; | 19 import 'package:http/testing.dart'; |
| 20 import '../../../pkg/oauth2/lib/oauth2.dart' as oauth2; | 20 import 'package:oauth2/oauth2.dart' as oauth2; |
| 21 import '../../../pkg/pathos/lib/path.dart' as path; | 21 import 'package:pathos/path.dart' as path; |
| 22 import '../../../pkg/scheduled_test/lib/scheduled_process.dart'; | 22 import 'package:scheduled_test/scheduled_process.dart'; |
| 23 import '../../../pkg/scheduled_test/lib/scheduled_server.dart'; | 23 import 'package:scheduled_test/scheduled_server.dart'; |
| 24 import '../../../pkg/scheduled_test/lib/scheduled_test.dart'; | 24 import 'package:scheduled_test/scheduled_test.dart'; |
| 25 import '../../../pkg/yaml/lib/yaml.dart'; | 25 import 'package:yaml/yaml.dart'; |
| 26 | 26 |
| 27 import '../../lib/file_system.dart' as fs; | |
| 28 import '../../pub/entrypoint.dart'; | 27 import '../../pub/entrypoint.dart'; |
| 29 // TODO(rnystrom): Using "gitlib" as the prefix here is ugly, but "git" collides | 28 // TODO(rnystrom): Using "gitlib" as the prefix here is ugly, but "git" collides |
| 30 // with the git descriptor method. Maybe we should try to clean up the top level | 29 // with the git descriptor method. Maybe we should try to clean up the top level |
| 31 // scope a bit? | 30 // scope a bit? |
| 32 import '../../pub/git.dart' as gitlib; | 31 import '../../pub/git.dart' as gitlib; |
| 33 import '../../pub/git_source.dart'; | 32 import '../../pub/git_source.dart'; |
| 34 import '../../pub/hosted_source.dart'; | 33 import '../../pub/hosted_source.dart'; |
| 35 import '../../pub/http.dart'; | 34 import '../../pub/http.dart'; |
| 36 import '../../pub/io.dart'; | 35 import '../../pub/io.dart'; |
| 37 import '../../pub/path_source.dart'; | 36 import '../../pub/path_source.dart'; |
| (...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 334 // used to run this script itself. | 333 // used to run this script itself. |
| 335 var dartBin = new Options().executable; | 334 var dartBin = new Options().executable; |
| 336 | 335 |
| 337 // If the executable looks like a path, get its full path. That way we | 336 // If the executable looks like a path, get its full path. That way we |
| 338 // can still find it when we spawn it with a different working directory. | 337 // can still find it when we spawn it with a different working directory. |
| 339 if (dartBin.contains(Platform.pathSeparator)) { | 338 if (dartBin.contains(Platform.pathSeparator)) { |
| 340 dartBin = new File(dartBin).fullPathSync(); | 339 dartBin = new File(dartBin).fullPathSync(); |
| 341 } | 340 } |
| 342 | 341 |
| 343 // Find the main pub entrypoint. | 342 // Find the main pub entrypoint. |
| 344 var pubPath = fs.joinPaths(testDirectory, '../../pub/pub.dart'); | 343 var pubPath = path.join(testDirectory, '..', '..', 'pub', 'pub.dart'); |
| 345 | 344 |
| 346 var dartArgs = ['--checked', pubPath, '--trace']; | 345 var dartArgs = ['--package-root=$_packageRoot/', '--checked', pubPath, |
| 346 '--trace']; |
| 347 dartArgs.addAll(args); | 347 dartArgs.addAll(args); |
| 348 | 348 |
| 349 if (tokenEndpoint == null) tokenEndpoint = new Future.immediate(null); | 349 if (tokenEndpoint == null) tokenEndpoint = new Future.immediate(null); |
| 350 var optionsFuture = tokenEndpoint.then((tokenEndpoint) { | 350 var optionsFuture = tokenEndpoint.then((tokenEndpoint) { |
| 351 var options = new ProcessOptions(); | 351 var options = new ProcessOptions(); |
| 352 options.workingDirectory = pathInSandbox(appPath); | 352 options.workingDirectory = pathInSandbox(appPath); |
| 353 // TODO(nweiz): remove this when issue 9294 is fixed. | 353 // TODO(nweiz): remove this when issue 9294 is fixed. |
| 354 options.environment = new Map.from(Platform.environment); | 354 options.environment = new Map.from(Platform.environment); |
| 355 options.environment['PUB_CACHE'] = pathInSandbox(cachePath); | 355 options.environment['PUB_CACHE'] = pathInSandbox(cachePath); |
| 356 options.environment['DART_SDK'] = pathInSandbox(sdkPath); | 356 options.environment['DART_SDK'] = pathInSandbox(sdkPath); |
| 357 if (tokenEndpoint != null) { | 357 if (tokenEndpoint != null) { |
| 358 options.environment['_PUB_TEST_TOKEN_ENDPOINT'] = | 358 options.environment['_PUB_TEST_TOKEN_ENDPOINT'] = |
| 359 tokenEndpoint.toString(); | 359 tokenEndpoint.toString(); |
| 360 } | 360 } |
| 361 return options; | 361 return options; |
| 362 }); | 362 }); |
| 363 | 363 |
| 364 return new ScheduledProcess.start(dartBin, dartArgs, options: optionsFuture, | 364 return new ScheduledProcess.start(dartBin, dartArgs, options: optionsFuture, |
| 365 description: args.isEmpty ? 'pub' : 'pub ${args.first}'); | 365 description: args.isEmpty ? 'pub' : 'pub ${args.first}'); |
| 366 } | 366 } |
| 367 | 367 |
| 368 /// Whether pub is running from within the Dart SDK, as opposed to from the Dart |
| 369 /// source repository. |
| 370 bool get _runningFromSdk => path.dirname(relativeToPub('..')) == 'util'; |
| 371 |
| 372 // TODO(nweiz): use the built-in mechanism for accessing this once it exists |
| 373 // (issue 9119). |
| 374 /// The path to the `packages` directory from which pub loads its dependencies. |
| 375 String get _packageRoot { |
| 376 if (_runningFromSdk) { |
| 377 return path.absolute(relativeToPub(path.join('..', '..', 'packages'))); |
| 378 } else { |
| 379 return path.absolute(path.join( |
| 380 path.dirname(new Options().executable), '..', '..', 'packages')); |
| 381 } |
| 382 } |
| 383 |
| 368 /// Skips the current test if Git is not installed. This validates that the | 384 /// Skips the current test if Git is not installed. This validates that the |
| 369 /// current test is running on a buildbot in which case we expect git to be | 385 /// current test is running on a buildbot in which case we expect git to be |
| 370 /// installed. If we are not running on the buildbot, we will instead see if | 386 /// installed. If we are not running on the buildbot, we will instead see if |
| 371 /// git is installed and skip the test if not. This way, users don't need to | 387 /// git is installed and skip the test if not. This way, users don't need to |
| 372 /// have git installed to run the tests locally (unless they actually care | 388 /// have git installed to run the tests locally (unless they actually care |
| 373 /// about the pub git tests). | 389 /// about the pub git tests). |
| 374 /// | 390 /// |
| 375 /// This will also increase the [Schedule] timeout to 30 seconds on Windows, | 391 /// This will also increase the [Schedule] timeout to 30 seconds on Windows, |
| 376 /// where Git runs really slowly. | 392 /// where Git runs really slowly. |
| 377 void ensureGit() { | 393 void ensureGit() { |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 584 bool matches(item, MatchState matchState) { | 600 bool matches(item, MatchState matchState) { |
| 585 if (item is! Pair) return false; | 601 if (item is! Pair) return false; |
| 586 return _firstMatcher.matches(item.first, matchState) && | 602 return _firstMatcher.matches(item.first, matchState) && |
| 587 _lastMatcher.matches(item.last, matchState); | 603 _lastMatcher.matches(item.last, matchState); |
| 588 } | 604 } |
| 589 | 605 |
| 590 Description describe(Description description) { | 606 Description describe(Description description) { |
| 591 description.addAll("(", ", ", ")", [_firstMatcher, _lastMatcher]); | 607 description.addAll("(", ", ", ")", [_firstMatcher, _lastMatcher]); |
| 592 } | 608 } |
| 593 } | 609 } |
| OLD | NEW |