| Index: utils/tests/pub/test_pub.dart
|
| diff --git a/utils/tests/pub/test_pub.dart b/utils/tests/pub/test_pub.dart
|
| index 49b64e88f2767c3d310bce94271b9395a5014107..73dbd111f1e6932f38891d8218c71840612e03d8 100644
|
| --- a/utils/tests/pub/test_pub.dart
|
| +++ b/utils/tests/pub/test_pub.dart
|
| @@ -28,10 +28,12 @@ FileDescriptor file(String name, String contents) =>
|
| DirectoryDescriptor dir(String name, [List<Descriptor> contents]) =>
|
| new DirectoryDescriptor(name, contents);
|
|
|
| -void testPub(String description, [List<Descriptor> cache, List<String> args,
|
| +void testPub(String description, [List<Descriptor> cache, Descriptor app,
|
| + List<String> args, List<Descriptor> expectedPackageDir,
|
| String output, int exitCode = 0]) {
|
| asyncTest(description, 1, () {
|
| var createdSandboxDir;
|
| + var createdAppDir;
|
|
|
| deleteSandboxIfCreated() {
|
| if (createdSandboxDir != null) {
|
| @@ -45,18 +47,22 @@ void testPub(String description, [List<Descriptor> cache, List<String> args,
|
|
|
| final future = _setUpSandbox().chain((sandboxDir) {
|
| createdSandboxDir = sandboxDir;
|
| - return _setUpCache(sandboxDir, cache);
|
| + return _setUpApp(sandboxDir, app);
|
| + }).chain((appDir) {
|
| + createdAppDir = appDir;
|
| + return _setUpCache(createdSandboxDir, cache);
|
| }).chain((cacheDir) {
|
| + var workingDir;
|
| + if (createdAppDir != null) workingDir = createdAppDir.path;
|
| +
|
| if (cacheDir != null) {
|
| // TODO(rnystrom): Hack in the cache directory path. Should pass this
|
| // in using environment var once #752 is done.
|
| - args.add('--cachedir=${cacheDir.path}');
|
| + args.add('--cachedir=${getFullPath(cacheDir)}');
|
| }
|
|
|
| - return _runPub(args);
|
| - });
|
| -
|
| - future.then((result) {
|
| + return _runPub(args, workingDir);
|
| + }).chain((result) {
|
| _validateOutput(output, result.stdout);
|
|
|
| Expect.equals(result.stderr.length, 0,
|
| @@ -66,6 +72,11 @@ void testPub(String description, [List<Descriptor> cache, List<String> args,
|
| Expect.equals(result.exitCode, exitCode,
|
| 'Pub returned exit code ${result.exitCode}, expected $exitCode.');
|
|
|
| + return _validateExpectedPackages(createdAppDir, expectedPackageDir);
|
| + });
|
| +
|
| + future.then((valid) {
|
| + Expect.isTrue(valid); // TODO(bob): Report which expectation failed.
|
| deleteSandboxIfCreated();
|
| });
|
|
|
| @@ -86,7 +97,14 @@ Future _setUpCache(Directory sandboxDir, List<Descriptor> cache) {
|
| return dir('pub-cache', cache).create(sandboxDir);
|
| }
|
|
|
| -Future<ProcessResult> _runPub(List<String> pubArgs) {
|
| +Future _setUpApp(Directory sandboxDir, Descriptor app) {
|
| + // No app directory.
|
| + if (app == null) return new Future.immediate(null);
|
| +
|
| + return app.create(sandboxDir);
|
| +}
|
| +
|
| +Future<ProcessResult> _runPub(List<String> pubArgs, String workingDir) {
|
| // Find a dart executable we can use to run pub. Uses the one that the
|
| // test infrastructure uses.
|
| final scriptDir = new File(new Options().script).directorySync().path;
|
| @@ -99,7 +117,15 @@ Future<ProcessResult> _runPub(List<String> pubArgs) {
|
| final args = [pubPath];
|
| args.addAll(pubArgs);
|
|
|
| - return runProcess(dartBin, args);
|
| + return runProcess(dartBin, args, workingDir);
|
| +}
|
| +
|
| +Future<bool> _validateExpectedPackages(Directory appDir,
|
| + List<Descriptor> expectedPackageDir) {
|
| + // No expectation.
|
| + if (expectedPackageDir == null) return new Future.immediate(true);
|
| +
|
| + return dir('packages', expectedPackageDir).validate(appDir.path);
|
| }
|
|
|
| /**
|
| @@ -110,6 +136,11 @@ Future<ProcessResult> _runPub(List<String> pubArgs) {
|
| void _validateOutput(String expectedText, List<String> actual) {
|
| final expected = expectedText.split('\n');
|
|
|
| + // Strip off the last line. This lets us have expected multiline strings
|
| + // where the closing ''' is on its own line. It also fixes '' expected output
|
| + // to expect zero lines of output, not a single empty line.
|
| + expected.removeLast();
|
| +
|
| final length = Math.min(expected.length, actual.length);
|
| for (var i = 0; i < length; i++) {
|
| if (expected[i].trim() != actual[i].trim()) {
|
| @@ -159,6 +190,13 @@ class Descriptor {
|
| * completed after the creation is done.
|
| */
|
| abstract Future create(String dir);
|
| +
|
| + /**
|
| + * Validates that this descriptor correctly matches the actual file system
|
| + * entry at [path]. Returns a [Future] that completes when the validation is
|
| + * done.
|
| + */
|
| + abstract Future<bool> validate(String path);
|
| }
|
|
|
| /**
|
| @@ -181,6 +219,18 @@ class FileDescriptor extends Descriptor {
|
| Future<File> create(String dir) {
|
| return writeTextFile(join(dir, name), contents);
|
| }
|
| +
|
| + /**
|
| + * Validates that this file correctly matches the actual file at [path].
|
| + */
|
| + Future<bool> validate(String path) {
|
| + path = join(path, name);
|
| + return fileExists(path).chain((exists) {
|
| + if (!exists) return new Future.immediate(false);
|
| +
|
| + return readTextFile(path).transform((text) => text == contents);
|
| + });
|
| + }
|
| }
|
|
|
| /**
|
| @@ -219,4 +269,21 @@ class DirectoryDescriptor extends Descriptor {
|
|
|
| return completer.future;
|
| }
|
| +
|
| + /**
|
| + * Validates that the directory at [path] contains all of the expected
|
| + * contents in this descriptor. Note that this does *not* check that the
|
| + * directory doesn't contain other unexpected stuff, just that it *does*
|
| + * contain the stuff we do expect.
|
| + */
|
| + Future<bool> validate(String path) {
|
| + // Validate each of the items in this directory.
|
| + final entryFutures = contents.map(
|
| + (entry) => entry.validate(join(path, name)));
|
| +
|
| + // If they are all valid, the directory is valid.
|
| + return Futures.wait(entryFutures).transform((entries) {
|
| + return !entries.some((valid) => !valid);
|
| + });
|
| + }
|
| }
|
|
|