3 $description = "Test handling of temporary file created from stdin.";
5 # These tests rely on the test_driver checking for leftover temporary content
7 create_file('input.mk', "world:=1\n");
8 create_file('bye.mk', "moon:=2\n");
11 # Test that makes leaves no temp file when make code is piped to stdin and -v,
12 # -h or an invalid option is specified.
13 my @opts = ('-v', '-h', '--nosuchopt');
14 my @exit_codes = (0, 0, 512);
15 for my $i (0 .. $#opts) {
17 open(STDIN, "<", 'input.mk') || die "$0: cannot open input.mk for reading: $!";
19 all:; $(info hello world)
21 "$opts[$i] -f-", "/uilt for /", $exit_codes[$i]);
25 # Test that a stdin temp file is removed.
27 open(STDIN, "<", 'input.mk') || die "$0: cannot open input.mk for reading: $!";
29 all:; $(info world=$(world))
31 '-f-', "world=1\n#MAKE#: 'all' is up to date.\n");
34 # Test that a stdin temp file is removed, even when make re-execs.
35 # Also test that make honors TMPDIR to create the temp file.
36 # Ensure touching bye.mk causes re-exec.
37 &utouch(-600, 'bye.mk');
39 open(STDIN, "<", 'input.mk') || die "$0: cannot open input.mk for reading: $!";
43 $(MAKE_RESTARTS)bye.mk: force; touch $@
46 '-R --debug=b -f-', "/Re-executing.+?--temp-stdin=\Q$temppath\E/");
48 if ($port_type eq 'UNIX') {
49 # POSIX doesn't require sh to set PPID so test this
50 my $cmd = create_command();
51 add_options($cmd, '-f', '/dev/null', '-E', q!all:;@echo $$PPID!);
52 my $fout = 'ppidtest.out';
53 run_command_with_output($fout, @$cmd);
54 $_ = read_file_into_string($fout);
60 # Test that make removes the temporary file which holds make code from stdin,
61 # even when a signal is received.
62 # include bye.mk and bye.mk: rule is needed to cause make to keep the temporary
63 # file for re-exec. Without re-exec make will remove the file before the signal
65 # sleep is needed to let make write its "... Terminated" message to the log
67 &utouch(-600, 'bye.mk');
69 open(STDIN, "<", 'input.mk') || die "$0: cannot open input.mk for reading: $!";
72 pid:=$(shell echo $$PPID)
74 bye.mk: force; @kill -TERM $(pid) && sleep 16
76 !, '-f-', '/#MAKE#: \*\*\* \[#MAKEFILE#:5: bye.mk] Terminated/', POSIX::SIGTERM);
81 # Test that a stdin temp file is removed, when execvp fails to re-exec make.
82 # In order to cause execvp to fail, copy the tested make binary to the temp
83 # directory and take away the 'x' bit.
87 my $tmakedir = File::Spec->catfile($cwdpath, 'tmakedir');
88 mkdir($tmakedir, 0770);
89 my $makecopy = File::Spec->catfile($tmakedir, 'make');
90 copy("$mkpath", $makecopy);
91 # Set file mode bits, because perl copy won't.
92 chmod 0700, $makecopy;
94 my @make_orig = @make_command;
95 @make_command = ($makecopy);
97 # Ensure touching bye.mk causes re-exec.
98 &utouch(-600, 'bye.mk');
100 open(STDIN, "<", 'input.mk') || die "$0: cannot open input.mk for reading: $!";
104 \$(MAKE_RESTARTS)bye.mk: force; touch \$@ && chmod u-x $makecopy
107 "-f-", "touch bye.mk && chmod u-x $makecopy\nmake: $makecopy: $ERR_nonexe_file\n", 32512);
109 @make_command = @make_orig;
115 unlink('input.mk', 'bye.mk');
117 # This tells the test driver that the perl test script executed properly.