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 |
| 11 import 'dart:async'; | 11 import 'dart:async'; |
| 12 import 'dart:convert'; | 12 import 'dart:convert'; |
| 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 | 16 |
| 17 import 'package:http/testing.dart'; | 17 import 'package:http/testing.dart'; |
| 18 import 'package:path/path.dart' as path; | 18 import 'package:path/path.dart' as path; |
| 19 import 'package:scheduled_test/scheduled_process.dart'; | 19 import 'package:scheduled_test/scheduled_process.dart'; |
| 20 import 'package:scheduled_test/scheduled_server.dart'; | 20 import 'package:scheduled_test/scheduled_server.dart'; |
| 21 import 'package:scheduled_test/scheduled_test.dart'; | 21 import 'package:scheduled_test/scheduled_test.dart'; |
| 22 import 'package:unittest/compact_vm_config.dart'; | 22 import 'package:unittest/compact_vm_config.dart'; |
| 23 import 'package:yaml/yaml.dart'; | |
| 23 | 24 |
| 24 import '../lib/src/entrypoint.dart'; | 25 import '../lib/src/entrypoint.dart'; |
| 25 // TODO(rnystrom): Using "gitlib" as the prefix here is ugly, but "git" collides | 26 // TODO(rnystrom): Using "gitlib" as the prefix here is ugly, but "git" collides |
| 26 // with the git descriptor method. Maybe we should try to clean up the top level | 27 // with the git descriptor method. Maybe we should try to clean up the top level |
| 27 // scope a bit? | 28 // scope a bit? |
| 28 import '../lib/src/git.dart' as gitlib; | 29 import '../lib/src/git.dart' as gitlib; |
| 29 import '../lib/src/http.dart'; | 30 import '../lib/src/http.dart'; |
| 30 import '../lib/src/io.dart'; | 31 import '../lib/src/io.dart'; |
| 32 import '../lib/src/lock_file.dart'; | |
| 31 import '../lib/src/log.dart' as log; | 33 import '../lib/src/log.dart' as log; |
| 34 import '../lib/src/package.dart'; | |
| 32 import '../lib/src/safe_http_server.dart'; | 35 import '../lib/src/safe_http_server.dart'; |
| 33 import '../lib/src/system_cache.dart'; | 36 import '../lib/src/system_cache.dart'; |
| 34 import '../lib/src/utils.dart'; | 37 import '../lib/src/utils.dart'; |
| 35 import '../lib/src/validator.dart'; | 38 import '../lib/src/validator.dart'; |
| 39 import '../lib/src/version.dart'; | |
| 36 import 'descriptor.dart' as d; | 40 import 'descriptor.dart' as d; |
| 37 | 41 |
| 38 /// This should be called at the top of a test file to set up an appropriate | 42 /// This should be called at the top of a test file to set up an appropriate |
| 39 /// test configuration for the machine running the tests. | 43 /// test configuration for the machine running the tests. |
| 40 initConfig() { | 44 initConfig() { |
| 41 useCompactVMConfiguration(); | 45 useCompactVMConfiguration(); |
| 42 } | 46 } |
| 43 | 47 |
| 44 /// Returns whether we're running on a Dart build bot. | 48 /// Returns whether we're running on a Dart build bot. |
| 45 bool get runningOnBuildbot => | 49 bool get runningOnBuildbot => |
| (...skipping 546 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 592 | 596 |
| 593 schedule(() { | 597 schedule(() { |
| 594 return gitlib.isInstalled.then((installed) { | 598 return gitlib.isInstalled.then((installed) { |
| 595 if (installed) return; | 599 if (installed) return; |
| 596 if (runningOnBuildbot) return; | 600 if (runningOnBuildbot) return; |
| 597 currentSchedule.abort(); | 601 currentSchedule.abort(); |
| 598 }); | 602 }); |
| 599 }, 'ensuring that Git is installed'); | 603 }, 'ensuring that Git is installed'); |
| 600 } | 604 } |
| 601 | 605 |
| 606 /// Create a lock file for [package] without running `pub install`. | |
| 607 /// | |
| 608 /// This creates a lock file with only path dependencies. [dependencies] is a | |
| 609 /// map of dependency names to paths. [pkg] is a list of Dart SDK packages; each | |
|
Bob Nystrom
2013/08/27 22:12:30
"Dart SDK packages" -> 'packages in the Dart repo'
nweiz
2013/08/28 20:45:23
Done.
| |
| 610 /// package listed here and all its dependencies will be linked to the version | |
| 611 /// in the Dart SDK. | |
|
Bob Nystrom
2013/08/27 22:12:30
"SDK" -> "repo".
nweiz
2013/08/28 20:45:23
Done.
| |
| 612 void createLockFile(String package, Map<String, String> dependencies, | |
| 613 {Iterable<String> pkg}) { | |
| 614 if (pkg != null) { | |
| 615 var pkgDir = path.absolute(path.join( | |
| 616 path.dirname(Platform.executable), | |
| 617 '..', '..', '..', '..', 'pkg')); | |
| 618 | |
| 619 _addPackage(String package) { | |
| 620 if (dependencies.containsKey(package)) return; | |
| 621 var packagePath = path.join(pkgDir, package); | |
| 622 dependencies[package] = packagePath; | |
| 623 var pubspec = loadYaml( | |
| 624 readTextFile(path.join(packagePath, 'pubspec.yaml'))); | |
|
Bob Nystrom
2013/08/27 22:12:30
How about using Pubspec.parse() here?
nweiz
2013/08/28 20:45:23
That requires setting up a SourceRegistry, which i
Bob Nystrom
2013/08/29 00:12:01
You should be able to just make an empty source re
nweiz
2013/09/04 00:21:58
It requires at least a real default source.
| |
| 625 var packageDeps = pubspec['dependencies']; | |
| 626 if (packageDeps == null) return; | |
| 627 packageDeps.keys.forEach(_addPackage); | |
| 628 } | |
| 629 | |
| 630 pkg.forEach(_addPackage); | |
| 631 } | |
| 632 | |
| 633 var lockFile = new LockFile.empty(); | |
| 634 dependencies.forEach((name, dependencyPath) { | |
| 635 var id = new PackageId(name, 'path', new Version(0, 0, 0), { | |
| 636 'path': dependencyPath, | |
| 637 'relative': path.isRelative(dependencyPath) | |
| 638 }); | |
| 639 lockFile.packages[name] = id; | |
| 640 }); | |
| 641 d.file(path.join(package, 'pubspec.lock'), lockFile.serialize()).create(); | |
| 642 } | |
| 643 | |
| 602 /// Use [client] as the mock HTTP client for this test. | 644 /// Use [client] as the mock HTTP client for this test. |
| 603 /// | 645 /// |
| 604 /// Note that this will only affect HTTP requests made via http.dart in the | 646 /// Note that this will only affect HTTP requests made via http.dart in the |
| 605 /// parent process. | 647 /// parent process. |
| 606 void useMockClient(MockClient client) { | 648 void useMockClient(MockClient client) { |
| 607 var oldInnerClient = httpClient.inner; | 649 var oldInnerClient = httpClient.inner; |
| 608 httpClient.inner = client; | 650 httpClient.inner = client; |
| 609 currentSchedule.onComplete.schedule(() { | 651 currentSchedule.onComplete.schedule(() { |
| 610 httpClient.inner = oldInnerClient; | 652 httpClient.inner = oldInnerClient; |
| 611 }, 'de-activating the mock client'); | 653 }, 'de-activating the mock client'); |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 784 bool matches(item, Map matchState) { | 826 bool matches(item, Map matchState) { |
| 785 if (item is! Pair) return false; | 827 if (item is! Pair) return false; |
| 786 return _firstMatcher.matches(item.first, matchState) && | 828 return _firstMatcher.matches(item.first, matchState) && |
| 787 _lastMatcher.matches(item.last, matchState); | 829 _lastMatcher.matches(item.last, matchState); |
| 788 } | 830 } |
| 789 | 831 |
| 790 Description describe(Description description) { | 832 Description describe(Description description) { |
| 791 description.addAll("(", ", ", ")", [_firstMatcher, _lastMatcher]); | 833 description.addAll("(", ", ", ")", [_firstMatcher, _lastMatcher]); |
| 792 } | 834 } |
| 793 } | 835 } |
| OLD | NEW |