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

Side by Side Diff: lib/src/io.dart

Issue 939383002: Run with colored output even within "pub run". (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
« no previous file with comments | « lib/src/console_reporter.dart ('k') | pubspec.yaml » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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:async';
8 import 'dart:io'; 8 import 'dart:io';
9 9
10 // TODO(nweiz): Make this check [stdioType] once that works within "pub run".
10 /// Whether "special" strings such as Unicode characters or color escapes are 11 /// Whether "special" strings such as Unicode characters or color escapes are
11 /// safe to use. 12 /// safe to use.
12 /// 13 ///
13 /// On Windows or when not printing to a terminal, only printable ASCII 14 /// On Windows or when not printing to a terminal, only printable ASCII
14 /// characters should be used. 15 /// characters should be used.
15 bool get canUseSpecialChars => 16 bool get canUseSpecialChars =>
16 Platform.operatingSystem != 'windows' && 17 Platform.operatingSystem != 'windows' &&
17 stdioType(stdout) == StdioType.TERMINAL; 18 Platform.environment["_UNITTEST_USE_COLOR"] != "false";
18 19
19 /// Gets a "special" string (ANSI escape or Unicode). 20 /// Gets a "special" string (ANSI escape or Unicode).
20 /// 21 ///
21 /// On Windows or when not printing to a terminal, returns something else since 22 /// On Windows or when not printing to a terminal, returns something else since
22 /// those aren't supported. 23 /// those aren't supported.
23 String getSpecial(String special, [String onWindows = '']) => 24 String getSpecial(String special, [String onWindows = '']) =>
24 canUseSpecialChars ? special : onWindows; 25 canUseSpecialChars ? special : onWindows;
25 26
26 /// Creates a temporary directory and passes its path to [fn]. 27 /// Creates a temporary directory and passes its path to [fn].
27 /// 28 ///
28 /// Once the [Future] returned by [fn] completes, the temporary directory and 29 /// 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 /// all its contents are deleted. [fn] can also return `null`, in which case
30 /// the temporary directory is deleted immediately afterwards. 31 /// the temporary directory is deleted immediately afterwards.
31 /// 32 ///
32 /// Returns a future that completes to the value that the future returned from 33 /// Returns a future that completes to the value that the future returned from
33 /// [fn] completes to. 34 /// [fn] completes to.
34 Future withTempDir(Future fn(String path)) { 35 Future withTempDir(Future fn(String path)) {
35 return new Future.sync(() { 36 return new Future.sync(() {
36 // TODO(nweiz): Empirically test whether sync or async functions perform 37 // TODO(nweiz): Empirically test whether sync or async functions perform
37 // better here when starting a bunch of isolates. 38 // better here when starting a bunch of isolates.
38 var tempDir = Directory.systemTemp.createTempSync('unittest_'); 39 var tempDir = Directory.systemTemp.createTempSync('unittest_');
39 return new Future.sync(() => fn(tempDir.path)) 40 return new Future.sync(() => fn(tempDir.path))
40 .whenComplete(() => tempDir.deleteSync(recursive: true)); 41 .whenComplete(() => tempDir.deleteSync(recursive: true));
41 }); 42 });
42 } 43 }
OLDNEW
« no previous file with comments | « lib/src/console_reporter.dart ('k') | pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698