Debian Codegraph @

tests/scripts/features/exec

raw
1 # -*-perl-*-
2
3 use warnings;
4
5 my $description = "Test that make can execute binaries as well as scripts with"
6 ." various shabangs and without a shbang";
7 my $details = "The various shells that this test uses are the default"
8 ." /bin/sh, \$SHELL and the perl interpreter that is"
9 ." executing this test program. The shells are used for the value"
10 ." of SHELL inside the test makefile and also as a shbang in the"
11 ." executed script. There is also a test which executes a script"
12 ." that has no shbang.";
13
14 # Only bother with this on UNIX systems
15 $port_type eq 'UNIX' or return -1;
16 $^O =~ /cygwin/ and return -1;
17
18 my @shbangs = ('', '#!/bin/sh', "#!$perl_name");
19 my @shells = ('', 'SHELL=/bin/sh');
20
21 # Try whatever shell the user has, as long as it's not a C shell.
22 # The C shell is not usable with make, due to not correctly handling
23 # file descriptors and possibly other issues.
24 my $usersh = $origENV{SHELL};
25 if ($usersh !~ /csh/) {
26 push @shbangs, ("#!$usersh");
27 push @shells, ("SHELL=$usersh");
28 }
29
30 my $answer = 'hello, world';
31
32 # tests [0-11]
33 # Have a makefile with various SHELL= exec a shell program with varios
34 # shbangs or without a shbang at all.
35 my $stem = './exec.cmd';
36 my $k = 0;
37 for my $shbang (@shbangs) {
38 for my $shell (@shells) {
39 my $cmd = $k ? "$stem.$k" : $stem;
40 ++$k;
41 unlink $cmd;
42 open(CMD,"> $cmd");
43 print CMD "$shbang\n";
44 print CMD "printf \"$answer\\n\";\n";
45 close(CMD);
46 chmod 0700, $cmd;
47
48 run_make_test("# shbang=$shbang\n# shell=$shell" . q!
49 all:; @$(CMD)
50 !, "$shell CMD=$cmd", "$answer\n");
51
52 rmfiles($cmd);
53 }
54 }
55
56 # tests [12-14]
57 # Exec a binary from a makefile that has SHELL=.
58 for my $shell (@shells) {
59 run_make_test(q!
60 all:; @#PERL# -e 'printf "$(ANSWER)\n"';
61 !, "$shell ANSWER='$answer'", "$answer\n");
62 }
63
64 # test 15
65 # Use perl as a shell.
66 run_make_test(q!
67 SHELL = #PERL#
68 .SHELLFLAGS = -e
69 all:; @printf "$(ANSWER)\n";
70 !, "ANSWER='$answer'", "$answer\n");
71
72 1;