Chromium Code Reviews| Index: lib/src/io.dart |
| diff --git a/lib/src/io.dart b/lib/src/io.dart |
| index b279f3ee0ed62abbf51846a3d5684890847b5772..c3756315879cc49eba86dd0930de22816d47183b 100644 |
| --- a/lib/src/io.dart |
| +++ b/lib/src/io.dart |
| @@ -4,6 +4,7 @@ |
| library unittest.io; |
| +import 'dart:async'; |
| import 'dart:io'; |
| /// Whether "special" strings such as Unicode characters or color escapes are |
| @@ -21,3 +22,19 @@ bool get canUseSpecialChars => |
| /// those aren't supported. |
| String getSpecial(String special, [String onWindows = '']) => |
| canUseSpecialChars ? special : onWindows; |
| + |
| +/// Creates a temporary directory and passes its path to [fn]. |
| +/// |
| +/// Once the [Future] returned by [fn] completes, the temporary directory and |
| +/// all its contents are deleted. [fn] can also return `null`, in which case |
| +/// the temporary directory is deleted immediately afterwards. |
| +/// |
| +/// Returns a future that completes to the value that the future returned from |
| +/// [fn] completes to. |
| +Future withTempDir(Future fn(String path)) { |
| + return new Future.sync(() { |
| + var tempDir = Directory.systemTemp.createTempSync('unittest_'); |
| + return new Future.sync(() => fn(tempDir.path)) |
| + .whenComplete(() => tempDir.deleteSync(recursive: true)); |
|
kevmoo
2015/02/12 22:31:15
If tests are being run on many isolates, do we wan
nweiz
2015/02/12 22:37:52
Evidence so far indicates that sync IO functions a
|
| + }); |
| +} |