1# -*-perl-*- 2# $Id: foreach,v 1.1.1.1 2014/08/18 06:47:57 christos Exp $ 3 4$description = "Test the foreach function."; 5 6$details = "This is a test of the foreach function in gnu make. 7This function starts with a space separated list of 8names and a variable. Each name in the list is subsituted 9into the variable and the given text evaluated. The general 10form of the command is $(foreach var,$list,$text). Several 11types of foreach loops are tested\n"; 12 13 14# TEST 0 15 16# Set an environment variable that we can test in the makefile. 17$extraENV{FOOFOO} = 'foo foo'; 18 19run_make_test("space = ' '".' 20null := 21auto_var = udef space CC null FOOFOO MAKE foo CFLAGS WHITE @ < 22foo = bletch null @ garf 23av = $(foreach var, $(auto_var), $(origin $(var)) ) 24override WHITE := BLACK 25for_var = $(addsuffix .c,foo $(null) $(foo) $(space) $(av) ) 26fe = $(foreach var2, $(for_var),$(subst .c,.o, $(var2) ) ) 27all: auto for2 28auto : ; @echo $(av) 29for2: ; @echo $(fe)', 30 '-e WHITE=WHITE CFLAGS=', 31 "undefined file default file environment default file command line override automatic automatic 32foo.o bletch.o null.o @.o garf.o .o .o undefined.o file.o default.o file.o environment.o default.o file.o command.o line.o override.o automatic.o automatic.o"); 33 34delete $extraENV{FOOFOO}; 35 36# TEST 1: Test that foreach variables take precedence over global 37# variables in a global scope (like inside an eval). Tests bug #11913 38 39run_make_test(' 40.PHONY: all target 41all: target 42 43x := BAD 44 45define mktarget 46target: x := $(x) 47target: ; @echo "$(x)" 48endef 49 50x := GLOBAL 51 52$(foreach x,FOREACH,$(eval $(value mktarget)))', 53 '', 54 'FOREACH'); 55 56 57# TEST 2: Check some error conditions. 58 59run_make_test(' 60x = $(foreach ) 61y = $x 62 63all: ; @echo $y', 64 '', 65 "#MAKEFILE#:2: *** insufficient number of arguments (1) to function `foreach'. Stop.", 66 512); 67 68run_make_test(' 69x = $(foreach ) 70y := $x 71 72all: ; @echo $y', 73 '', 74 "#MAKEFILE#:2: *** insufficient number of arguments (1) to function `foreach'. Stop.", 75 512); 76 771; 78