Home | History | Annotate | Line # | Download | only in unit-tests
      1 # $NetBSD: varmod-assign-shell.mk,v 1.11 2025/01/11 21:21:33 rillig Exp $
      2 #
      3 # Tests for the variable modifier '::!=', which assigns the output of a shell
      4 # command to the variable, but only if the command exited successfully.  This
      5 # is different from the other places that capture the output of an external
      6 # command (variable assignment operator '!=', expression modifier ':sh',
      7 # expression modifier ':!...!'), which also use the output when the shell
      8 # command fails or crashes.
      9 #
     10 # The variable modifier '::!=' and its close relatives have been around since
     11 # var.c 1.45 from 2000-06-01.
     12 #
     13 # Before 2020.08.25.21.16.53, the variable modifier '::!=' had a bug for
     14 # unsuccessful commands, it put the previous value of the variable into the
     15 # error message instead of the command that was executed.  That's where the
     16 # counterintuitive error message 'make: "previous" returned non-zero status'
     17 # comes from.
     18 
     19 DIRECT=		previous
     20 # expect+1: warning: Command "echo output; (exit 13)" exited with status 13
     21 DIRECT!=	echo output; (exit 13)
     22 
     23 ASSIGNED=	previous
     24 .MAKEFLAGS: -dv			# to see the "Capturing" debug output
     25 # expect+1: warning: Command "echo output; (exit 13)" exited with status 13
     26 _:=		${ASSIGNED::!=echo output; ${:U(exit 13)}}
     27 .MAKEFLAGS: -d0
     28 
     29 all:
     30 	@echo DIRECT=${DIRECT:Q}
     31 	@echo ASSIGNED=${ASSIGNED:Q}
     32