Chromium Code Reviews

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

Issue 1290763003: Drop support for old SDK and shelf versions. (Closed) Base URL: git@github.com:dart-lang/test@master
Patch Set: Code review changes Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff |
« no previous file with comments | « lib/src/util/dart.dart ('k') | lib/src/util/isolate_wrapper.dart » ('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 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:convert';
9 import 'dart:io'; 9 import 'dart:io';
10 import 'dart:mirrors'; 10 import 'dart:mirrors';
11 11
12 import 'package:path/path.dart' as p; 12 import 'package:path/path.dart' as p;
13 import 'package:pub_semver/pub_semver.dart'; 13 import 'package:pub_semver/pub_semver.dart';
14 14
15 import '../backend/operating_system.dart'; 15 import '../backend/operating_system.dart';
16 import '../runner/application_exception.dart'; 16 import '../runner/application_exception.dart';
17 import '../util/stream_queue.dart'; 17 import '../util/stream_queue.dart';
18 import '../utils.dart'; 18 import '../utils.dart';
19 19
20 /// The ASCII code for a newline character. 20 /// The ASCII code for a newline character.
21 const _newline = 0xA; 21 const _newline = 0xA;
22 22
23 /// The ASCII code for a carriage return character. 23 /// The ASCII code for a carriage return character.
24 const _carriageReturn = 0xD; 24 const _carriageReturn = 0xD;
25 25
26 /// The root directory of the Dart SDK. 26 /// The root directory of the Dart SDK.
27 final String sdkDir = (() { 27 final String sdkDir = p.dirname(p.dirname(Platform.resolvedExecutable));
28 // TODO(kevmoo): work-around for accessing the SDK root dartbug.com/16994
29 //
30 // Don't resolve symlinks on Windows because of issue 133. Once the TODO above
31 // is resolved, we won't have to do explicit symlink resolution anyway.
32 var path = Platform.isWindows
33 ? Platform.executable
34 : new File(Platform.executable).resolveSymbolicLinksSync();
35 return p.dirname(p.dirname(path));
36 })();
37 28
38 /// The version of the Dart SDK currently in use. 29 /// The version of the Dart SDK currently in use.
39 final Version _sdkVersion = new Version.parse( 30 final Version _sdkVersion = new Version.parse(
40 new File(p.join(sdkDir, 'version')) 31 new File(p.join(sdkDir, 'version'))
41 .readAsStringSync().trim()); 32 .readAsStringSync().trim());
42 33
43 /// Returns the current operating system. 34 /// Returns the current operating system.
44 final OperatingSystem currentOS = (() { 35 final OperatingSystem currentOS = (() {
45 var name = Platform.operatingSystem; 36 var name = Platform.operatingSystem;
46 var os = OperatingSystem.findByIoName(name); 37 var os = OperatingSystem.findByIoName(name);
(...skipping 14 matching lines...)
61 final _tempDir = Platform.environment.containsKey("_UNITTEST_TEMP_DIR") 52 final _tempDir = Platform.environment.containsKey("_UNITTEST_TEMP_DIR")
62 ? Platform.environment["_UNITTEST_TEMP_DIR"] 53 ? Platform.environment["_UNITTEST_TEMP_DIR"]
63 : Directory.systemTemp.path; 54 : Directory.systemTemp.path;
64 55
65 /// The path to the `lib` directory of the `test` package. 56 /// The path to the `lib` directory of the `test` package.
66 String libDir({String packageRoot}) { 57 String libDir({String packageRoot}) {
67 var pathToIo = libraryPath(#test.util.io, packageRoot: packageRoot); 58 var pathToIo = libraryPath(#test.util.io, packageRoot: packageRoot);
68 return p.dirname(p.dirname(p.dirname(pathToIo))); 59 return p.dirname(p.dirname(p.dirname(pathToIo)));
69 } 60 }
70 61
71 /// Returns whether the current Dart version has a fix for issue 23084.
72 final bool supportsPubServe = ((){
73 // This isn't 100% accurate, since issue 23084 wasn't fixed in early 1.10 dev
74 // releases, but it's unlikely anyone will be using them.
75 // TODO(nweiz): remove this when we no longer support older Dart versions.
76 return new VersionConstraint.parse('>=1.9.2 <2.0.0').allows(_sdkVersion);
77 })();
78
79 /// Returns whether the current Dart version supports running isolates in
80 /// checked mode.
81 final bool supportsIsolateCheckedMode = (() {
82 // TODO(nweiz): remove this when we no longer support older Dart versions.
83 return new VersionConstraint.parse('>=1.11.0-dev.5.0 <2.0.0')
84 .allows(_sdkVersion);
85 })();
86
87 // TODO(nweiz): Make this check [stdioType] once that works within "pub run". 62 // TODO(nweiz): Make this check [stdioType] once that works within "pub run".
88 /// Whether "special" strings such as Unicode characters or color escapes are 63 /// Whether "special" strings such as Unicode characters or color escapes are
89 /// safe to use. 64 /// safe to use.
90 /// 65 ///
91 /// On Windows or when not printing to a terminal, only printable ASCII 66 /// On Windows or when not printing to a terminal, only printable ASCII
92 /// characters should be used. 67 /// characters should be used.
93 bool get canUseSpecialChars => 68 bool get canUseSpecialChars =>
94 Platform.operatingSystem != 'windows' && 69 Platform.operatingSystem != 'windows' &&
95 Platform.environment["_UNITTEST_USE_COLOR"] != "false"; 70 Platform.environment["_UNITTEST_USE_COLOR"] != "false";
96 71
(...skipping 120 matching lines...)
217 /// 192 ///
218 /// This has a built-in race condition: another process may bind this port at 193 /// This has a built-in race condition: another process may bind this port at
219 /// any time after this call has returned. If at all possible, callers should 194 /// any time after this call has returned. If at all possible, callers should
220 /// use [getUnusedPort] instead. 195 /// use [getUnusedPort] instead.
221 Future<int> getUnsafeUnusedPort() async { 196 Future<int> getUnsafeUnusedPort() async {
222 var socket = await RawServerSocket.bind(InternetAddress.LOOPBACK_IP_V4, 0); 197 var socket = await RawServerSocket.bind(InternetAddress.LOOPBACK_IP_V4, 0);
223 var port = socket.port; 198 var port = socket.port;
224 await socket.close(); 199 await socket.close();
225 return port; 200 return port;
226 } 201 }
OLDNEW
« no previous file with comments | « lib/src/util/dart.dart ('k') | lib/src/util/isolate_wrapper.dart » ('j') | no next file with comments »

Powered by Google App Engine