Imported Upstream version 4.4
[platform/upstream/make.git] / tests / scripts / features / errors
1 #                                                                    -*-perl-*-
2
3 $description = "Test ignored failures in recipe command lines";
4
5 run_make_test(qq!
6 one:
7 \t-exit 1
8 \texit 0
9 two:
10 \texit 1
11 \texit 0
12 !,
13               "one", "exit 1\n#MAKE#: [#MAKEFILE#:3: one] Error 1 (ignored)\nexit 0\n");
14
15 # TEST #1
16 # -------
17
18 run_make_test(undef, " -i two",
19               "exit 1\n#MAKE#: [#MAKEFILE#:6: two] Error 1 (ignored)\nexit 0\n");
20
21 # TEST #2
22 # -------
23
24 # Test that error line offset works
25
26 run_make_test(qq!
27 all:
28 \t\@echo hi
29 \t\@echo there
30 \t\@exit 1
31 !,
32               '', "hi\nthere\n#MAKE#: *** [#MAKEFILE#:5: all] Error 1", 512);
33
34 # Windows error look completely different :-/
35
36 sub errors_getinfo
37 {
38     my ($cmd, $args) = @_;
39     if ($port_type eq 'W32') {
40         return (2, "process_begin: CreateProcess(NULL, $cmd $args, ...) failed.\nmake (e=2): The system cannot find the file specified.");
41     }
42
43     return (127, "#MAKE#: $cmd: $ERR_no_such_file");
44 }
45
46 # TEST #3
47 # -------
48
49 # Try failing due to unknown command
50 my $unk = './foobarbazbozblat';
51 unlink($unk);
52
53 my ($ernum, $erstr) = errors_getinfo($unk, "xx yy");
54 run_make_test(qq!
55 one: ; -$unk xx yy
56 !, 'one',
57               "$unk xx yy\n$erstr\n#MAKE#: [#MAKEFILE#:2: one] Error $ernum (ignored)\n");
58
59 # TEST #4
60 # -------
61
62 ($ernum, $erstr) = errors_getinfo($unk, "aa bb");
63 run_make_test(qq!
64 two: ; $unk aa bb
65 !, 'two -i',
66               "$unk aa bb\n$erstr\n#MAKE#: [#MAKEFILE#:2: two] Error $ernum (ignored)\n");
67
68 # TEST #5
69 # -------
70
71 run_make_test(undef, 'two',
72               "$unk aa bb\n$erstr\n#MAKE#: *** [#MAKEFILE#:2: two] Error $ernum\n", 512);
73
74 # SV #56918 : Test the unknown command as the second recipe line
75
76 ($ernum, $erstr) = errors_getinfo($unk, "qq rr");
77 run_make_test(qq!
78 three:
79 \t\@echo one
80 \t$unk qq rr
81 !, 'three',
82               "one\n$unk qq rr\n$erstr\n#MAKE#: *** [#MAKEFILE#:4: three] Error $ernum\n", 512);
83
84 # Try failing due to non-executable file
85
86 if ($ERR_nonexe_file) {
87     my $noexe = './barfooblatboz';
88     touch($noexe);
89
90     run_make_test(qq!
91     one: ; -$noexe xx yy
92     two: ; $noexe aa bb
93     !,
94                   'one', "$noexe xx yy\n#MAKE#: $noexe: $ERR_nonexe_file\n#MAKE#: [#MAKEFILE#:2: one] Error 127 (ignored)\n");
95
96     unlink($noexe);
97 }
98
99 # Try failing by "running" a directory
100
101 if ($ERR_exe_dir) {
102     mkdir('sd', 0775) or print "mkdir: sd: $!\n";
103
104     run_make_test(q!
105 PATH := .
106 all: ; sd
107 !,
108               '', "sd\n#MAKE#: sd: $ERR_exe_dir\n#MAKE#: *** [#MAKEFILE#:3: all] Error 127", 512);
109
110     run_make_test(q!
111 all: ; ./sd
112 !,
113               '', "./sd\n#MAKE#: ./sd: $ERR_exe_dir\n#MAKE#: *** [#MAKEFILE#:2: all] Error 127", 512);
114
115     rmdir('sd');
116 }
117
118 1;