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 import 'dart:async'; | 10 import 'dart:async'; |
11 import 'dart:convert'; | 11 import 'dart:convert'; |
12 import 'dart:io'; | 12 import 'dart:io'; |
13 import 'dart:math'; | 13 import 'dart:math'; |
14 | 14 |
15 import 'package:async/async.dart'; | 15 import 'package:async/async.dart'; |
16 import 'package:http/testing.dart'; | 16 import 'package:http/testing.dart'; |
| 17 import 'package:package_resolver/package_resolver.dart'; |
17 import 'package:path/path.dart' as p; | 18 import 'package:path/path.dart' as p; |
18 import 'package:pub/src/entrypoint.dart'; | 19 import 'package:pub/src/entrypoint.dart'; |
19 import 'package:pub/src/exceptions.dart'; | 20 import 'package:pub/src/exceptions.dart'; |
20 import 'package:pub/src/exit_codes.dart' as exit_codes; | 21 import 'package:pub/src/exit_codes.dart' as exit_codes; |
21 // TODO(rnystrom): Using "gitlib" as the prefix here is ugly, but "git" collides | 22 // TODO(rnystrom): Using "gitlib" as the prefix here is ugly, but "git" collides |
22 // with the git descriptor method. Maybe we should try to clean up the top level | 23 // with the git descriptor method. Maybe we should try to clean up the top level |
23 // scope a bit? | 24 // scope a bit? |
24 import 'package:pub/src/git.dart' as gitlib; | 25 import 'package:pub/src/git.dart' as gitlib; |
25 import 'package:pub/src/http.dart'; | 26 import 'package:pub/src/http.dart'; |
26 import 'package:pub/src/io.dart'; | 27 import 'package:pub/src/io.dart'; |
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
339 | 340 |
340 // If there's a snapshot available, use it. The user is responsible for | 341 // If there's a snapshot available, use it. The user is responsible for |
341 // ensuring this is up-to-date.. | 342 // ensuring this is up-to-date.. |
342 // | 343 // |
343 // TODO(nweiz): When the test runner supports plugins, create one to | 344 // TODO(nweiz): When the test runner supports plugins, create one to |
344 // auto-generate the snapshot before each run. | 345 // auto-generate the snapshot before each run. |
345 var pubPath = p.absolute(p.join(pubRoot, 'bin/pub.dart')); | 346 var pubPath = p.absolute(p.join(pubRoot, 'bin/pub.dart')); |
346 if (fileExists('$pubPath.snapshot')) pubPath += '.snapshot'; | 347 if (fileExists('$pubPath.snapshot')) pubPath += '.snapshot'; |
347 | 348 |
348 var dartArgs = <dynamic>[ | 349 var dartArgs = <dynamic>[ |
349 '--package-root=${p.toUri(p.absolute(p.fromUri(Platform.packageRoot)))}', | 350 PackageResolver.current.processArgument, |
350 pubPath, | 351 pubPath, |
351 '--verbose' | 352 '--verbose' |
352 ]..addAll(args); | 353 ]..addAll(args); |
353 | 354 |
354 if (tokenEndpoint == null) tokenEndpoint = new Future.value(); | 355 if (tokenEndpoint == null) tokenEndpoint = new Future.value(); |
355 var environmentFuture = tokenEndpoint | 356 var environmentFuture = tokenEndpoint |
356 .then((tokenEndpoint) => getPubTestEnvironment(tokenEndpoint)) | 357 .then((tokenEndpoint) => getPubTestEnvironment(tokenEndpoint)) |
357 .then((pubEnvironment) { | 358 .then((pubEnvironment) { |
358 if (environment != null) pubEnvironment.addAll(environment); | 359 if (environment != null) pubEnvironment.addAll(environment); |
359 return pubEnvironment; | 360 return pubEnvironment; |
(...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
756 _lastMatcher.matches(item.last, matchState); | 757 _lastMatcher.matches(item.last, matchState); |
757 } | 758 } |
758 | 759 |
759 Description describe(Description description) { | 760 Description describe(Description description) { |
760 return description.addAll("(", ", ", ")", [_firstMatcher, _lastMatcher]); | 761 return description.addAll("(", ", ", ")", [_firstMatcher, _lastMatcher]); |
761 } | 762 } |
762 } | 763 } |
763 | 764 |
764 /// A [StreamMatcher] that matches multiple lines of output. | 765 /// A [StreamMatcher] that matches multiple lines of output. |
765 StreamMatcher emitsLines(String output) => inOrder(output.split("\n")); | 766 StreamMatcher emitsLines(String output) => inOrder(output.split("\n")); |
OLD | NEW |