Get more pub tests working.

Review URL: https://codereview.chromium.org//11821012

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@16830 260f80e4-7a28-3924-810f-c04153c831b5
This commit is contained in:
rnystrom@google.com 2013-01-09 01:32:55 +00:00
parent 12dbb6aa18
commit b60575a0fb
5 changed files with 22 additions and 16 deletions

View file

@ -133,8 +133,8 @@ abstract class Future<T> {
* completer.complete(value);
*
* // alternatively, if the service cannot produce the value, it
* // can provide an exception:
* completer.completeException(exception);
* // can provide an error:
* completer.completeError(error);
*
*/
abstract class Completer<T> {

View file

@ -131,12 +131,14 @@ Future<File> createFileFromStream(InputStream stream, path) {
log.io("Creating $path from stream.");
var completer = new Completer<File>();
var completed = false;
var file = new File(path);
var outputStream = file.openOutputStream();
stream.pipe(outputStream);
outputStream.onClosed = () {
log.fine("Created $path from stream.");
completed = true;
completer.complete(file);
};
@ -149,8 +151,9 @@ Future<File> createFileFromStream(InputStream stream, path) {
}
completeError(error) {
if (!completer.isComplete) {
completer.completeException(error, stackTrace);
if (!completed) {
completed = true;
completer.completeError(error, stackTrace);
} else {
log.fine("Got error after stream was closed: $error");
}
@ -263,7 +266,7 @@ Future<List<String>> listDir(dir,
}
var children = [];
lister.onError = (error) => completer.completeException(error, stackTrace);
lister.onError = (error) => completer.completeError(error, stackTrace);
lister.onDir = (file) {
if (!includeHiddenFiles && basename(file).startsWith('.')) return;
file = join(dir, basename(file));
@ -487,7 +490,7 @@ Future<String> readLine([StringInputStream stream]) {
stream.onError = (e) {
removeCallbacks();
completer.completeException(e, stackTrace);
completer.completeError(e, stackTrace);
};
return completer.future;
@ -535,7 +538,7 @@ Future<List<int>> consumeInputStream(InputStream stream) {
var buffer = <int>[];
stream.onClosed = () => completer.complete(buffer);
stream.onData = () => buffer.addAll(stream.read());
stream.onError = (e) => completer.completeException(e, stackTrace);
stream.onError = (e) => completer.completeError(e, stackTrace);
return completer.future;
}
@ -555,7 +558,7 @@ Future<String> consumeStringInputStream(StringInputStream stream) {
var buffer = new StringBuffer();
stream.onClosed = () => completer.complete(buffer.toString());
stream.onData = () => buffer.add(stream.read());
stream.onError = (e) => completer.completeException(e, stackTrace);
stream.onError = (e) => completer.completeError(e, stackTrace);
return completer.future;
}
@ -671,7 +674,7 @@ Future timeout(Future input, int milliseconds, String description) {
bool completed = false;
var completer = new Completer();
var timer = new Timer(milliseconds, (_) {
completer = true;
completed = true;
completer.completeError(new TimeoutException(
'Timed out while $description.'));
});

View file

@ -81,7 +81,7 @@ Future withClient(SystemCache cache, Future fn(Client client)) {
} catch (e, stackTrace) {
// whenComplete will drop exceptions on the floor. We want to ensure
// that any programming errors here don't go un-noticed. See issue 4127.
completer.completeException(e, stackTrace);
completer.completeError(e, stackTrace);
}
});
return completer.future;

View file

@ -104,13 +104,16 @@ bool endsWithPattern(String str, Pattern matcher) {
}
/// Returns the hex-encoded sha1 hash of [source].
String sha1(String source) =>
CryptoUtils.bytesToHex(new SHA1().add(source.charCodes).close());
String sha1(String source) {
var sha = new SHA1();
sha.add(source.charCodes);
return CryptoUtils.bytesToHex(sha.close());
}
/// Returns a [Future] that completes in [milliseconds].
Future sleep(int milliseconds) {
var completer = new Completer();
new Timer(milliseconds, completer.complete);
new Timer(milliseconds, (_) => completer.complete());
return completer.future;
}

View file

@ -834,9 +834,9 @@ abstract class Descriptor {
var error = new StringBuffer();
error.add("No files named $name in $dir were valid:\n");
for (var failure in failures) {
error.add(" ").add(failure).add("\n");
error.add(" $failure\n");
}
completer.completeException(
completer.completeError(
new ExpectException(error.toString()), stackTrace);
}
@ -851,7 +851,7 @@ abstract class Descriptor {
future.then((_) {
successes++;
checkComplete();
}).catchError(() {});
}).catchError((_) {});
}
return completer.future;
});