Debian Codegraph @

tests/scripts/options/dash-k

raw
1 # -*-perl-*-
2
3 $description = "Test the make -k (don't stop on error) option.\n";
4
5 $details = "\
6 The makefile created in this test is a simulation of building
7 a small product. However, the trick to this one is that one
8 of the dependencies of the main target does not exist.
9 Without the -k option, make would fail immediately and not
10 build any part of the target. What we are looking for here,
11 is that make builds the rest of the dependencies even though
12 it knows that at the end it will fail to rebuild the main target.";
13
14 open(MAKEFILE,"> $makefile");
15
16 # The Contents of the MAKEFILE ...
17
18 print MAKEFILE <<EOF;
19 VPATH = $workdir
20 edit: main.o kbd.o commands.o display.o
21 \t\@echo cc -o edit main.o kbd.o commands.o display.o
22
23 main.o : main.c defs.h
24 \t\@echo cc -c main.c
25
26 kbd.o : kbd.c defs.h command.h
27 \t\@echo cc -c kbd.c
28
29 commands.o : command.c defs.h command.h
30 \t\@echo cc -c commands.c
31
32 display.o : display.c defs.h buffer.h
33 \t\@echo cc -c display.c
34 EOF
35
36 # END of Contents of MAKEFILE
37
38 close(MAKEFILE);
39
40
41 @files_to_touch = ("$workdir${pathsep}main.c","$workdir${pathsep}defs.h",
42 "$workdir${pathsep}command.h",
43 "$workdir${pathsep}commands.c","$workdir${pathsep}display.c",
44 "$workdir${pathsep}buffer.h",
45 "$workdir${pathsep}command.c");
46
47 &touch(@files_to_touch);
48
49 if ($vos) {
50 $error_code = 3307;
51 }
52 else {
53 $error_code = 512;
54 }
55
56 &run_make_with_options($makefile, "-k", &get_logfile, $error_code);
57
58 # Create the answer to what should be produced by this Makefile
59 $answer = "cc -c main.c
60 $make_name: *** No rule to make target 'kbd.c', needed by 'kbd.o'.
61 cc -c commands.c
62 cc -c display.c
63 $make_name: Target 'edit' not remade because of errors.\n";
64
65 # COMPARE RESULTS
66
67 &compare_output($answer, &get_logfile(1));
68
69 unlink(@files_to_touch) unless $keep;
70
71
72 # TEST 1: Make sure that top-level targets that depend on targets that
73 # previously failed to build, aren't attempted. Regression for PR/1634.
74
75 $makefile2 = &get_tmpfile;
76
77 open(MAKEFILE, "> $makefile2");
78 print MAKEFILE <<'EOF';
79 .SUFFIXES:
80
81 all: exe1 exe2; @echo making $@
82
83 exe1 exe2: lib; @echo cp $^ $@
84
85 lib: foo.o; @echo cp $^ $@
86
87 foo.o: ; exit 1
88 EOF
89
90 close(MAKEFILE);
91
92 my $answer = "exit 1
93 $makefile2:9: *** [foo.o] error 1
94
95 #0 foo.o at work/options/dash-k.mk.1:9
96 #1 lib at work/options/dash-k.mk.1:7
97 #2 exe1 at work/options/dash-k.mk.1:5
98 #3 all at work/options/dash-k.mk.1:3
99 $make_name: Target 'all' not remade because of errors.
100 ";
101
102 my $logfile = &get_logfile;
103 &run_make_with_options($makefile2, "-k", $logfile, $error_code);
104 my $slurp = &read_file_into_string ($logfile);
105 $slurp =~ s{at .*work/options/}{at work/options/}gm;
106 &compare_output_string($answer, $slurp, $logfile);
107
108 # TEST -- make sure we keep the error code if we can't create an included
109 # makefile.
110
111 if (defined $ERR_no_such_file) {
112 run_make_test('all: ; @echo hi
113 include ifile
114 ifile: no-such-file; @false
115 ',
116 '-k',
117 "#MAKEFILE#:2: ifile: $ERR_no_such_file
118 #MAKE#: *** No rule to make target 'no-such-file', needed by 'ifile'.
119 #MAKE#: Failed to remake makefile 'ifile'.
120 hi\n",
121 512);
122 }
123
124 1;