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 /** | 5 /** |
6 * Test infrastructure for testing pub. Unlike typical unit tests, most pub | 6 * Test infrastructure for testing pub. Unlike typical unit tests, most pub |
7 * tests are integration tests that stage some stuff on the file system, run | 7 * tests are integration tests that stage some stuff on the file system, run |
8 * pub, and then validate the results. This library provides an API to build | 8 * pub, and then validate the results. This library provides an API to build |
9 * tests like that. | 9 * tests like that. |
10 */ | 10 */ |
(...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
494 // test framework knows we're done doing asynchronous stuff. | 494 // test framework knows we're done doing asynchronous stuff. |
495 cleanup().then((_) => registerException(error, future.stackTrace)); | 495 cleanup().then((_) => registerException(error, future.stackTrace)); |
496 return true; | 496 return true; |
497 }); | 497 }); |
498 | 498 |
499 future.chain((_) => cleanup()).then((_) { | 499 future.chain((_) => cleanup()).then((_) { |
500 asyncDone(); | 500 asyncDone(); |
501 }); | 501 }); |
502 } | 502 } |
503 | 503 |
| 504 /// Get the path to the root "util/test/pub" directory containing the pub tests. |
| 505 String get testDirectory { |
| 506 var dir = new Path.fromNative(new Options().script); |
| 507 while (dir.filename != 'pub') dir = dir.directoryPath; |
| 508 |
| 509 return dir.toNativePath(); |
| 510 } |
| 511 |
504 /** | 512 /** |
505 * Schedules a call to the Pub command-line utility. Runs Pub with [args] and | 513 * Schedules a call to the Pub command-line utility. Runs Pub with [args] and |
506 * validates that its results match [output], [error], and [exitCode]. | 514 * validates that its results match [output], [error], and [exitCode]. |
507 */ | 515 */ |
508 void schedulePub([List<String> args, Pattern output, Pattern error, | 516 void schedulePub([List<String> args, Pattern output, Pattern error, |
509 int exitCode = 0]) { | 517 int exitCode = 0]) { |
510 _schedule((sandboxDir) { | 518 _schedule((sandboxDir) { |
511 String pathInSandbox(path) => join(getFullPath(sandboxDir), path); | 519 String pathInSandbox(path) => join(getFullPath(sandboxDir), path); |
512 | 520 |
513 return ensureDir(pathInSandbox(appPath)).chain((_) { | 521 return ensureDir(pathInSandbox(appPath)).chain((_) { |
514 // Find a Dart executable we can use to spawn. Use the same one that was | 522 // Find a Dart executable we can use to spawn. Use the same one that was |
515 // used to run this script itself. | 523 // used to run this script itself. |
516 var dartBin = new Options().executable; | 524 var dartBin = new Options().executable; |
517 | 525 |
518 // If the executable looks like a path, get its full path. That way we | 526 // If the executable looks like a path, get its full path. That way we |
519 // can still find it when we spawn it with a different working directory. | 527 // can still find it when we spawn it with a different working directory. |
520 if (dartBin.contains(Platform.pathSeparator)) { | 528 if (dartBin.contains(Platform.pathSeparator)) { |
521 dartBin = new File(dartBin).fullPathSync(); | 529 dartBin = new File(dartBin).fullPathSync(); |
522 } | 530 } |
523 | 531 |
524 var scriptDir = new File(new Options().script).directorySync().path; | |
525 | |
526 // Find the main pub entrypoint. | 532 // Find the main pub entrypoint. |
527 var pubPath = fs.joinPaths(scriptDir, '../../pub/pub.dart'); | 533 var pubPath = fs.joinPaths(testDirectory, '../../pub/pub.dart'); |
528 | 534 |
529 var dartArgs = | 535 var dartArgs = |
530 ['--enable-type-checks', '--enable-asserts', pubPath, '--trace']; | 536 ['--enable-type-checks', '--enable-asserts', pubPath, '--trace']; |
531 dartArgs.addAll(args); | 537 dartArgs.addAll(args); |
532 | 538 |
533 var environment = new Map.from(Platform.environment); | 539 var environment = new Map.from(Platform.environment); |
534 environment['PUB_CACHE'] = pathInSandbox(cachePath); | 540 environment['PUB_CACHE'] = pathInSandbox(cachePath); |
535 environment['DART_SDK'] = pathInSandbox(sdkPath); | 541 environment['DART_SDK'] = pathInSandbox(sdkPath); |
536 | 542 |
537 return runProcess(dartBin, dartArgs, workingDir: pathInSandbox(appPath), | 543 return runProcess(dartBin, dartArgs, workingDir: pathInSandbox(appPath), |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
657 | 663 |
658 Expect.fail(message.toString()); | 664 Expect.fail(message.toString()); |
659 } | 665 } |
660 } | 666 } |
661 | 667 |
662 /** | 668 /** |
663 * Base class for [FileDescriptor] and [DirectoryDescriptor] so that a | 669 * Base class for [FileDescriptor] and [DirectoryDescriptor] so that a |
664 * directory can contain a heterogeneous collection of files and | 670 * directory can contain a heterogeneous collection of files and |
665 * subdirectories. | 671 * subdirectories. |
666 */ | 672 */ |
667 class Descriptor { | 673 abstract class Descriptor { |
668 /** | 674 /** |
669 * The name of this file or directory. This must be a [String] if the fiel or | 675 * The name of this file or directory. This must be a [String] if the fiel or |
670 * directory is going to be created. | 676 * directory is going to be created. |
671 */ | 677 */ |
672 final Pattern name; | 678 final Pattern name; |
673 | 679 |
674 Descriptor(this.name); | 680 Descriptor(this.name); |
675 | 681 |
676 /** | 682 /** |
677 * Creates the file or directory within [dir]. Returns a [Future] that is | 683 * Creates the file or directory within [dir]. Returns a [Future] that is |
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1038 "--file", join(parentDir, _stringName)]; | 1044 "--file", join(parentDir, _stringName)]; |
1039 args.addAll(contents.map((child) => child.name)); | 1045 args.addAll(contents.map((child) => child.name)); |
1040 return runProcess("tar", args); | 1046 return runProcess("tar", args); |
1041 } else { | 1047 } else { |
1042 // Create the tar file. | 1048 // Create the tar file. |
1043 var tarFile = join(tempDir, _stringName.replaceAll("tar.gz", "tar")); | 1049 var tarFile = join(tempDir, _stringName.replaceAll("tar.gz", "tar")); |
1044 var args = ["a", tarFile]; | 1050 var args = ["a", tarFile]; |
1045 args.addAll(contents.map( | 1051 args.addAll(contents.map( |
1046 (child) => '-i!"${join(tempDir, child.name)}"')); | 1052 (child) => '-i!"${join(tempDir, child.name)}"')); |
1047 | 1053 |
1048 // Find 7zip. Note: this assumes the tests are being run from | 1054 // Find 7zip. |
1049 // utils/tests/pub/ | 1055 var command = fs.joinPaths(testDirectory, |
1050 var scriptDir = new File(new Options().script).directorySync().path; | |
1051 var command = fs.joinPaths(scriptDir, | |
1052 '../../../third_party/7zip/7za.exe'); | 1056 '../../../third_party/7zip/7za.exe'); |
1053 | 1057 |
1054 return runProcess(command, args).chain((_) { | 1058 return runProcess(command, args).chain((_) { |
1055 // GZIP it. 7zip doesn't support doing both as a single operation. | 1059 // GZIP it. 7zip doesn't support doing both as a single operation. |
1056 args = ["a", join(parentDir, _stringName), tarFile]; | 1060 args = ["a", join(parentDir, _stringName), tarFile]; |
1057 return runProcess(command, args); | 1061 return runProcess(command, args); |
1058 }); | 1062 }); |
1059 } | 1063 } |
1060 }).chain((result) { | 1064 }).chain((result) { |
1061 if (!result.success) { | 1065 if (!result.success) { |
1062 throw "Failed to create tar file $name.\n" | 1066 throw "Failed to create tar file $name.\n" |
1063 "STDERR: ${Strings.join(result.stderr, "\n")}"; | 1067 "STDERR: ${Strings.join(result.stderr, "\n")}"; |
1064 } | 1068 } |
1065 return deleteDir(tempDir); | 1069 return deleteDir(tempDir); |
1066 }).transform((_) { | 1070 }).transform((_) { |
1067 return new File(join(parentDir, _stringName)); | 1071 return new File(join(parentDir, _stringName)); |
1068 }); | 1072 }); |
1069 } | 1073 } |
1070 | 1074 |
1071 /** | 1075 /** |
1072 * Validates that the `.tar.gz` file at [path] contains the expected contents. | 1076 * Validates that the `.tar.gz` file at [path] contains the expected contents. |
1073 */ | 1077 */ |
1074 Future validate(String path) { | 1078 Future validate(String path) { |
1075 throw "TODO(nweiz): implement this"; | 1079 throw "TODO(nweiz): implement this"; |
1076 } | 1080 } |
1077 | 1081 |
| 1082 Future delete(dir) { |
| 1083 throw new UnsupportedOperationException(''); |
| 1084 } |
| 1085 |
1078 /** | 1086 /** |
1079 * Loads the contents of this tar file. | 1087 * Loads the contents of this tar file. |
1080 */ | 1088 */ |
1081 InputStream load(List<String> path) { | 1089 InputStream load(List<String> path) { |
1082 if (!path.isEmpty()) { | 1090 if (!path.isEmpty()) { |
1083 var joinedPath = Strings.join(path, '/'); | 1091 var joinedPath = Strings.join(path, '/'); |
1084 throw "Can't load $joinedPath from within $name: not a directory."; | 1092 throw "Can't load $joinedPath from within $name: not a directory."; |
1085 } | 1093 } |
1086 | 1094 |
1087 var sinkStream = new ListInputStream(); | 1095 var sinkStream = new ListInputStream(); |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1158 } | 1166 } |
1159 | 1167 |
1160 /** | 1168 /** |
1161 * Schedules a callback to be called after Pub is run with [runPub], even if it | 1169 * Schedules a callback to be called after Pub is run with [runPub], even if it |
1162 * fails. | 1170 * fails. |
1163 */ | 1171 */ |
1164 void _scheduleCleanup(_ScheduledEvent event) { | 1172 void _scheduleCleanup(_ScheduledEvent event) { |
1165 if (_scheduledCleanup == null) _scheduledCleanup = []; | 1173 if (_scheduledCleanup == null) _scheduledCleanup = []; |
1166 _scheduledCleanup.add(event); | 1174 _scheduledCleanup.add(event); |
1167 } | 1175 } |
OLD | NEW |