Line data Source code
1 : // Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file 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. 4 : 5 : import 'package:path/path.dart' as p; 6 : import 'package:test_api/src/backend/operating_system.dart'; // ignore: implementation_imports 7 : 8 : /// Directories that are specific to OS X. 9 : /// 10 : /// This is used to try to distinguish OS X and Linux in [currentOSGuess]. 11 0 : final _macOSDirectories = { 12 : '/Applications', 13 : '/Library', 14 : '/Network', 15 : '/System', 16 : '/Users', 17 : }; 18 : 19 : /// Returns the best guess for the current operating system without using 20 : /// `dart:io`. 21 : /// 22 : /// This is useful for running test files directly and skipping tests as 23 : /// appropriate. The only OS-specific information we have is the current path, 24 : /// which we try to use to figure out the OS. 25 0 : final OperatingSystem currentOSGuess = (() { 26 : if (p.style == p.Style.url) return OperatingSystem.none; 27 : if (p.style == p.Style.windows) return OperatingSystem.windows; 28 : if (_macOSDirectories.any(p.current.startsWith)) return OperatingSystem.macOS; 29 : return OperatingSystem.linux; 30 : })();