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

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

Issue 1248073003: Add a --pause-after-load flag for debugging. (Closed) Base URL: git@github.com:dart-lang/test@master
Patch Set: Created 5 years, 5 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 test.util.io; 5 library test.util.io;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:convert';
8 import 'dart:io'; 9 import 'dart:io';
9 import 'dart:mirrors'; 10 import 'dart:mirrors';
10 11
12 import 'package:async/async.dart';
11 import 'package:path/path.dart' as p; 13 import 'package:path/path.dart' as p;
12 import 'package:pub_semver/pub_semver.dart'; 14 import 'package:pub_semver/pub_semver.dart';
13 15
14 import '../backend/operating_system.dart'; 16 import '../backend/operating_system.dart';
15 import '../runner/application_exception.dart'; 17 import '../runner/application_exception.dart';
18 import '../utils.dart';
16 19
17 /// The ASCII code for a newline character. 20 /// The ASCII code for a newline character.
18 const _newline = 0xA; 21 const _newline = 0xA;
19 22
20 /// The ASCII code for a carriage return character. 23 /// The ASCII code for a carriage return character.
21 const _carriageReturn = 0xD; 24 const _carriageReturn = 0xD;
22 25
23 /// The root directory of the Dart SDK. 26 /// The root directory of the Dart SDK.
24 final String sdkDir = (() { 27 final String sdkDir = (() {
25 // TODO(kevmoo): work-around for accessing the SDK root dartbug.com/16994 28 // TODO(kevmoo): work-around for accessing the SDK root dartbug.com/16994
(...skipping 13 matching lines...) Expand all
39 42
40 /// Returns the current operating system. 43 /// Returns the current operating system.
41 final OperatingSystem currentOS = (() { 44 final OperatingSystem currentOS = (() {
42 var name = Platform.operatingSystem; 45 var name = Platform.operatingSystem;
43 var os = OperatingSystem.findByIoName(name); 46 var os = OperatingSystem.findByIoName(name);
44 if (os != null) return os; 47 if (os != null) return os;
45 48
46 throw new UnsupportedError('Unsupported operating system "$name".'); 49 throw new UnsupportedError('Unsupported operating system "$name".');
47 })(); 50 })();
48 51
52 /// A queue of lines of standard input.
53 final stdinLines = new StreamQueue(
54 UTF8.decoder.fuse(const LineSplitter()).bind(stdin));
55
49 /// The root directory below which to nest temporary directories created by the 56 /// The root directory below which to nest temporary directories created by the
50 /// test runner. 57 /// test runner.
51 /// 58 ///
52 /// This is configurable so that the test code can validate that the runner 59 /// This is configurable so that the test code can validate that the runner
53 /// cleans up after itself fully. 60 /// cleans up after itself fully.
54 final _tempDir = Platform.environment.containsKey("_UNITTEST_TEMP_DIR") 61 final _tempDir = Platform.environment.containsKey("_UNITTEST_TEMP_DIR")
55 ? Platform.environment["_UNITTEST_TEMP_DIR"] 62 ? Platform.environment["_UNITTEST_TEMP_DIR"]
56 : Directory.systemTemp.path; 63 : Directory.systemTemp.path;
57 64
58 /// The path to the `lib` directory of the `test` package. 65 /// The path to the `lib` directory of the `test` package.
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 var previous; 131 var previous;
125 return list.reversed.where((byte) { 132 return list.reversed.where((byte) {
126 if (byte == 0) return false; 133 if (byte == 0) return false;
127 if (byte == _carriageReturn && previous == _newline) return false; 134 if (byte == _carriageReturn && previous == _newline) return false;
128 previous = byte; 135 previous = byte;
129 return true; 136 return true;
130 }).toList().reversed.toList(); 137 }).toList().reversed.toList();
131 }); 138 });
132 } 139 }
133 140
141 /// Print a warning containing [message].
142 ///
143 /// This automatically wraps lines if they get too long. If [color] is passed,
144 /// it controls whether the warning header is color; otherwise, it defaults to
145 /// [canUseSpecialChars].
146 void warn(String message, {bool color}) {
147 if (color == null) color = canUseSpecialChars;
148 var header = color
149 ? "\u001b[33mWarning:\u001b[0m"
150 : "Warning:";
151 stderr.writeln(wordWrap("$header $message\n"));
152 }
153
134 /// Creates a URL string for [address]:[port]. 154 /// Creates a URL string for [address]:[port].
135 /// 155 ///
136 /// Handles properly formatting IPv6 addresses. 156 /// Handles properly formatting IPv6 addresses.
137 Uri baseUrlForAddress(InternetAddress address, int port) { 157 Uri baseUrlForAddress(InternetAddress address, int port) {
138 if (address.isLoopback) { 158 if (address.isLoopback) {
139 return new Uri(scheme: "http", host: "localhost", port: port); 159 return new Uri(scheme: "http", host: "localhost", port: port);
140 } 160 }
141 161
142 // IPv6 addresses in URLs need to be enclosed in square brackets to avoid 162 // IPv6 addresses in URLs need to be enclosed in square brackets to avoid
143 // URL ambiguity with the ":" in the address. 163 // URL ambiguity with the ":" in the address.
(...skipping 24 matching lines...) Expand all
168 /// returned. 188 /// returned.
169 String libraryPath(Symbol libraryName, {String packageRoot}) { 189 String libraryPath(Symbol libraryName, {String packageRoot}) {
170 var lib = currentMirrorSystem().findLibrary(libraryName); 190 var lib = currentMirrorSystem().findLibrary(libraryName);
171 if (lib.uri.scheme != 'package') return p.fromUri(lib.uri); 191 if (lib.uri.scheme != 'package') return p.fromUri(lib.uri);
172 192
173 // TODO(nweiz): is there a way to avoid assuming this is being run next to a 193 // TODO(nweiz): is there a way to avoid assuming this is being run next to a
174 // packages directory?. 194 // packages directory?.
175 if (packageRoot == null) packageRoot = p.absolute('packages'); 195 if (packageRoot == null) packageRoot = p.absolute('packages');
176 return p.join(packageRoot, p.fromUri(lib.uri.path)); 196 return p.join(packageRoot, p.fromUri(lib.uri.path));
177 } 197 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698