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

Unified Diff: lib/src/util/io.dart

Issue 1056733002: Run test tearDowns and clean up temporary directories when a signal is caught. (Closed) Base URL: git@github.com:dart-lang/test@master
Patch Set: Code review changes Created 5 years, 9 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/util/dart.dart ('k') | lib/src/utils.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/util/io.dart
diff --git a/lib/src/util/io.dart b/lib/src/util/io.dart
index 39c336ac84ddff329fcecdc6fee2f9932b7110f5..fa12ae6d1eb205677ad246c964a0a8fd36930873 100644
--- a/lib/src/util/io.dart
+++ b/lib/src/util/io.dart
@@ -26,6 +26,15 @@ final OperatingSystem currentOS = (() {
throw new UnsupportedError('Unsupported operating system "$name".');
})();
+/// The root directory below which to nest temporary directories created by the
+/// test runner.
+///
+/// This is configurable so that the test code can validate that the runner
+/// cleans up after itself fully.
+final _tempDir = Platform.environment.containsKey("_UNITTEST_TEMP_DIR")
+ ? Platform.environment["_UNITTEST_TEMP_DIR"]
+ : Directory.systemTemp.path;
+
/// The path to the `lib` directory of the `test` package.
String libDir({String packageRoot}) {
var pathToIo = libraryPath(#test.util.io, packageRoot: packageRoot);
@@ -52,6 +61,10 @@ bool get canUseSpecialChars =>
Platform.operatingSystem != 'windows' &&
Platform.environment["_UNITTEST_USE_COLOR"] != "false";
+/// Creates a temporary directory and returns its path.
+String createTempDir() =>
+ new Directory(_tempDir).createTempSync('dart_test_').path;
+
/// Creates a temporary directory and passes its path to [fn].
///
/// Once the [Future] returned by [fn] completes, the temporary directory and
@@ -62,11 +75,9 @@ bool get canUseSpecialChars =>
/// [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('test_');
- return new Future.sync(() => fn(tempDir.path))
- .whenComplete(() => tempDir.deleteSync(recursive: true));
+ var tempDir = createTempDir();
+ return new Future.sync(() => fn(tempDir))
+ .whenComplete(() => new Directory(tempDir).deleteSync(recursive: true));
});
}
« no previous file with comments | « lib/src/util/dart.dart ('k') | lib/src/utils.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698