1# $NetBSD: var-op-shell.mk,v 1.4 2021/02/06 04:55:08 sjg 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. 7OUTPUT!= 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. 21OUTPUT!= 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. 28OUTPUT!= echo "failed"; false 29.if ${OUTPUT} != "failed" 30. error 31.endif 32 33# A command with empty output may fail as well. 34OUTPUT!= 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. 41OUTPUT!= 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. 48OUTPUT!= echo "before"; false; echo "after" 49.if ${OUTPUT} != "before after" 50. error 51.endif 52 53# This should result in a warning about "exited on a signal". 54# This used to be kill -14 (SIGALRM), but that stopped working on 55# Darwin18 after recent update. 56OUTPUT!= kill $$$$ 57.if ${OUTPUT} != "" 58. error 59.endif 60 61# A nonexistent command produces a non-zero exit status. 62OUTPUT!= /bin/no/such/command 63.if ${OUTPUT} != "" 64. error 65.endif 66 67# The output from the shell's stderr is not captured, it just passes through. 68OUTPUT!= echo "stdout"; echo "stderr" 1>&2 69.if ${OUTPUT} != "stdout" 70. error 71.endif 72 73# The 8 dollar signs end up as 4 dollar signs when expanded. The shell sees 74# the command "echo '$$$$'". The 4 dollar signs are stored in OUTPUT, and 75# when that variable is expanded, they expand to 2 dollar signs. 76OUTPUT!= echo '$$$$$$$$' 77.if ${OUTPUT} != "\$\$" 78. error 79.endif 80 81all: 82