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

Unified Diff: lib/src/io.dart

Issue 920703006: Add a Loader class for loading tests from files. (Closed) Base URL: git@github.com:dart-lang/unittest@master
Patch Set: Code review changes Created 5 years, 10 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
« no previous file with comments | « lib/src/dart.dart ('k') | lib/src/loader.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/io.dart
diff --git a/lib/src/io.dart b/lib/src/io.dart
index b279f3ee0ed62abbf51846a3d5684890847b5772..dc909aae3a77323278762c672ead086928a12f01 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,21 @@ 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(() {
+ // TODO(nweiz): Empirically test whether sync or async functions perform
+ // better here when starting a bunch of isolates.
+ var tempDir = Directory.systemTemp.createTempSync('unittest_');
+ return new Future.sync(() => fn(tempDir.path))
+ .whenComplete(() => tempDir.deleteSync(recursive: true));
+ });
+}
« no previous file with comments | « lib/src/dart.dart ('k') | lib/src/loader.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698