| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 | 18 |
| 18 import '../../../pkg/http/lib/testing.dart'; | 19 import '../../../pkg/http/lib/testing.dart'; |
| 19 import '../../../pkg/oauth2/lib/oauth2.dart' as oauth2; | 20 import '../../../pkg/oauth2/lib/oauth2.dart' as oauth2; |
| 20 import '../../../pkg/path/lib/path.dart' as path; | 21 import '../../../pkg/path/lib/path.dart' as path; |
| 21 import '../../../pkg/unittest/lib/unittest.dart'; | 22 import '../../../pkg/unittest/lib/unittest.dart'; |
| 22 import '../../../pkg/yaml/lib/yaml.dart'; | 23 import '../../../pkg/yaml/lib/yaml.dart'; |
| 23 import '../../lib/file_system.dart' as fs; | 24 import '../../lib/file_system.dart' as fs; |
| 24 import '../../pub/entrypoint.dart'; | 25 import '../../pub/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 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 42 // If we aren't running on the bots, use the human-friendly config. | 43 // If we aren't running on the bots, use the human-friendly config. |
| 43 if (new Options().arguments.contains('--human')) { | 44 if (new Options().arguments.contains('--human')) { |
| 44 configure(new CommandLineConfiguration()); | 45 configure(new CommandLineConfiguration()); |
| 45 } | 46 } |
| 46 } | 47 } |
| 47 | 48 |
| 48 /// Creates a new [FileDescriptor] with [name] and [contents]. | 49 /// Creates a new [FileDescriptor] with [name] and [contents]. |
| 49 FileDescriptor file(Pattern name, String contents) => | 50 FileDescriptor file(Pattern name, String contents) => |
| 50 new FileDescriptor(name, contents); | 51 new FileDescriptor(name, contents); |
| 51 | 52 |
| 53 /// Creates a new [FileDescriptor] with [name] and [contents]. |
| 54 FileDescriptor binaryFile(Pattern name, List<int> contents) => |
| 55 new FileDescriptor.bytes(name, contents); |
| 56 |
| 52 /// Creates a new [DirectoryDescriptor] with [name] and [contents]. | 57 /// Creates a new [DirectoryDescriptor] with [name] and [contents]. |
| 53 DirectoryDescriptor dir(Pattern name, [List<Descriptor> contents]) => | 58 DirectoryDescriptor dir(Pattern name, [List<Descriptor> contents]) => |
| 54 new DirectoryDescriptor(name, contents); | 59 new DirectoryDescriptor(name, contents); |
| 55 | 60 |
| 56 /// Creates a new [FutureDescriptor] wrapping [future]. | 61 /// Creates a new [FutureDescriptor] wrapping [future]. |
| 57 FutureDescriptor async(Future<Descriptor> future) => | 62 FutureDescriptor async(Future<Descriptor> future) => |
| 58 new FutureDescriptor(future); | 63 new FutureDescriptor(future); |
| 59 | 64 |
| 60 /// Creates a new [GitRepoDescriptor] with [name] and [contents]. | 65 /// Creates a new [GitRepoDescriptor] with [name] and [contents]. |
| 61 GitRepoDescriptor git(Pattern name, [List<Descriptor> contents]) => | 66 GitRepoDescriptor git(Pattern name, [List<Descriptor> contents]) => |
| (...skipping 797 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 859 } | 864 } |
| 860 return completer.future; | 865 return completer.future; |
| 861 }); | 866 }); |
| 862 } | 867 } |
| 863 } | 868 } |
| 864 | 869 |
| 865 /// Describes a file. These are used both for setting up an expected directory | 870 /// Describes a file. These are used both for setting up an expected directory |
| 866 /// tree before running a test, and for validating that the file system matches | 871 /// tree before running a test, and for validating that the file system matches |
| 867 /// some expectations after running it. | 872 /// some expectations after running it. |
| 868 class FileDescriptor extends Descriptor { | 873 class FileDescriptor extends Descriptor { |
| 869 /// The text contents of the file. | 874 /// The contents of the file, in bytes. |
| 870 final String contents; | 875 final List<int> contents; |
| 871 | 876 |
| 872 FileDescriptor(Pattern name, this.contents) : super(name); | 877 FileDescriptor.bytes(Pattern name, this.contents) : super(name); |
| 878 |
| 879 FileDescriptor(Pattern name, String contents) : |
| 880 this.bytes(name, encodeUtf8(contents)); |
| 873 | 881 |
| 874 /// Creates the file within [dir]. Returns a [Future] that is completed after | 882 /// Creates the file within [dir]. Returns a [Future] that is completed after |
| 875 /// the creation is done. | 883 /// the creation is done. |
| 876 Future<File> create(dir) { | 884 Future<File> create(dir) => writeByteFile(join(dir, _stringName), contents); |
| 877 return writeTextFile(join(dir, _stringName), contents); | |
| 878 } | |
| 879 | 885 |
| 880 /// Deletes the file within [dir]. Returns a [Future] that is completed after | 886 /// Deletes the file within [dir]. Returns a [Future] that is completed after |
| 881 /// the deletion is done. | 887 /// the deletion is done. |
| 882 Future delete(dir) { | 888 Future delete(dir) { |
| 883 return deleteFile(join(dir, _stringName)); | 889 return deleteFile(join(dir, _stringName)); |
| 884 } | 890 } |
| 885 | 891 |
| 886 /// Validates that this file correctly matches the actual file at [path]. | 892 /// Validates that this file correctly matches the actual file at [path]. |
| 887 Future validate(String path) { | 893 Future validate(String path) { |
| 888 return _validateOneMatch(path, (file) { | 894 return _validateOneMatch(path, (file) { |
| (...skipping 661 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1550 /// calling [completion] is unnecessary. | 1556 /// calling [completion] is unnecessary. |
| 1551 void expectLater(Future actual, matcher, {String reason, | 1557 void expectLater(Future actual, matcher, {String reason, |
| 1552 FailureHandler failureHandler, bool verbose: false}) { | 1558 FailureHandler failureHandler, bool verbose: false}) { |
| 1553 _schedule((_) { | 1559 _schedule((_) { |
| 1554 return actual.then((value) { | 1560 return actual.then((value) { |
| 1555 expect(value, matcher, reason: reason, failureHandler: failureHandler, | 1561 expect(value, matcher, reason: reason, failureHandler: failureHandler, |
| 1556 verbose: false); | 1562 verbose: false); |
| 1557 }); | 1563 }); |
| 1558 }); | 1564 }); |
| 1559 } | 1565 } |
| OLD | NEW |