diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-11 08:21:29 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-11 08:21:29 +0000 |
commit | 29cd838eab01ed7110f3ccb2e8c6a35c8a31dbcc (patch) | |
tree | 63ef546b10a81d461e5cf5ed9e98a68cd7dee1aa /src/kmk/tests/scripts/functions/eval | |
parent | Initial commit. (diff) | |
download | kbuild-29cd838eab01ed7110f3ccb2e8c6a35c8a31dbcc.tar.xz kbuild-29cd838eab01ed7110f3ccb2e8c6a35c8a31dbcc.zip |
Adding upstream version 1:0.1.9998svn3589+dfsg.upstream/1%0.1.9998svn3589+dfsg
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | src/kmk/tests/scripts/functions/eval | 169 | ||||
-rw-r--r-- | src/kmk/tests/scripts/functions/evalcall | 119 |
2 files changed, 288 insertions, 0 deletions
diff --git a/src/kmk/tests/scripts/functions/eval b/src/kmk/tests/scripts/functions/eval new file mode 100644 index 0000000..90513bd --- /dev/null +++ b/src/kmk/tests/scripts/functions/eval @@ -0,0 +1,169 @@ +# -*-perl-*- + +$description = "Test the eval function."; + +$details = "This is a test of the eval function in GNU make. +This function will evaluate inline makefile syntax and incorporate the +results into its internal database.\n"; + +open(MAKEFILE,"> $makefile"); + +print MAKEFILE <<'EOF'; +define Y + all:: ; @echo $AA + A = B +endef + +X = $(eval $(value Y)) + +$(eval $(shell echo A = A)) +$(eval $(Y)) +$(eval A = C) +$(eval $(X)) +EOF + +close(MAKEFILE); + +&run_make_with_options($makefile, "", &get_logfile); + +# Create the answer to what should be produced by this Makefile +$answer = "AA\nBA\n"; + +&compare_output($answer,&get_logfile(1)); + +# Test to make sure defining variables when we have extra scope pushed works +# as expected. + +$makefile2 = &get_tmpfile; + +open(MAKEFILE,"> $makefile2"); + +print MAKEFILE <<'EOF'; +VARS = A B + +VARSET = $(1) = $(2) + +$(foreach v,$(VARS),$(eval $(call VARSET,$v,$v))) + +all: ; @echo A = $(A) B = $(B) +EOF + +close(MAKEFILE); + +&run_make_with_options($makefile2, "", &get_logfile); + +# Create the answer to what should be produced by this Makefile +$answer = "A = A B = B\n"; + +&compare_output($answer,&get_logfile(1)); + +# Test to make sure eval'ing inside conditionals works properly + +$makefile3 = &get_tmpfile; + +open(MAKEFILE,"> $makefile3"); + +print MAKEFILE <<'EOF'; +FOO = foo + +all:: ; @echo it + +define Y + all:: ; @echo worked +endef + +ifdef BAR +$(eval $(Y)) +endif + +EOF + +close(MAKEFILE); + +&run_make_with_options($makefile3, "", &get_logfile); +$answer = "it\n"; +&compare_output($answer,&get_logfile(1)); + +&run_make_with_options($makefile3, "BAR=1", &get_logfile); +$answer = "it\nworked\n"; +&compare_output($answer,&get_logfile(1)); + + +# TEST very recursive invocation of eval + +$makefile3 = &get_tmpfile; + +open(MAKEFILE,"> $makefile3"); + +print MAKEFILE <<'EOF'; +..9 := 0 1 2 3 4 5 6 7 8 9 +rev=$(eval res:=)$(foreach word,$1,$(eval res:=${word} ${res}))${res} +a:=$(call rev,${..9}) +all: ; @echo '[$(a)]' + +EOF + +close(MAKEFILE); + +&run_make_with_options($makefile3, "", &get_logfile); +$answer = "[ 9 8 7 6 5 4 3 2 1 0 ]\n"; +&compare_output($answer,&get_logfile(1)); + + +# TEST eval with no filename context. +# The trick here is that because EVAR is taken from the environment, it must +# be evaluated before every command is invoked. Make sure that works, when +# we have no file context for reading_file (bug # 6195) + +$makefile4 = &get_tmpfile; + +open(MAKEFILE,"> $makefile4"); + +print MAKEFILE <<'EOF'; +EVAR = $(eval FOBAR = 1) +all: ; @echo "OK" + +EOF + +close(MAKEFILE); + +$extraENV{EVAR} = '1'; +&run_make_with_options($makefile4, "", &get_logfile); +$answer = "OK\n"; +&compare_output($answer,&get_logfile(1)); + + +# Clean out previous information to allow new run_make_test() interface. +# If we ever convert all the above to run_make_test() we can remove this line. +$makefile = undef; + +# Test handling of backslashes in strings to be evaled. + +run_make_test(' +define FOO +all: ; @echo hello \ +world +endef +$(eval $(FOO)) +', '', 'hello world'); + +run_make_test(' +define FOO +all: ; @echo '."'".'he\llo'."'".' + @echo world +endef +$(eval $(FOO)) +', '', 'he\llo +world'); + + +# We don't allow new target/prerequisite relationships to be defined within a +# command script, because these are evaluated after snap_deps() and that +# causes lots of problems (like core dumps!) +# See Savannah bug # 12124. + +run_make_test('deps: ; $(eval deps: foo)', '', + '#MAKEFILE#:1: *** prerequisites cannot be defined in recipes. Stop.', + 512); + +1; diff --git a/src/kmk/tests/scripts/functions/evalcall b/src/kmk/tests/scripts/functions/evalcall new file mode 100644 index 0000000..f0213c2 --- /dev/null +++ b/src/kmk/tests/scripts/functions/evalcall @@ -0,0 +1,119 @@ +# $Id: evalcall 2413 2010-09-11 17:43:04Z bird $ -*-perl-*- +## @file +# $(evalcall var,argN...) +# + +# +# Copyright (c) 2008-2010 knut st. osmundsen <bird-kBuild-spamx@anduin.net> +# +# This file is part of kBuild. +# +# kBuild is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# kBuild is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with kBuild. If not, see <http://www.gnu.org/licenses/> +# +# + +$description = "Tests the $(evalcall ) function"; + +$details = "A few simple tests, nothing spectacular."; + +if ($is_kmk) { + + # TEST #0 - check that the feature is present. + # -------------------------------------------- + run_make_test(' +FUNC = local .RETURN = $2 $1 +ifneq ($(evalcall FUNC,a,b),b a) +$(error sub-test 0 failed: $(evalcall FUNC,a,b)) +endif + +.PHONY: all +all: ; @: +', +'', +''); + + # TEST #1 - the real test. + # ------------------------ + run_make_test(' + +FUNC = local .RETURN = $2 $1 +ifneq ($(evalcall FUNC,a,b),b a) +$(error sub-test 0 failed) +endif + +ADD = local .RETURN = $(expr $1 + $2) +ifneq ($(evalcall ADD,1,2),3) +$(error sub-test 1 failed) +endif + +define POP +local words := $(words $($1)) +local .RETURN := $(word $(words), $($1)) +$1 := $(wordlist 1, $(expr $(words) - 1), $($1)) +endef +stack-var = a b c d +ifneq ($(evalcall POP,stack-var),d) +$(error sub-test 2d failed) +endif +ifneq ($(evalcall POP,stack-var),c) +$(error sub-test 2c failed) +endif +ifneq ($(evalcall POP,stack-var),b) +$(error sub-test 2b failed) +endif +ifneq ($(evalcall POP,stack-var),a) +$(error sub-test 2a failed) +endif + + +# Negative tests: + +.RETURN = $2 $1 +FUNC = +ifneq ($(evalcall FUNC,a,b),) +$(error sub-test 10 failed) +endif + +.RETURN = +FUNC = .RETURN = $2 $1 +ifneq ($(evalcall FUNC,a,b),) +$(error sub-test 11 failed) +endif + + +# Test .ARGC: + +FUNC = local .RETURN = $(.ARGC) +ifneq ($(evalcall FUNC,a,b),2) +$(error sub-test 20 failed) +endif +ifneq ($(evalcall FUNC),0) +$(error sub-test 21 failed) +endif +ifneq ($(evalcall FUNC,aasdfasdf),1) +$(error sub-test 22 failed) +endif + + +.PHONY: all +all: ; @: +', +'', +''); +} + + +# Indicate that we're done. +1; + |