@@ -10,14 +10,12 @@ import 'dart:typed_data';
1010import 'package:async/async.dart' ;
1111import 'package:collection/collection.dart' ;
1212import 'package:matcher/matcher.dart' ;
13+ import 'package:path/path.dart' as p;
1314import 'package:stream_channel/stream_channel.dart' ;
1415import 'package:term_glyph/term_glyph.dart' as glyph;
1516
1617import 'backend/invoker.dart' ;
1718import 'backend/operating_system.dart' ;
18- // Prefix this import to avoid accidentally using IO stuff in cross-platform
19- // contexts.
20- import 'util/io.dart' as io;
2119
2220/// A typedef for a possibly-asynchronous function.
2321///
@@ -51,16 +49,24 @@ final _exceptionPrefix = new RegExp(r'^([A-Z][a-zA-Z]*)?(Exception|Error): ');
5149/// A regular expression matching a single vowel.
5250final _vowel = new RegExp ('[aeiou]' );
5351
54- /// Returns the best guess for the current operating system without relying on
52+ /// Directories that are specific to OS X.
53+ ///
54+ /// This is used to try to distinguish OS X and Linux in [currentOSGuess] .
55+ final _macOSDirectories = new Set <String >.from (
56+ ["/Applications" , "/Library" , "/Network" , "/System" , "/Users" ]);
57+
58+ /// Returns the best guess for the current operating system without using
5559/// `dart:io` .
5660///
5761/// This is useful for running test files directly and skipping tests as
58- /// appropriate.
59- final currentOSGuess = _ifSupported (() => io.currentOS, OperatingSystem .none);
60-
61- /// Returns the best guess for whether we're running on internal Google
62- /// infrastructure without relying on `dart:io` .
63- final inGoogleGuess = _ifSupported (() => io.inGoogle, false );
62+ /// appropriate. The only OS-specific information we have is the current path,
63+ /// which we try to use to figure out the OS.
64+ final OperatingSystem currentOSGuess = (() {
65+ if (p.style == p.Style .url) return OperatingSystem .none;
66+ if (p.style == p.Style .windows) return OperatingSystem .windows;
67+ if (_macOSDirectories.any (p.current.startsWith)) return OperatingSystem .macOS;
68+ return OperatingSystem .linux;
69+ })();
6470
6571/// A regular expression matching a hyphenated identifier.
6672///
@@ -90,16 +96,6 @@ class Pair<E, F> {
9096 int get hashCode => first.hashCode ^ last.hashCode;
9197}
9298
93- /// Returns [callback] 's return value, unless it throws an [UnsupportedError] in
94- /// which case returns [fallback] .
95- T _ifSupported <T >(T callback (), T fallback) {
96- try {
97- return callback ();
98- } on UnsupportedError {
99- return fallback;
100- }
101- }
102-
10399/// Get a string description of an exception.
104100///
105101/// Many exceptions include the exception class name at the beginning of their
0 commit comments