]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/bmake/unit-tests/var-op-shell.mk
Merge bmake-20201117
[FreeBSD/FreeBSD.git] / contrib / bmake / unit-tests / var-op-shell.mk
1 # $NetBSD: var-op-shell.mk,v 1.3 2020/11/09 20:39:46 rillig Exp $
2 #
3 # Tests for the != variable assignment operator, which runs its right-hand
4 # side through the shell.
5
6 # The variable OUTPUT gets the output from running the shell command.
7 OUTPUT!=        echo "success"'ful'
8 .if ${OUTPUT} != "successful"
9 .  error
10 .endif
11
12 # Since 2014-08-20, the output of the shell command may be empty.
13 #
14 # On 1996-05-29, when the '!=' assignment operator and Cmd_Exec were added,
15 # an empty output produced the error message "Couldn't read shell's output
16 # for \"%s\"".
17 #
18 # The error message is still there but reserved for technical errors.
19 # It may be possible to trigger the error message by killing the shell after
20 # reading part of its output.
21 OUTPUT!=        true
22 .if ${OUTPUT} != ""
23 .  error
24 .endif
25
26 # The output of a shell command that failed is processed nevertheless.
27 # TODO: Make this an error in lint mode.
28 OUTPUT!=        echo "failed"; false
29 .if ${OUTPUT} != "failed"
30 .  error
31 .endif
32
33 # A command with empty output may fail as well.
34 OUTPUT!=        false
35 .if ${OUTPUT} != ""
36 .  error
37 .endif
38
39 # In the output of the command, each newline is replaced with a space.
40 # Except for the very last one, which is discarded.
41 OUTPUT!=        echo "line 1"; echo "line 2"
42 .if ${OUTPUT} != "line 1 line 2"
43 .  error
44 .endif
45
46 # A failing command in the middle results in the exit status 0, which in the
47 # end means that the whole sequence of commands succeeded.
48 OUTPUT!=        echo "before"; false; echo "after"
49 .if ${OUTPUT} != "before after"
50 .  error
51 .endif
52
53 # NB: The signal number must be numeric since some shells (which ones?) don't
54 # accept symbolic signal names.  14 is typically SIGALRM.
55 #
56 # XXX: The number of the signal is not mentioned in the warning since that
57 # would have been difficult to implement; currently the errfmt is a format
58 # string containing a single %s conversion.
59 OUTPUT!=        kill -14 $$$$
60 .if ${OUTPUT} != ""
61 .  error
62 .endif
63
64 # A nonexistent command produces a non-zero exit status.
65 OUTPUT!=        /bin/no/such/command
66 .if ${OUTPUT} != ""
67 .  error
68 .endif
69
70 # The output from the shell's stderr is not captured, it just passes through.
71 OUTPUT!=        echo "stdout"; echo "stderr" 1>&2
72 .if ${OUTPUT} != "stdout"
73 .  error
74 .endif
75
76 # The 8 dollar signs end up as 4 dollar signs when expanded.  The shell sees
77 # the command "echo '$$$$'".  The 4 dollar signs are stored in OUTPUT, and
78 # when that variable is expanded, they expand to 2 dollar signs.
79 OUTPUT!=        echo '$$$$$$$$'
80 .if ${OUTPUT} != "\$\$"
81 .  error
82 .endif
83
84 all: