xref: /freebsd/contrib/bmake/unit-tests/varmod-assign-shell.mk (revision d21e322d563e0fd1f92c22205c2ced4bcd22dc23)
1# $NetBSD: varmod-assign-shell.mk,v 1.8 2024/07/04 17:47:54 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
19DIRECT=		previous
20# expect+1: warning: Command "echo output; (exit 13)" exited with status 13
21DIRECT!=	echo output; (exit 13)
22
23ASSIGNED=	previous
24.MAKEFLAGS: -dv			# to see the "Capturing" debug output
25# expect+1: warning: while evaluating variable "ASSIGNED" with value "previous": Command "echo output; (exit 13)" exited with status 13
26_:=		${ASSIGNED::!=echo output; ${:U(exit 13)}}
27.MAKEFLAGS: -d0
28
29all:
30	@echo DIRECT=${DIRECT:Q}
31	@echo ASSIGNED=${ASSIGNED:Q}
32