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

Side by Side 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: 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 unified diff | Download patch
OLDNEW
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.io; 5 library unittest.io;
6 6
7 import 'dart:async';
7 import 'dart:io'; 8 import 'dart:io';
8 9
9 /// Whether "special" strings such as Unicode characters or color escapes are 10 /// Whether "special" strings such as Unicode characters or color escapes are
10 /// safe to use. 11 /// safe to use.
11 /// 12 ///
12 /// On Windows or when not printing to a terminal, only printable ASCII 13 /// On Windows or when not printing to a terminal, only printable ASCII
13 /// characters should be used. 14 /// characters should be used.
14 bool get canUseSpecialChars => 15 bool get canUseSpecialChars =>
15 Platform.operatingSystem != 'windows' && 16 Platform.operatingSystem != 'windows' &&
16 stdioType(stdout) == StdioType.TERMINAL; 17 stdioType(stdout) == StdioType.TERMINAL;
17 18
18 /// Gets a "special" string (ANSI escape or Unicode). 19 /// Gets a "special" string (ANSI escape or Unicode).
19 /// 20 ///
20 /// On Windows or when not printing to a terminal, returns something else since 21 /// On Windows or when not printing to a terminal, returns something else since
21 /// those aren't supported. 22 /// those aren't supported.
22 String getSpecial(String special, [String onWindows = '']) => 23 String getSpecial(String special, [String onWindows = '']) =>
23 canUseSpecialChars ? special : onWindows; 24 canUseSpecialChars ? special : onWindows;
25
26 /// Creates a temporary directory and passes its path to [fn].
27 ///
28 /// Once the [Future] returned by [fn] completes, the temporary directory and
29 /// all its contents are deleted. [fn] can also return `null`, in which case
30 /// the temporary directory is deleted immediately afterwards.
31 ///
32 /// Returns a future that completes to the value that the future returned from
33 /// [fn] completes to.
34 Future withTempDir(Future fn(String path)) {
35 return new Future.sync(() {
36 var tempDir = Directory.systemTemp.createTempSync('unittest_');
37 return new Future.sync(() => fn(tempDir.path))
38 .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
39 });
40 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698