| OLD | NEW |
| (Empty) |
| 1 | |
| 2 library which.test.which_impl; | |
| 3 | |
| 4 import 'dart:async'; | |
| 5 | |
| 6 import 'package:unittest/unittest.dart'; | |
| 7 import 'package:which/src/which_impl.dart'; | |
| 8 | |
| 9 import 'util.dart'; | |
| 10 | |
| 11 main() { | |
| 12 group('which', () { | |
| 13 test('should complete to the first matching executable in candidate paths',
() { | |
| 14 var candidatePaths = getPosixCandidatePaths('z', '/x/y:/a/b/c', '/foo/bar'
); | |
| 15 | |
| 16 return which('z', candidatePaths, false, (path, isWindows) => new Future.v
alue(path == '/x/y/z' || path == '/a/b/c/z'), null) | |
| 17 .then((path) => expect(path, '/x/y/z')); | |
| 18 }); | |
| 19 | |
| 20 test('should call orElse if command not found', () { | |
| 21 var candidatePaths = getPosixCandidatePaths('z', '/x/y:/a/b/c', '/foo/bar'
); | |
| 22 | |
| 23 return which('z', candidatePaths, false, (path, isWindows) => new Future.v
alue(false), () => '/or/else') | |
| 24 .then((path) => expect(path, '/or/else')); | |
| 25 }); | |
| 26 | |
| 27 test('should throw state error if command not found and orElse not provided'
, () { | |
| 28 var future = new Future(() => | |
| 29 which('z', [], false, (path, isWindows) => new Future.value(false), nu
ll)); | |
| 30 | |
| 31 expect(future, throwsStateError); | |
| 32 }); | |
| 33 }); | |
| 34 | |
| 35 group('whichSync', () { | |
| 36 test('should return the first matching executable in candidate paths', () { | |
| 37 var candidatePaths = getWindowsCandidatePaths('z', r'C:\x\y;C:\a\b\c', '.E
XE;.BAT', r'C:\foo\bar'); | |
| 38 | |
| 39 var result = whichSync('find', candidatePaths, true, (path, isWindows) =>
path == r'C:\x\y\z.BAT' || path == r'C:\a\b\c\z.BAT', null); | |
| 40 | |
| 41 expect(result, r'C:\x\y\z.BAT'); | |
| 42 }); | |
| 43 | |
| 44 test('should call orElse if command not found', () { | |
| 45 var candidatePaths = getWindowsCandidatePaths('z', r'C:\x\y;C:\a\b\c', '.E
XE;.BAT', r'C:\foo\bar'); | |
| 46 | |
| 47 var result = whichSync('find', candidatePaths, true, (path, isWindows) =>
false, () => r'C:\or\else'); | |
| 48 | |
| 49 expect(result, r'C:\or\else'); | |
| 50 }); | |
| 51 test('should throw state error if command not found and orElse not provided'
, () { | |
| 52 expect(() => whichSync('z', [], true, (path, isWindows) => false, null), t
hrowsStateError); | |
| 53 }); | |
| 54 }); | |
| 55 } | |
| OLD | NEW |