| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library unittest.util.io; | 5 library unittest.util.io; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:io'; | 8 import 'dart:io'; |
| 9 | 9 |
| 10 import 'package:path/path.dart' as p; | 10 import 'package:path/path.dart' as p; |
| 11 | 11 |
| 12 /// The root directory of the Dart SDK. |
| 13 final String sdkDir = _computeSdkDir(); |
| 14 String _computeSdkDir() => p.dirname(p.dirname(Platform.executable)); |
| 15 |
| 12 /// Returns whether the current Dart version supports [Isolate.kill]. | 16 /// Returns whether the current Dart version supports [Isolate.kill]. |
| 13 final bool supportsIsolateKill = _supportsIsolateKill; | 17 final bool supportsIsolateKill = _supportsIsolateKill; |
| 14 bool get _supportsIsolateKill { | 18 bool get _supportsIsolateKill { |
| 15 // This isn't 100% accurate, since early 1.9 dev releases didn't support | 19 // This isn't 100% accurate, since early 1.9 dev releases didn't support |
| 16 // Isolate.kill(), but it's very unlikely anyone will be using them. | 20 // Isolate.kill(), but it's very unlikely anyone will be using them. |
| 17 // TODO(nweiz): remove this when we no longer support older Dart versions. | 21 // TODO(nweiz): remove this when we no longer support older Dart versions. |
| 18 var path = p.join(p.dirname(p.dirname(Platform.executable)), 'version'); | 22 var path = p.join(p.dirname(p.dirname(Platform.executable)), 'version'); |
| 19 return new File(path).readAsStringSync().startsWith('1.9'); | 23 return new File(path).readAsStringSync().startsWith('1.9'); |
| 20 } | 24 } |
| 21 | 25 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 46 /// [fn] completes to. | 50 /// [fn] completes to. |
| 47 Future withTempDir(Future fn(String path)) { | 51 Future withTempDir(Future fn(String path)) { |
| 48 return new Future.sync(() { | 52 return new Future.sync(() { |
| 49 // TODO(nweiz): Empirically test whether sync or async functions perform | 53 // TODO(nweiz): Empirically test whether sync or async functions perform |
| 50 // better here when starting a bunch of isolates. | 54 // better here when starting a bunch of isolates. |
| 51 var tempDir = Directory.systemTemp.createTempSync('unittest_'); | 55 var tempDir = Directory.systemTemp.createTempSync('unittest_'); |
| 52 return new Future.sync(() => fn(tempDir.path)) | 56 return new Future.sync(() => fn(tempDir.path)) |
| 53 .whenComplete(() => tempDir.deleteSync(recursive: true)); | 57 .whenComplete(() => tempDir.deleteSync(recursive: true)); |
| 54 }); | 58 }); |
| 55 } | 59 } |
| OLD | NEW |