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 import 'dart:async'; | 5 import 'dart:async'; |
6 import 'dart:convert'; | 6 import 'dart:convert'; |
7 import 'dart:io'; | 7 import 'dart:io'; |
8 import 'dart:mirrors'; | 8 import 'dart:mirrors'; |
9 | 9 |
10 import 'package:path/path.dart' as p; | 10 import 'package:path/path.dart' as p; |
(...skipping 24 matching lines...) Expand all Loading... |
35 var os = OperatingSystem.findByIoName(name); | 35 var os = OperatingSystem.findByIoName(name); |
36 if (os != null) return os; | 36 if (os != null) return os; |
37 | 37 |
38 throw new UnsupportedError('Unsupported operating system "$name".'); | 38 throw new UnsupportedError('Unsupported operating system "$name".'); |
39 })(); | 39 })(); |
40 | 40 |
41 /// A queue of lines of standard input. | 41 /// A queue of lines of standard input. |
42 final stdinLines = new StreamQueue( | 42 final stdinLines = new StreamQueue( |
43 UTF8.decoder.fuse(const LineSplitter()).bind(stdin)); | 43 UTF8.decoder.fuse(const LineSplitter()).bind(stdin)); |
44 | 44 |
| 45 /// Whether this is being run as a subprocess in the test package's own tests. |
| 46 bool inTestTests = Platform.environment["_DART_TEST_TESTING"] == "true"; |
| 47 |
45 /// The root directory below which to nest temporary directories created by the | 48 /// The root directory below which to nest temporary directories created by the |
46 /// test runner. | 49 /// test runner. |
47 /// | 50 /// |
48 /// This is configurable so that the test code can validate that the runner | 51 /// This is configurable so that the test code can validate that the runner |
49 /// cleans up after itself fully. | 52 /// cleans up after itself fully. |
50 final _tempDir = Platform.environment.containsKey("_UNITTEST_TEMP_DIR") | 53 final _tempDir = Platform.environment.containsKey("_UNITTEST_TEMP_DIR") |
51 ? Platform.environment["_UNITTEST_TEMP_DIR"] | 54 ? Platform.environment["_UNITTEST_TEMP_DIR"] |
52 : Directory.systemTemp.path; | 55 : Directory.systemTemp.path; |
53 | 56 |
54 /// The path to the `lib` directory of the `test` package. | 57 /// The path to the `lib` directory of the `test` package. |
55 String libDir({String packageRoot}) { | 58 String libDir({String packageRoot}) { |
56 var pathToIo = libraryPath(#test.util.io, packageRoot: packageRoot); | 59 var pathToIo = libraryPath(#test.util.io, packageRoot: packageRoot); |
57 return p.dirname(p.dirname(p.dirname(pathToIo))); | 60 return p.dirname(p.dirname(p.dirname(pathToIo))); |
58 } | 61 } |
59 | 62 |
60 // TODO(nweiz): Make this check [stdioType] once that works within "pub run". | 63 // TODO(nweiz): Make this check [stdioType] once that works within "pub run". |
61 /// Whether "special" strings such as Unicode characters or color escapes are | 64 /// Whether "special" strings such as Unicode characters or color escapes are |
62 /// safe to use. | 65 /// safe to use. |
63 /// | 66 /// |
64 /// On Windows or when not printing to a terminal, only printable ASCII | 67 /// On Windows or when not printing to a terminal, only printable ASCII |
65 /// characters should be used. | 68 /// characters should be used. |
66 bool get canUseSpecialChars => | 69 bool get canUseSpecialChars => |
67 Platform.operatingSystem != 'windows' && | 70 Platform.operatingSystem != 'windows' && !inTestTests; |
68 Platform.environment["_UNITTEST_USE_COLOR"] != "false"; | |
69 | 71 |
70 /// Creates a temporary directory and returns its path. | 72 /// Creates a temporary directory and returns its path. |
71 String createTempDir() => | 73 String createTempDir() => |
72 new Directory(_tempDir).createTempSync('dart_test_').path; | 74 new Directory(_tempDir).createTempSync('dart_test_').path; |
73 | 75 |
74 /// Creates a temporary directory and passes its path to [fn]. | 76 /// Creates a temporary directory and passes its path to [fn]. |
75 /// | 77 /// |
76 /// Once the [Future] returned by [fn] completes, the temporary directory and | 78 /// Once the [Future] returned by [fn] completes, the temporary directory and |
77 /// all its contents are deleted. [fn] can also return `null`, in which case | 79 /// all its contents are deleted. [fn] can also return `null`, in which case |
78 /// the temporary directory is deleted immediately afterwards. | 80 /// the temporary directory is deleted immediately afterwards. |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 /// | 175 /// |
174 /// This has a built-in race condition: another process may bind this port at | 176 /// This has a built-in race condition: another process may bind this port at |
175 /// any time after this call has returned. If at all possible, callers should | 177 /// any time after this call has returned. If at all possible, callers should |
176 /// use [getUnusedPort] instead. | 178 /// use [getUnusedPort] instead. |
177 Future<int> getUnsafeUnusedPort() async { | 179 Future<int> getUnsafeUnusedPort() async { |
178 var socket = await RawServerSocket.bind(InternetAddress.LOOPBACK_IP_V4, 0); | 180 var socket = await RawServerSocket.bind(InternetAddress.LOOPBACK_IP_V4, 0); |
179 var port = socket.port; | 181 var port = socket.port; |
180 await socket.close(); | 182 await socket.close(); |
181 return port; | 183 return port; |
182 } | 184 } |
OLD | NEW |