20
20
import org .junit .Test ;
21
21
import org .junit .rules .Timeout ;
22
22
23
+ import java .io .IOException ;
24
+
23
25
import static org .junit .Assert .assertEquals ;
26
+ import static org .junit .Assert .assertTrue ;
27
+ import static org .junit .Assert .fail ;
24
28
import static org .junit .Assume .assumeTrue ;
25
29
26
30
public class ShellTest {
@@ -41,4 +45,28 @@ public void testHeadDevZero() throws Exception {
41
45
String output = Shell .execCommand ("head" , "-c" , Integer .toString (length ), "/dev/zero" );
42
46
assertEquals (length , output .length ());
43
47
}
48
+
49
+ private final static String NONEXISTENT_PATH = "/dev/a/path/that/does/not/exist/in/the/filesystem" ;
50
+
51
+ @ Test
52
+ public void testAttemptToRunNonExistentProgram () throws Exception {
53
+ assumeTrue (!OperatingSystem .IS_WINDOWS );
54
+ try {
55
+ Shell .execCommand (NONEXISTENT_PATH );
56
+ fail ("Expected to get an exception when trying to run a program that does not exist" );
57
+ } catch (IOException e ) {
58
+ assertTrue (e .getMessage ().contains ("No such file" ));
59
+ }
60
+ }
61
+
62
+ @ Test
63
+ public void testRunProgramWithErrorReturn () throws Exception {
64
+ assumeTrue (!OperatingSystem .IS_WINDOWS );
65
+ try {
66
+ Shell .execCommand ("head" , "-c" , "0" , NONEXISTENT_PATH );
67
+ fail ("Expected to get an exception when trying to head a nonexistent file" );
68
+ } catch (Shell .ExitCodeException e ) {
69
+ assertTrue (e .getMessage ().contains ("No such file" ));
70
+ }
71
+ }
44
72
}
0 commit comments