Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1617)

Unified Diff: utils/tests/pub/test_pub.dart

Issue 12079112: Make a bunch of stuff in pub synchronous. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« utils/pub/utils.dart ('K') | « utils/tests/pub/io_test.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: utils/tests/pub/test_pub.dart
diff --git a/utils/tests/pub/test_pub.dart b/utils/tests/pub/test_pub.dart
index eeaddc96786dfe3ba635e0213c96199d46dc7bae..1f12cf78d8ffcf7d285ef4467ee4299b62a1685b 100644
--- a/utils/tests/pub/test_pub.dart
+++ b/utils/tests/pub/test_pub.dart
@@ -585,14 +585,16 @@ void confirmPublish(ScheduledProcess pub) {
/// [Future] may have a type other than [Process].
Future _doPub(Function fn, sandboxDir, List args, Future<Uri> tokenEndpoint) {
String pathInSandbox(path) => join(getFullPath(sandboxDir), path);
-
- return Future.wait([
- ensureDir(pathInSandbox(appPath)),
- _awaitObject(args),
- tokenEndpoint == null ? new Future.immediate(null) : tokenEndpoint
- ]).then((results) {
- var args = results[1];
- var tokenEndpoint = results[2];
+ // Make sure all errors propagate through future.
+ return defer(() {
+ ensureDir(pathInSandbox(appPath));
+ return Future.wait([
+ _awaitObject(args),
+ tokenEndpoint == null ? new Future.immediate(null) : tokenEndpoint
+ ]);
+ }).then((results) {
+ var args = results[0];
+ var tokenEndpoint = results[1];
// Find a Dart executable we can use to spawn. Use the same one that was
// used to run this script itself.
var dartBin = new Options().executable;
@@ -800,14 +802,15 @@ abstract class Descriptor {
}
/// Validates that at least one file in [dir] matching [name] is valid
- /// according to [validate]. [validate] should complete to an exception if
- /// the input path is invalid.
+ /// according to [validate]. [validate] should throw or complete to an
+ /// exception if the input path is invalid.
Future _validateOneMatch(String dir, Future validate(String path)) {
// Special-case strings to support multi-level names like "myapp/packages".
if (name is String) {
var path = join(dir, name);
- return exists(path).then((exists) {
- if (!exists) {
+ // Make sure errors propagate through future.
+ return defer(() {
+ if (!entryExists(path)) {
throw new ExpectException('File $name in $dir not found.');
}
return validate(path);
@@ -873,26 +876,23 @@ class FileDescriptor extends Descriptor {
/// Creates the file within [dir]. Returns a [Future] that is completed after
/// the creation is done.
- Future<File> create(dir) {
- return writeTextFile(join(dir, _stringName), contents);
- }
+ Future<File> create(dir) =>
+ defer(() => writeTextFile(join(dir, _stringName), contents));
/// Deletes the file within [dir]. Returns a [Future] that is completed after
/// the deletion is done.
- Future delete(dir) {
- return deleteFile(join(dir, _stringName));
- }
+ Future delete(dir) =>
+ defer(() => deleteFile(join(dir, _stringName)));
/// Validates that this file correctly matches the actual file at [path].
Future validate(String path) {
return _validateOneMatch(path, (file) {
- return readTextFile(file).then((text) {
- if (text == contents) return null;
+ var text = readTextFile(file);
+ if (text == contents) return null;
- throw new ExpectException(
- 'File $file should contain:\n\n$contents\n\n'
- 'but contained:\n\n$text');
- });
+ throw new ExpectException(
+ 'File $file should contain:\n\n$contents\n\n'
+ 'but contained:\n\n$text');
});
}
@@ -924,13 +924,14 @@ class DirectoryDescriptor extends Descriptor {
/// Creates the file within [dir]. Returns a [Future] that is completed after
/// the creation is done.
Future<Directory> create(parentDir) {
- // Create the directory.
- return ensureDir(join(parentDir, _stringName)).then((dir) {
- if (contents == null) return new Future<Directory>.immediate(dir);
+ // Make sure all errors propagate through the future.
+ return defer(() {
+ // Create the directory.
+ var dir = ensureDir(join(parentDir, _stringName));
+ if (contents == null) return dir;
// Recursively create all of its children.
- final childFutures =
- contents.map((child) => child.create(dir)).toList();
+ var childFutures = contents.map((child) => child.create(dir)).toList();
// Only complete once all of the children have been created too.
return Future.wait(childFutures).then((_) => dir);
});
@@ -1134,8 +1135,9 @@ class NothingDescriptor extends Descriptor {
Future delete(dir) => new Future.immediate(null);
Future validate(String dir) {
- return exists(join(dir, name)).then((exists) {
- if (exists) {
+ // Make sure errors propagate through future.
+ return defer(() {
+ if (entryExists(join(dir, name))) {
throw new ExpectException('File $name in $dir should not exist.');
}
});
@@ -1159,12 +1161,10 @@ typedef Validator ValidatorCreator(Entrypoint entrypoint);
Future<Pair<List<String>, List<String>>> schedulePackageValidation(
ValidatorCreator fn) {
return _scheduleValue((sandboxDir) {
- var cache = new SystemCache.withSources(
- join(sandboxDir, cachePath));
+ var cache = new SystemCache.withSources(join(sandboxDir, cachePath));
- return Entrypoint.load(join(sandboxDir, appPath), cache)
- .then((entrypoint) {
- var validator = fn(entrypoint);
+ return defer(() {
+ var validator = fn(new Entrypoint(join(sandboxDir, appPath), cache));
return validator.validate().then((_) {
return new Pair(validator.errors, validator.warnings);
});
@@ -1473,7 +1473,8 @@ class ScheduledServer {
/// Raises an error complaining of an unexpected request.
void _awaitHandle(HttpRequest request, HttpResponse response) {
if (_ignored.contains(new Pair(request.method, request.path))) return;
- var future = timeout(new Future.immediate(null).then((_) {
+ // Make sure all errors propagate through future.
+ var future = timeout(defer(() {
if (_handlers.isEmpty) {
fail('Unexpected ${request.method} request to ${request.path}.');
}
« utils/pub/utils.dart ('K') | « utils/tests/pub/io_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698