summaryrefslogtreecommitdiffstats
path: root/src/kmk/tests/scripts/functions
diff options
context:
space:
mode:
Diffstat (limited to 'src/kmk/tests/scripts/functions')
-rw-r--r--src/kmk/tests/scripts/functions/abspath81
-rw-r--r--src/kmk/tests/scripts/functions/addprefix44
-rw-r--r--src/kmk/tests/scripts/functions/addsuffix36
-rw-r--r--src/kmk/tests/scripts/functions/andor50
-rw-r--r--src/kmk/tests/scripts/functions/basename44
-rw-r--r--src/kmk/tests/scripts/functions/call92
-rw-r--r--src/kmk/tests/scripts/functions/dir44
-rw-r--r--src/kmk/tests/scripts/functions/error71
-rw-r--r--src/kmk/tests/scripts/functions/eval169
-rw-r--r--src/kmk/tests/scripts/functions/evalcall119
-rw-r--r--src/kmk/tests/scripts/functions/expr74
-rw-r--r--src/kmk/tests/scripts/functions/file161
-rw-r--r--src/kmk/tests/scripts/functions/filter-out42
-rw-r--r--src/kmk/tests/scripts/functions/findstring47
-rw-r--r--src/kmk/tests/scripts/functions/flavor44
-rw-r--r--src/kmk/tests/scripts/functions/for69
-rw-r--r--src/kmk/tests/scripts/functions/foreach97
-rw-r--r--src/kmk/tests/scripts/functions/guile99
-rw-r--r--src/kmk/tests/scripts/functions/if33
-rw-r--r--src/kmk/tests/scripts/functions/if-expr84
-rw-r--r--src/kmk/tests/scripts/functions/insert106
-rw-r--r--src/kmk/tests/scripts/functions/intersects94
-rw-r--r--src/kmk/tests/scripts/functions/join44
-rw-r--r--src/kmk/tests/scripts/functions/lastpos118
-rw-r--r--src/kmk/tests/scripts/functions/length71
-rw-r--r--src/kmk/tests/scripts/functions/length-var75
-rw-r--r--src/kmk/tests/scripts/functions/notdir44
-rw-r--r--src/kmk/tests/scripts/functions/origin54
-rw-r--r--src/kmk/tests/scripts/functions/pos118
-rw-r--r--src/kmk/tests/scripts/functions/printf80
-rw-r--r--src/kmk/tests/scripts/functions/realpath82
-rw-r--r--src/kmk/tests/scripts/functions/root172
-rw-r--r--src/kmk/tests/scripts/functions/select96
-rw-r--r--src/kmk/tests/scripts/functions/shell60
-rw-r--r--src/kmk/tests/scripts/functions/sort51
-rw-r--r--src/kmk/tests/scripts/functions/strip57
-rw-r--r--src/kmk/tests/scripts/functions/substitution38
-rw-r--r--src/kmk/tests/scripts/functions/substr125
-rw-r--r--src/kmk/tests/scripts/functions/suffix57
-rw-r--r--src/kmk/tests/scripts/functions/translate76
-rw-r--r--src/kmk/tests/scripts/functions/value30
-rw-r--r--src/kmk/tests/scripts/functions/warning83
-rw-r--r--src/kmk/tests/scripts/functions/while73
-rw-r--r--src/kmk/tests/scripts/functions/wildcard103
-rw-r--r--src/kmk/tests/scripts/functions/word167
45 files changed, 3574 insertions, 0 deletions
diff --git a/src/kmk/tests/scripts/functions/abspath b/src/kmk/tests/scripts/functions/abspath
new file mode 100644
index 0000000..84c30ab
--- /dev/null
+++ b/src/kmk/tests/scripts/functions/abspath
@@ -0,0 +1,81 @@
+# -*-perl-*-
+$description = "Test the abspath functions.";
+
+$details = "";
+
+run_make_test('
+ifneq ($(realpath $(abspath .)),$(CURDIR))
+ $(warning .: abs="$(abspath .)" real="$(realpath $(abspath .))" curdir="$(CURDIR)")
+endif
+
+ifneq ($(realpath $(abspath ./)),$(CURDIR))
+ $(warning ./: abs="$(abspath ./)" real="$(realpath $(abspath ./))" curdir="$(CURDIR)")
+endif
+
+ifneq ($(realpath $(abspath .///)),$(CURDIR))
+ $(warning .///: abs="$(abspath .///)" real="$(realpath $(abspath .///))" curdir="$(CURDIR)")
+endif
+
+ifneq ($(abspath /),/)
+ $(warning /: abspath="$(abspath /)")
+endif
+
+ifneq ($(abspath ///),/)
+ $(warning ///: abspath="$(abspath ///)")
+endif
+
+ifneq ($(abspath /.),/)
+ $(warning /.: abspath="$(abspath /.)")
+endif
+
+ifneq ($(abspath ///.),/)
+ $(warning ///.: abspath="$(abspath ///.)")
+endif
+
+ifneq ($(abspath /./),/)
+ $(warning /./: abspath="$(abspath /./)")
+endif
+
+ifneq ($(abspath /.///),/)
+ $(warning /.///: abspath="$(abspath /.///)")
+endif
+
+ifneq ($(abspath /..),/)
+ $(warning /..: abspath="$(abspath /..)")
+endif
+
+ifneq ($(abspath ///..),/)
+ $(warning ///..: abspath="$(abspath ///..)")
+endif
+
+ifneq ($(abspath /../),/)
+ $(warning /../: abspath="$(abspath /../)")
+endif
+
+ifneq ($(abspath /..///),/)
+ $(warning /..///: abspath="$(abspath /..///)")
+endif
+
+
+ifneq ($(abspath /foo/bar/..),/foo)
+ $(warning /foo/bar/..: abspath="$(abspath /foo/bar/..)")
+endif
+
+ifneq ($(abspath /foo/bar/../../../baz),/baz)
+ $(warning /foo/bar/../../../baz: abspath="$(abspath /foo/bar/../../../baz)")
+endif
+
+ifneq ($(abspath /foo/bar/../ /..),/foo /)
+ $(warning /foo/bar/../ /..: abspath="$(abspath /foo/bar/../ /..)")
+endif
+
+
+.PHONY: all
+all: ; @:
+',
+'',
+'');
+
+
+# This tells the test driver that the perl test script executed properly.
+1;
diff --git a/src/kmk/tests/scripts/functions/addprefix b/src/kmk/tests/scripts/functions/addprefix
new file mode 100644
index 0000000..1845552
--- /dev/null
+++ b/src/kmk/tests/scripts/functions/addprefix
@@ -0,0 +1,44 @@
+$description = "The following test creates a makefile to test the addprefix "
+ ."function.";
+
+$details = "";
+
+# IF YOU NEED >1 MAKEFILE FOR THIS TEST, USE &get_tmpfile; TO GET
+# THE NAME OF THE MAKEFILE. THIS INSURES CONSISTENCY AND KEEPS TRACK OF
+# HOW MANY MAKEFILES EXIST FOR EASY DELETION AT THE END.
+# EXAMPLE: $makefile2 = &get_tmpfile;
+
+
+open(MAKEFILE,"> $makefile");
+
+# The Contents of the MAKEFILE ...
+
+print MAKEFILE "string := \$(addprefix src${pathsep},a.b.z.foo hacks) \n"
+ ."all: \n"
+ ."\t\@echo \$(string) \n";
+
+# END of Contents of MAKEFILE
+
+close(MAKEFILE);
+
+&run_make_with_options($makefile,"",&get_logfile,0);
+
+# Create the answer to what should be produced by this Makefile
+$answer = "src${pathsep}a.b.z.foo src${pathsep}hacks\n";
+
+# COMPARE RESULTS
+
+# In this call to compare output, you should use the call &get_logfile(1)
+# to send the name of the last logfile created. You may also use
+# the special call &get_logfile(1) which returns the same as &get_logfile(1).
+
+&compare_output($answer,&get_logfile(1));
+
+# This tells the test driver that the perl test script executed properly.
+1;
+
+
+
+
+
+
diff --git a/src/kmk/tests/scripts/functions/addsuffix b/src/kmk/tests/scripts/functions/addsuffix
new file mode 100644
index 0000000..da4fbb7
--- /dev/null
+++ b/src/kmk/tests/scripts/functions/addsuffix
@@ -0,0 +1,36 @@
+# -*-perl-*-
+$description = "Test the addsuffix function.";
+
+$details = "";
+
+
+open(MAKEFILE,"> $makefile");
+
+# The Contents of the MAKEFILE ...
+
+print MAKEFILE <<EOMAKE;
+string := \$(addsuffix .c,src${pathsep}a.b.z.foo hacks)
+one: ; \@echo \$(string)
+
+two: ; \@echo \$(addsuffix foo,)
+EOMAKE
+
+close(MAKEFILE);
+
+
+# TEST 0
+
+&run_make_with_options($makefile, "", &get_logfile);
+$answer = "src${pathsep}a.b.z.foo.c hacks.c\n";
+&compare_output($answer,&get_logfile(1));
+
+
+# TEST 1
+
+&run_make_with_options($makefile, "two", &get_logfile);
+$answer = "\n";
+&compare_output($answer,&get_logfile(1));
+
+
+# This tells the test driver that the perl test script executed properly.
+1;
diff --git a/src/kmk/tests/scripts/functions/andor b/src/kmk/tests/scripts/functions/andor
new file mode 100644
index 0000000..62e0c2e
--- /dev/null
+++ b/src/kmk/tests/scripts/functions/andor
@@ -0,0 +1,50 @@
+# -*-perl-*-
+$description = "Test the and & or functions.\n";
+
+$details = "Try various uses of and & or to ensure they all give the correct
+results.\n";
+
+# TEST #0
+# For $(and ...), it will either be empty or the last value
+run_make_test('
+NEQ = $(subst $1,,$2)
+f =
+t = true
+
+all:
+ @echo 1 $(and ,$t)
+ @echo 2 $(and $t)
+ @echo 3 $(and $t,)
+ @echo 4 $(and z,true,$f,false)
+ @echo 5 $(and $t,$f,$(info bad short-circuit))
+ @echo 6 $(and $(call NEQ,a,b),true)
+ @echo 7 $(and $(call NEQ,a,a),true)
+ @echo 8 $(and z,true,fal,se) hi
+ @echo 9 $(and ,true,fal,se)there
+ @echo 10 $(and $(e) ,$t)',
+ '',
+ "1\n2 true\n3\n4\n5\n6 true\n7\n8 se hi\n9 there\n10\n");
+
+# TEST #1
+# For $(or ...), it will either be empty or the first true value
+run_make_test('
+NEQ = $(subst $1,,$2)
+f =
+t = true
+
+all:
+ @echo 1 $(or , )
+ @echo 2 $(or $t)
+ @echo 3 $(or ,$t)
+ @echo 4 $(or z,true,$f,false)
+ @echo 5 $(or $t,$(info bad short-circuit))
+ @echo 6 $(or $(info short-circuit),$t)
+ @echo 7 $(or $(call NEQ,a,b),true)
+ @echo 8 $(or $(call NEQ,a,a),true)
+ @echo 9 $(or z,true,fal,se) hi
+ @echo 10 $(or ,true,fal,se)there
+ @echo 11 $(or $(e) ,$f)',
+ '',
+ "short-circuit\n1\n2 true\n3 true\n4 z\n5 true\n6 true\n7 b\n8 true\n9 z hi\n10 truethere\n11\n");
+
+1;
diff --git a/src/kmk/tests/scripts/functions/basename b/src/kmk/tests/scripts/functions/basename
new file mode 100644
index 0000000..08f2ea5
--- /dev/null
+++ b/src/kmk/tests/scripts/functions/basename
@@ -0,0 +1,44 @@
+$description = "The following test creates a makefile to test the suffix "
+ ."function.";
+
+$details = "";
+
+# IF YOU NEED >1 MAKEFILE FOR THIS TEST, USE &get_tmpfile; TO GET
+# THE NAME OF THE MAKEFILE. THIS INSURES CONSISTENCY AND KEEPS TRACK OF
+# HOW MANY MAKEFILES EXIST FOR EASY DELETION AT THE END.
+# EXAMPLE: $makefile2 = &get_tmpfile;
+
+
+open(MAKEFILE,"> $makefile");
+
+# The Contents of the MAKEFILE ...
+
+print MAKEFILE "string := \$(basename src${pathsep}a.b.z.foo.c src${pathsep}hacks src.bar${pathsep}a.b.z.foo.c src.bar${pathsep}hacks hacks) \n"
+ ."all: \n"
+ ."\t\@echo \$(string) \n";
+
+# END of Contents of MAKEFILE
+
+close(MAKEFILE);
+
+&run_make_with_options($makefile,"",&get_logfile,0);
+
+# Create the answer to what should be produced by this Makefile
+$answer = "src${pathsep}a.b.z.foo src${pathsep}hacks src.bar${pathsep}a.b.z.foo src.bar${pathsep}hacks hacks\n";
+
+# COMPARE RESULTS
+
+# In this call to compare output, you should use the call &get_logfile(1)
+# to send the name of the last logfile created. You may also use
+# the special call &get_logfile(1) which returns the same as &get_logfile(1).
+
+&compare_output($answer,&get_logfile(1));
+
+# This tells the test driver that the perl test script executed properly.
+1;
+
+
+
+
+
+
diff --git a/src/kmk/tests/scripts/functions/call b/src/kmk/tests/scripts/functions/call
new file mode 100644
index 0000000..dc1a623
--- /dev/null
+++ b/src/kmk/tests/scripts/functions/call
@@ -0,0 +1,92 @@
+# -*-perl-*-
+$description = "Test the call function.\n";
+
+$details = "Try various uses of call and ensure they all give the correct
+results.\n";
+
+run_make_test(q!
+# Simple, just reverse two things
+#
+reverse = $2 $1
+
+# A complex 'map' function, using recursive 'call'.
+#
+map = $(foreach a,$2,$(call $1,$a))
+
+# Test using a builtin; this is silly as it's simpler to do without call
+#
+my-notdir = $(call notdir,$(1))
+
+# Test using non-expanded builtins
+#
+my-foreach = $(foreach $(1),$(2),$(3))
+my-if = $(if $(1),$(2),$(3))
+
+# Test recursive invocations of call with different arguments
+#
+one = $(1) $(2) $(3)
+two = $(call one,$(1),foo,$(2))
+
+# Test recursion on the user-defined function. As a special case make
+# won't error due to this.
+# Implement transitive closure using $(call ...)
+#
+DEP_foo = bar baz quux
+DEP_baz = quux blarp
+rest = $(wordlist 2,$(words ${1}),${1})
+tclose = $(if $1,$(firstword $1)\
+ $(call tclose,$(sort ${DEP_$(firstword $1)} $(call rest,$1))))
+
+all: ; @echo '$(call reverse,bar,foo)'; \
+ echo '$(call map,origin,MAKE reverse map)'; \
+ echo '$(call my-notdir,a/b c/d e/f)'; \
+ echo '$(call my-foreach)'; \
+ echo '$(call my-foreach,a,,,)'; \
+ echo '$(call my-if,a,b,c)'; \
+ echo '$(call two,bar,baz)'; \
+ echo '$(call tclose,foo)';
+!,
+ "", "foo bar\ndefault file file\nb d f\n\n\nb\nbar foo baz\nfoo bar baz blarp quux \n");
+
+# These won't work because call expands all its arguments first, before
+# passing them on, then marks them as resolved/simple, so they're not
+# expanded again by the function.
+#
+# echo '$(call my-foreach,a,x y z,$$(a)$$(a))'; \
+# echo '$(call my-if,,$$(info don't print this),$$(info do print this))'
+#
+# $answer = "xx yy zz\ndo print this\n";
+
+# TEST eclipsing of arguments when invoking sub-calls
+
+run_make_test(q!
+all = $1 $2 $3 $4 $5 $6 $7 $8 $9
+
+level1 = $(call all,$1,$2,$3,$4,$5)
+level2 = $(call level1,$1,$2,$3)
+level3 = $(call level2,$1,$2,$3,$4,$5)
+
+all:
+ @echo $(call all,1,2,3,4,5,6,7,8,9,10,11)
+ @echo $(call level1,1,2,3,4,5,6,7,8)
+ @echo $(call level2,1,2,3,4,5,6,7,8)
+ @echo $(call level3,1,2,3,4,5,6,7,8)
+!,
+ "", "1 2 3 4 5 6 7 8 9\n1 2 3 4 5\n1 2 3\n1 2 3\n");
+
+# Ensure that variables are defined in global scope even in a $(call ...)
+
+delete $ENV{X123};
+
+run_make_test('
+tst = $(eval export X123)
+$(call tst)
+all: ; @echo "$${X123-not set}"
+',
+ '', "\n");
+
+1;
+
+### Local Variables:
+### eval: (setq whitespace-action (delq 'auto-cleanup whitespace-action))
+### End:
diff --git a/src/kmk/tests/scripts/functions/dir b/src/kmk/tests/scripts/functions/dir
new file mode 100644
index 0000000..f48fb8c
--- /dev/null
+++ b/src/kmk/tests/scripts/functions/dir
@@ -0,0 +1,44 @@
+$description = "The following test creates a makefile to test the dir "
+ ."function.";
+
+$details = "";
+
+# IF YOU NEED >1 MAKEFILE FOR THIS TEST, USE &get_tmpfile; TO GET
+# THE NAME OF THE MAKEFILE. THIS INSURES CONSISTENCY AND KEEPS TRACK OF
+# HOW MANY MAKEFILES EXIST FOR EASY DELETION AT THE END.
+# EXAMPLE: $makefile2 = &get_tmpfile;
+
+
+open(MAKEFILE,"> $makefile");
+
+# The Contents of the MAKEFILE ...
+
+print MAKEFILE "string := \$(dir src${pathsep}foo.c hacks) \n"
+ ."all: \n"
+ ."\t\@echo \$(string) \n";
+
+# END of Contents of MAKEFILE
+
+close(MAKEFILE);
+
+&run_make_with_options($makefile,"",&get_logfile,0);
+
+# Create the answer to what should be produced by this Makefile
+$answer = "src${pathsep} .${pathsep}\n";
+
+# COMPARE RESULTS
+
+# In this call to compare output, you should use the call &get_logfile(1)
+# to send the name of the last logfile created. You may also use
+# the special call &get_logfile(1) which returns the same as &get_logfile(1).
+
+&compare_output($answer,&get_logfile(1));
+
+# This tells the test driver that the perl test script executed properly.
+1;
+
+
+
+
+
+
diff --git a/src/kmk/tests/scripts/functions/error b/src/kmk/tests/scripts/functions/error
new file mode 100644
index 0000000..998afe4
--- /dev/null
+++ b/src/kmk/tests/scripts/functions/error
@@ -0,0 +1,71 @@
+# -*-Perl-*-
+
+$description = "\
+The following test creates a makefile to test the error function.";
+
+$details = "";
+
+open(MAKEFILE,"> $makefile");
+
+print MAKEFILE 'err = $(error Error found!)
+
+ifdef ERROR1
+$(error error is $(ERROR1))
+endif
+
+ifdef ERROR2
+$(error error is $(ERROR2))
+endif
+
+ifdef ERROR3
+all: some; @echo $(error error is $(ERROR3))
+endif
+
+ifdef ERROR4
+all: some; @echo error is $(ERROR4)
+ @echo $(error error is $(ERROR4))
+endif
+
+some: ; @echo Some stuff
+
+testvar: ; @: $(err)
+';
+
+close(MAKEFILE);
+
+# Test #1
+
+&run_make_with_options($makefile, "ERROR1=yes", &get_logfile, 512);
+$answer = "$makefile:4: *** error is yes. Stop.\n";
+&compare_output($answer,&get_logfile(1));
+
+# Test #2
+
+&run_make_with_options($makefile, "ERROR2=no", &get_logfile, 512);
+$answer = "$makefile:8: *** error is no. Stop.\n";
+&compare_output($answer,&get_logfile(1));
+
+# Test #3
+
+&run_make_with_options($makefile, "ERROR3=maybe", &get_logfile, 512);
+$answer = "Some stuff\n$makefile:12: *** error is maybe. Stop.\n";
+&compare_output($answer,&get_logfile(1));
+
+# Test #4
+
+&run_make_with_options($makefile, "ERROR4=definitely", &get_logfile, 512);
+$answer = "Some stuff\n$makefile:17: *** error is definitely. Stop.\n";
+&compare_output($answer,&get_logfile(1));
+
+# Test #5
+
+&run_make_with_options($makefile, "testvar", &get_logfile, 512);
+$answer = "$makefile:22: *** Error found!. Stop.\n";
+&compare_output($answer,&get_logfile(1));
+
+# This tells the test driver that the perl test script executed properly.
+1;
+
+### Local Variables:
+### eval: (setq whitespace-action (delq 'auto-cleanup whitespace-action))
+### End:
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;
+
diff --git a/src/kmk/tests/scripts/functions/expr b/src/kmk/tests/scripts/functions/expr
new file mode 100644
index 0000000..a68205f
--- /dev/null
+++ b/src/kmk/tests/scripts/functions/expr
@@ -0,0 +1,74 @@
+# $Id: expr 2413 2010-09-11 17:43:04Z bird $ -*-perl-*-
+## @file
+# $(expr expr)
+#
+
+#
+# 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 \$(expr ) function";
+
+$details = "Much of the basic testing is taken care of by features/ifcond.
+We only make sure \$(expr ) works here).";
+
+if ($is_kmk) {
+
+ # TEST #0 - check that the feature is present.
+ # --------------------------------------------
+ run_make_test('
+ifneq ($(expr 1+1),2)
+$(error sub-test 0 failed)
+endif
+.PHONY: all
+all: ; @:
+',
+'',
+'');
+
+ # TEST #1 - basics, the $(expr test checks the rest).
+ # ---------------------------------------------------
+ run_make_test('
+ifneq ($(expr 1==1),1)
+$(error sub-test 0 failed)
+endif
+ifneq ($(expr 1!=1),0)
+$(error sub-test 1 failed)
+endif
+ifneq ($(expr 2*2),4)
+$(error sub-test 1 failed)
+endif
+ifneq ($(expr 25*25),625)
+$(error sub-test 1 failed)
+endif
+
+.PHONY: all
+all: ; @:
+',
+'',
+'');
+
+}
+
+
+
+# Indicate that we're done.
+1;
+
+
diff --git a/src/kmk/tests/scripts/functions/file b/src/kmk/tests/scripts/functions/file
new file mode 100644
index 0000000..904db79
--- /dev/null
+++ b/src/kmk/tests/scripts/functions/file
@@ -0,0 +1,161 @@
+# -*-perl-*-
+
+$description = 'Test the $(file ...) function.';
+
+# Test > and >>
+run_make_test(q!
+define A
+a
+b
+endef
+B = c d
+$(file >file.out,$(A))
+$(foreach L,$(B),$(file >> file.out,$L))
+x:;@echo hi; cat file.out
+!,
+ '', "hi\na\nb\nc\nd");
+
+unlink('file.out');
+
+# Test >> to a non-existent file
+run_make_test(q!
+define A
+a
+b
+endef
+$(file >> file.out,$(A))
+x:;@cat file.out
+!,
+ '', "a\nb");
+
+unlink('file.out');
+
+# Test > with no content
+run_make_test(q!
+$(file >4touch)
+.PHONY:x
+x:;@cat 4touch
+!,
+ '', '');
+
+# Test >> with no content
+run_make_test(q!
+$(file >>4touch)
+.PHONY:x
+x:;@cat 4touch
+!,
+ '', '');
+unlink('4touch');
+
+# Test > to a read-only file
+touch('file.out');
+chmod(0444, 'file.out');
+
+# Find the error that will be printed
+# This seems complicated, but we need the message from the C locale
+my $loc = undef;
+if ($has_POSIX) {
+ $loc = POSIX::setlocale(POSIX::LC_MESSAGES);
+ POSIX::setlocale(POSIX::LC_MESSAGES, 'C');
+}
+my $e;
+open(my $F, '>', 'file.out') and die "Opened read-only file!\n";
+$e = "$!";
+$loc and POSIX::setlocale(POSIX::LC_MESSAGES, $loc);
+
+run_make_test(q!
+define A
+a
+b
+endef
+$(file > file.out,$(A))
+x:;@cat file.out
+!,
+ '', "#MAKEFILE#:6: *** open: file.out: $e. Stop.",
+ 512);
+
+unlink('file.out');
+
+# Use variables for operator and filename
+run_make_test(q!
+define A
+a
+b
+endef
+OP = >
+FN = file.out
+$(file $(OP) $(FN),$(A))
+x:;@cat file.out
+!,
+ '', "a\nb");
+
+unlink('file.out');
+
+# Don't add newlines if one already exists
+run_make_test(q!
+define A
+a
+b
+
+endef
+$(file >file.out,$(A))
+x:;@cat file.out
+!,
+ '', "a\nb");
+
+unlink('file.out');
+
+# Empty text
+run_make_test(q!
+$(file >file.out,)
+$(file >>file.out,)
+x:;@cat file.out
+!,
+ '', "\n\n");
+
+unlink('file.out');
+
+# Reading files
+run_make_test(q!
+$(file >file.out,A = foo)
+X1 := $(file <file.out)
+$(file >>file.out,B = bar)
+$(eval $(file <file.out))
+
+x:;@echo '$(X1)'; echo '$(A)'; echo '$(B)'
+!,
+ '', "A = foo\nfoo\nbar\n");
+
+unlink('file.out');
+
+# Reading from non-existent file
+run_make_test(q!
+X1 := $(file <file.out)
+x:;@echo '$(X1)';
+!,
+ '', "\n");
+
+# Extra arguments in read mode
+run_make_test(q!
+X1 := $(file <file.out,foo)
+x:;@echo '$(X1)';
+!,
+ '', "#MAKEFILE#:2: *** file: too many arguments. Stop.\n", 512);
+
+
+# Missing filename
+run_make_test('$(file >)', '',
+ "#MAKEFILE#:1: *** file: missing filename. Stop.\n", 512);
+
+run_make_test('$(file >>)', '',
+ "#MAKEFILE#:1: *** file: missing filename. Stop.\n", 512);
+
+run_make_test('$(file <)', '',
+ "#MAKEFILE#:1: *** file: missing filename. Stop.\n", 512);
+
+# Bad call
+
+run_make_test('$(file foo)', '',
+ "#MAKEFILE#:1: *** file: invalid file operation: foo. Stop.\n", 512);
+
+1;
diff --git a/src/kmk/tests/scripts/functions/filter-out b/src/kmk/tests/scripts/functions/filter-out
new file mode 100644
index 0000000..1fe4819
--- /dev/null
+++ b/src/kmk/tests/scripts/functions/filter-out
@@ -0,0 +1,42 @@
+# -*-perl-*-
+
+$description = "Test the filter and filter-out functions.";
+
+$details = "The makefile created in this test has two variables. The
+filter-out function is first used to discard names ending in
+.o with a single simple pattern. The second filter-out function
+augments the simple pattern with three literal names, which are
+also added to the text argument. This tests an internal hash table
+which is only used if there are multiple literals present in both
+the pattern and text arguments. The result of both filter-out
+functions is the same single .elc name.\n";
+
+# Basic test -- filter
+run_make_test(q!
+files1 := $(filter %.o, foo.elc bar.o lose.o)
+files2 := $(filter %.o foo.i, foo.i bar.i lose.i foo.elc bar.o lose.o)
+all: ; @echo '$(files1) $(files2)'
+!,
+ '', "bar.o lose.o foo.i bar.o lose.o\n");
+
+# Basic test -- filter-out
+run_make_test(q!
+files1 := $(filter-out %.o, foo.elc bar.o lose.o)
+files2 := $(filter-out foo.i bar.i lose.i %.o, foo.i bar.i lose.i foo.elc bar.o lose.o)
+all: ; @echo '$(files1) $(files2)'
+!,
+ '', "foo.elc foo.elc\n");
+
+# Escaped patterns
+run_make_test(q!all:;@echo '$(filter foo\%bar,foo%bar fooXbar)'!,
+ '', "foo%bar\n");
+
+run_make_test(q!all:;@echo '$(filter foo\%\%\\\\\%\%bar,foo%%\\%%bar fooX\\Ybar)'!,
+ '', "foo%%\\%%bar\n");
+
+run_make_test(q!
+X = $(filter foo\\\\\%bar,foo\%bar foo\Xbar)
+all:;@echo '$(X)'!,
+ '', "foo\\%bar\n");
+
+1;
diff --git a/src/kmk/tests/scripts/functions/findstring b/src/kmk/tests/scripts/functions/findstring
new file mode 100644
index 0000000..48abede
--- /dev/null
+++ b/src/kmk/tests/scripts/functions/findstring
@@ -0,0 +1,47 @@
+$description = "The following test creates a makefile to test the findstring "
+ ."function.";
+
+$details = "";
+
+# IF YOU NEED >1 MAKEFILE FOR THIS TEST, USE &get_tmpfile; TO GET
+# THE NAME OF THE MAKEFILE. THIS INSURES CONSISTENCY AND KEEPS TRACK OF
+# HOW MANY MAKEFILES EXIST FOR EASY DELETION AT THE END.
+# EXAMPLE: $makefile2 = &get_tmpfile;
+
+
+open(MAKEFILE,"> $makefile");
+
+# The Contents of the MAKEFILE ...
+
+print MAKEFILE "string := \$(findstring port, reporter)\n"
+ ."all: \n"
+ ."\t\@echo \$(string) \n";
+
+# END of Contents of MAKEFILE
+
+close(MAKEFILE);
+
+&run_make_with_options($makefile,
+ "",
+ &get_logfile,
+ 0);
+
+# Create the answer to what should be produced by this Makefile
+$answer = "port\n";
+
+# COMPARE RESULTS
+
+# In this call to compare output, you should use the call &get_logfile(1)
+# to send the name of the last logfile created. You may also use
+# the special call &get_logfile(1) which returns the same as &get_logfile(1).
+
+&compare_output($answer,&get_logfile(1));
+
+# This tells the test driver that the perl test script executed properly.
+1;
+
+
+
+
+
+
diff --git a/src/kmk/tests/scripts/functions/flavor b/src/kmk/tests/scripts/functions/flavor
new file mode 100644
index 0000000..80d6be7
--- /dev/null
+++ b/src/kmk/tests/scripts/functions/flavor
@@ -0,0 +1,44 @@
+# -*-perl-*-
+$description = "Test the flavor function.";
+
+$details = "";
+
+
+# Test #1: Test general logic.
+#
+run_make_test('
+s := s
+r = r
+
+$(info u $(flavor u))
+$(info s $(flavor s))
+$(info r $(flavor r))
+
+ra += ra
+rc ?= rc
+
+$(info ra $(flavor ra))
+$(info rc $(flavor rc))
+
+s += s
+r += r
+
+$(info s $(flavor s))
+$(info r $(flavor r))
+
+
+.PHONY: all
+all:;@:
+',
+'',
+'u undefined
+s simple
+r recursive
+ra recursive
+rc recursive
+s simple
+r recursive');
+
+
+# This tells the test driver that the perl test script executed properly.
+1;
diff --git a/src/kmk/tests/scripts/functions/for b/src/kmk/tests/scripts/functions/for
new file mode 100644
index 0000000..0152395
--- /dev/null
+++ b/src/kmk/tests/scripts/functions/for
@@ -0,0 +1,69 @@
+# $Id: for 2413 2010-09-11 17:43:04Z bird $ -*-perl-*-
+## @file
+# $(for init,condition,next,body)
+#
+
+#
+# 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 $(for ) loop function";
+
+$details = "A few simple tests, nothing spectacular.";
+
+if ($is_kmk) {
+
+ # TEST #0 - check that the feature is present.
+ # --------------------------------------------
+ run_make_test('
+ifneq ($(for local i=0, $i <= 10, local i := $(expr $i + 1),$i),0 1 2 3 4 5 6 7 8 9 10)
+$(error sub-test 0 failed:$(for local i=0, $i <= 10, local i := $(expr $i + 1),$i))
+endif
+
+.PHONY: all
+all: ; @:
+',
+'',
+'');
+
+ # TEST #1 - the real test.
+ # ------------------------
+ run_make_test('
+ifneq ($(for local i=0, $i <= 10, local i := $(expr $i + 1),$i),0 1 2 3 4 5 6 7 8 9 10)
+$(error sub-test 0 failed)
+endif
+ifneq (.$(for local i=0, $i <= 3, local i := $(expr $i + 1), $i ).,. 0 1 2 3 .)
+$(error sub-test 1 failed)
+endif
+ifneq (.$(foreach i,0 1 2 3, $i ).,. 0 1 2 3 .)
+$(error sub-test 1b failed)
+endif
+
+.PHONY: all
+all: ; @:
+',
+'',
+'');
+}
+
+
+
+# Indicate that we're done.
+1;
+
diff --git a/src/kmk/tests/scripts/functions/foreach b/src/kmk/tests/scripts/functions/foreach
new file mode 100644
index 0000000..88ef0a7
--- /dev/null
+++ b/src/kmk/tests/scripts/functions/foreach
@@ -0,0 +1,97 @@
+# -*-perl-*-
+# $Id$
+
+$description = "Test the foreach function.";
+
+$details = "This is a test of the foreach function in gnu make.
+This function starts with a space separated list of
+names and a variable. Each name in the list is subsituted
+into the variable and the given text evaluated. The general
+form of the command is $(foreach var,$list,$text). Several
+types of foreach loops are tested\n";
+
+
+# TEST 0
+
+# Set an environment variable that we can test in the makefile.
+# kmk: CC isn't a default.
+$extraENV{FOOFOO} = 'foo foo';
+$CC_origin = $is_kmk ? "undefined" : "default";
+
+run_make_test("space = ' '".'
+null :=
+auto_var = udef space CC null FOOFOO MAKE foo CFLAGS WHITE @ <
+foo = bletch null @ garf
+av = $(foreach var, $(auto_var), $(origin $(var)) )
+override WHITE := BLACK
+for_var = $(addsuffix .c,foo $(null) $(foo) $(space) $(av) )
+fe = $(foreach var2, $(for_var),$(subst .c,.o, $(var2) ) )
+all: auto for2
+auto : ; @echo $(av)
+for2: ; @echo $(fe)',
+ '-j1 -e WHITE=WHITE CFLAGS=',
+ "undefined file ". $CC_origin ." file environment default file command line override automatic automatic
+foo.o bletch.o null.o @.o garf.o .o .o undefined.o file.o ". $CC_origin .".o file.o environment.o default.o file.o command.o line.o override.o automatic.o automatic.o");
+
+delete $extraENV{FOOFOO};
+
+# TEST 1: Test that foreach variables take precedence over global
+# variables in a global scope (like inside an eval). Tests bug #11913
+
+run_make_test('
+.PHONY: all target
+all: target
+
+x := BAD
+
+define mktarget
+target: x := $(x)
+target: ; @echo "$(x)"
+endef
+
+x := GLOBAL
+
+$(foreach x,FOREACH,$(eval $(value mktarget)))',
+ '',
+ 'FOREACH');
+
+# Allow variable names with trailing space
+run_make_test(q!
+$(foreach \
+ a \
+, b c d \
+, $(info $a))
+all:;@:
+!,
+ "", "b\nc\nd\n");
+
+# Allow empty variable names. We still expand the body.
+
+run_make_test('
+x = $(foreach ,1 2 3,a)
+y := $x
+
+all: ; @echo $y',
+ '', "a a a\n");
+
+# Check some error conditions.
+
+run_make_test('
+x = $(foreach )
+y = $x
+
+all: ; @echo $y',
+ '',
+ "#MAKEFILE#:2: *** insufficient number of arguments (1) to function 'foreach'. Stop.",
+ 512);
+
+run_make_test('
+x = $(foreach x,y)
+y := $x
+
+all: ; @echo $y',
+ '',
+ "#MAKEFILE#:2: *** insufficient number of arguments (2) to function 'foreach'. Stop.",
+ 512);
+
+1;
diff --git a/src/kmk/tests/scripts/functions/guile b/src/kmk/tests/scripts/functions/guile
new file mode 100644
index 0000000..c63bec9
--- /dev/null
+++ b/src/kmk/tests/scripts/functions/guile
@@ -0,0 +1,99 @@
+# -*-perl-*-
+
+$description = 'Test the $(guile ...) function.';
+
+$details = 'This only works on systems that support it.';
+
+# If this instance of make doesn't support GNU Guile, skip it
+# This detects if guile is loaded using the "load" directive
+# $makefile = get_tmpfile();
+# open(MAKEFILE, "> $makefile") || die "Failed to open $makefile: $!\n";
+# print MAKEFILE q!
+# -load guile
+# all: ; @echo $(filter guile,$(.LOADED))
+# !;
+# close(MAKEFILE) || die "Failed to write $makefile: $!\n";
+# $cmd = subst_make_string("#MAKEPATH# -f $makefile");
+# $log = get_logfile(0);
+# $code = run_command_with_output($log, $cmd);
+# read_file_into_string ($log) eq "guile\n" and $FEATURES{guile} = 1;
+
+# If we don't have Guile support, never mind.
+exists $FEATURES{guile} or return -1;
+
+# Verify simple data type conversions
+# Currently we don't support vectors:
+# echo '$(guile (vector 1 2 3))'; \
+run_make_test(q!
+x:;@echo '$(guile #f)'; \
+ echo '$(guile #t)'; \
+ echo '$(guile #\c)'; \
+ echo '$(guile 1234)'; \
+ echo '$(guile 'foo)'; \
+ echo '$(guile "bar")'; \
+ echo '$(guile (cons 'a 'b))'; \
+ echo '$(guile '(a b (c . d) 1 (2) 3))'
+!,
+ '', "\n#t\nc\n1234\nfoo\nbar\na b\na b c d 1 2 3");
+
+# Verify the gmk-expand function
+run_make_test(q!
+VAR = $(guile (gmk-expand "$(shell echo hi)"))
+x:;@echo '$(VAR)'
+!,
+ '', "hi");
+
+# Verify the gmk-eval function
+# Prove that the string is expanded only once (by eval)
+run_make_test(q!
+TEST = bye
+EVAL = VAR = $(TEST) $(shell echo there)
+$(guile (gmk-eval "$(value EVAL)"))
+TEST = hi
+x:;@echo '$(VAR)'
+!,
+ '', "hi there");
+
+# Verify the gmk-eval function with a list
+run_make_test(q!
+$(guile (gmk-eval '(VAR = 1 (2) () 3)))
+x:;@echo '$(VAR)'
+!,
+ '', "1 2 3");
+
+# Verify the gmk-var function
+run_make_test(q!
+VALUE = hi $(shell echo there)
+VAR = $(guile (gmk-var "VALUE"))
+x:;@echo '$(VAR)'
+!,
+ '', "hi there");
+
+# Verify the gmk-var function with a symbol
+run_make_test(q!
+VALUE = hi $(shell echo there)
+VAR = $(guile (gmk-var 'VALUE))
+x:;@echo '$(VAR)'
+!,
+ '', "hi there");
+
+# Write a Guile program using define and run it
+run_make_test(q!
+# Define the "fib" function in Guile
+define fib
+;; A procedure for counting the n:th Fibonacci number
+;; See SICP, p. 37
+(define (fib n)
+ (cond ((= n 0) 0)
+ ((= n 1) 1)
+ (else (+ (fib (- n 1))
+ (fib (- n 2))))))
+endef
+$(guile $(fib))
+
+# Now run it
+x:;@echo $(guile (fib $(FIB)))
+!,
+ 'FIB=10', "55");
+
+1;
diff --git a/src/kmk/tests/scripts/functions/if b/src/kmk/tests/scripts/functions/if
new file mode 100644
index 0000000..8604e4f
--- /dev/null
+++ b/src/kmk/tests/scripts/functions/if
@@ -0,0 +1,33 @@
+# -*-perl-*-
+$description = "Test the if function.\n";
+
+$details = "Try various uses of if and ensure they all give the correct
+results.\n";
+
+open(MAKEFILE, "> $makefile");
+
+print MAKEFILE <<EOMAKE;
+NEQ = \$(subst \$1,,\$2)
+e =
+
+all:
+\t\@echo 1 \$(if ,true,false)
+\t\@echo 2 \$(if ,true,)
+\t\@echo 3 \$(if ,true)
+\t\@echo 4 \$(if z,true,false)
+\t\@echo 5 \$(if z,true,\$(shell echo hi))
+\t\@echo 6 \$(if ,\$(shell echo hi),false)
+\t\@echo 7 \$(if \$(call NEQ,a,b),true,false)
+\t\@echo 8 \$(if \$(call NEQ,a,a),true,false)
+\t\@echo 9 \$(if z,true,fal,se) hi
+\t\@echo 10 \$(if ,true,fal,se)there
+\t\@echo 11 \$(if \$(e) ,true,false)
+EOMAKE
+
+close(MAKEFILE);
+
+&run_make_with_options($makefile, "", &get_logfile);
+$answer = "1 false\n2\n3\n4 true\n5 true\n6 false\n7 true\n8 false\n9 true hi\n10 fal,sethere\n11 false\n";
+&compare_output($answer, &get_logfile(1));
+
+1;
diff --git a/src/kmk/tests/scripts/functions/if-expr b/src/kmk/tests/scripts/functions/if-expr
new file mode 100644
index 0000000..764522d
--- /dev/null
+++ b/src/kmk/tests/scripts/functions/if-expr
@@ -0,0 +1,84 @@
+# $Id: if-expr 2413 2010-09-11 17:43:04Z bird $ -*-perl-*-
+## @file
+# $(if-expr expr, if-expand, else-expand)
+#
+
+#
+# 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 \$(if-expr ) function";
+
+$details = "A few simple tests, nothing spectacular. More comprehensive testing
+is preformed by functions/expr and features/ifcond.";
+
+if ($is_kmk) {
+
+ # TEST #0 - check that the feature is present.
+ # --------------------------------------------
+ run_make_test('
+ifneq ($(if-expr 1+1,1,0),1)
+$(error sub-test 0 failed)
+endif
+.PHONY: all
+all: ; @:
+',
+'',
+'');
+
+ # TEST #1 - basics, the $(expr test checks the rest).
+ # ---------------------------------------------------
+ run_make_test('
+IF-EXPAND = 7
+ELSE-EXPAND = -7
+ifneq ($(if-expr 1==1,$(IF-EXPAND),$(ELSE-EXPAND)),7)
+$(error sub-test 0 failed)
+endif
+ifneq ($(if-expr 1!=1,$(IF-EXPAND),$(ELSE-EXPAND)),-7)
+$(error sub-test 1 failed)
+endif
+.PHONY: all
+all: ; @:
+',
+'',
+'');
+
+
+ # TEST #2 - Checks that the optional 3 argument can be omitted.
+ # -------------------------------------------------------------
+ run_make_test('
+ifneq ($(if-expr 1==1,true),true)
+$(error sub-test 0 failed)
+endif
+ifneq ($(if-expr 2==1,true),)
+$(error sub-test 0 failed)
+endif
+.PHONY: all
+all: ; @:
+',
+'',
+'');
+
+}
+
+
+
+# Indicate that we're done.
+1;
+
diff --git a/src/kmk/tests/scripts/functions/insert b/src/kmk/tests/scripts/functions/insert
new file mode 100644
index 0000000..6a597c6
--- /dev/null
+++ b/src/kmk/tests/scripts/functions/insert
@@ -0,0 +1,106 @@
+# $Id: insert 2413 2010-09-11 17:43:04Z bird $ -*-perl-*-
+## @file
+# $(insert in, str[, n[, length[, pad]]])
+#
+
+#
+# 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 $(insert ) function";
+
+$details = "Testing edges and some simple stuff.";
+
+if ($is_kmk) {
+
+ # TEST #0 - check that the feature is present.
+ # --------------------------------------------
+ run_make_test('
+ifneq ($(insert a,b),ab)
+$(error sub-test 0 failed)
+endif
+.PHONY: all
+all: ; @:
+',
+'',
+'');
+
+ # TEST #1 - the real test.
+ # ------------------------
+ run_make_test('
+ifneq ($(insert a,b,1),ab)
+$(error sub-test 0 failed)
+endif
+ifneq ($(insert a,b,2),ba)
+$(error sub-test 1 failed)
+endif
+ifneq ($(insert a,b,3),b a)
+$(error sub-test 2 failed)
+endif
+ifneq ($(insert a,b,0),ba)
+$(error sub-test 3 failed)
+endif
+ifneq ($(insert a,b,-1),ab)
+$(error sub-test 4 failed)
+endif
+ifneq ($(insert a,b,-2),ab)
+$(error sub-test 5 failed)
+endif
+ifneq ($(insert a,b,-10),ab)
+$(error sub-test 6 failed)
+endif
+
+ifneq ($(insert a,b,-10,0),b)
+$(error sub-test 10 failed)
+endif
+ifneq ($(insert aAAA,b,4,1),b a)
+$(error sub-test 11 failed)
+endif
+ifneq ($(insert a,bBbBbBb,4,4),bBba BbBb)
+$(error sub-test 12 failed)
+endif
+
+ifneq ($(insert a,bBbBbBb,4,4,z),bBbazzzBbBb)
+$(error sub-test 20 failed)
+endif
+ifneq ($(insert a,bBbBbBb,4,4,xy),bBbaxyxBbBb)
+$(error sub-test 21 failed)
+endif
+ifneq ($(insert a,bBbBbBb,4,4,xyz),bBbaxyzBbBb)
+$(error sub-test 22 failed)
+endif
+ifneq ($(insert a,bBbBbBb,4,4,xyzXYZ),bBbaxyzBbBb)
+$(error sub-test 23 failed)
+endif
+ifneq ($(insert a,bBbBbBb,4,4,),bBba BbBb)
+$(error sub-test 24 failed)
+endif
+
+.PHONY: all
+all: ; @:
+',
+'',
+'');
+}
+
+
+
+# Indicate that we're done.
+1;
+
diff --git a/src/kmk/tests/scripts/functions/intersects b/src/kmk/tests/scripts/functions/intersects
new file mode 100644
index 0000000..8d136fb
--- /dev/null
+++ b/src/kmk/tests/scripts/functions/intersects
@@ -0,0 +1,94 @@
+# $Id: intersects 2413 2010-09-11 17:43:04Z bird $ -*-perl-*-
+## @file
+# $(intersects set-a,set-b)
+#
+
+#
+# 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 $(intersecs ) predicate function";
+
+$details = "A few simple tests, nothing spectacular.";
+
+if ($is_kmk) {
+
+ # TEST #0 - check that the feature is present.
+ # --------------------------------------------
+ run_make_test('
+ifneq ($(intersects a b c d e f, a),1)
+$(error sub-test 0 failed)
+endif
+.PHONY: all
+all: ; @:
+',
+'',
+'');
+
+ # TEST #1 - the real test.
+ # ------------------------
+ run_make_test('
+ifneq ($(intersects a b c d e f, f),1)
+$(error sub-test 0 failed)
+endif
+ifneq ($(intersects a b c d e f, f),1)
+$(error sub-test 1 failed)
+endif
+ifneq ($(intersects a b c d e f, d),1)
+$(error sub-test 2 failed)
+endif
+ifneq ($(intersects b c d e f, a),)
+$(error sub-test 3 failed)
+endif
+ifneq ($(intersects a b c d e f, a b c d e f),1)
+$(error sub-test 4 failed)
+endif
+ifneq ($(intersects a b c d e f, f e d c b a),1)
+$(error sub-test 5 failed)
+endif
+ifneq ($(intersects f e d c b a, a b c d e f),1)
+$(error sub-test 6 failed)
+endif
+
+SET-A = make foo bar
+SET-B = $(SET-A)
+ifeq ($(intersects $(SET-A),$(SET-B)),)
+$(error sub-test 7 failed)
+endif
+SET-B = foo
+ifeq ($(intersects $(SET-A),$(SET-B)),)
+$(error sub-test 8 failed)
+endif
+SET-B = foobar
+ifneq ($(intersects $(SET-A),$(SET-B)),)
+$(error sub-test 9 failed)
+endif
+
+.PHONY: all
+all: ; @:
+',
+'',
+'');
+}
+
+
+
+# Indicate that we're done.
+1;
+
diff --git a/src/kmk/tests/scripts/functions/join b/src/kmk/tests/scripts/functions/join
new file mode 100644
index 0000000..302c307
--- /dev/null
+++ b/src/kmk/tests/scripts/functions/join
@@ -0,0 +1,44 @@
+$description = "The following test creates a makefile to test the join "
+ ."function.";
+
+$details = "";
+
+# IF YOU NEED >1 MAKEFILE FOR THIS TEST, USE &get_tmpfile; TO GET
+# THE NAME OF THE MAKEFILE. THIS INSURES CONSISTENCY AND KEEPS TRACK OF
+# HOW MANY MAKEFILES EXIST FOR EASY DELETION AT THE END.
+# EXAMPLE: $makefile2 = &get_tmpfile;
+
+
+open(MAKEFILE,"> $makefile");
+
+# The Contents of the MAKEFILE ...
+
+print MAKEFILE "string := \$(join a b c,foo hacks .pl1) \n"
+ ."all: \n"
+ ."\t\@echo \$(string) \n";
+
+# END of Contents of MAKEFILE
+
+close(MAKEFILE);
+
+&run_make_with_options($makefile,"",&get_logfile,0);
+
+# Create the answer to what should be produced by this Makefile
+$answer = "afoo bhacks c.pl1\n";
+
+# COMPARE RESULTS
+
+# In this call to compare output, you should use the call &get_logfile(1)
+# to send the name of the last logfile created. You may also use
+# the special call &get_logfile(1) which returns the same as &get_logfile(1).
+
+&compare_output($answer,&get_logfile(1));
+
+# This tells the test driver that the perl test script executed properly.
+1;
+
+
+
+
+
+
diff --git a/src/kmk/tests/scripts/functions/lastpos b/src/kmk/tests/scripts/functions/lastpos
new file mode 100644
index 0000000..248db2b
--- /dev/null
+++ b/src/kmk/tests/scripts/functions/lastpos
@@ -0,0 +1,118 @@
+# $Id: lastpos 2413 2010-09-11 17:43:04Z bird $ -*-perl-*-
+## @file
+# $(lastpos needle, haystack[, start])
+#
+
+#
+# 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 $(lastpos ) function";
+
+$details = "A few simple tests, nothing spectacular.";
+
+if ($is_kmk) {
+
+ # TEST #0 - check that the feature is present.
+ # --------------------------------------------
+ run_make_test('
+ifneq ($(lastpos b,abc),2)
+$(error sub-test 0 failed)
+endif
+.PHONY: all
+all: ; @:
+',
+'',
+'');
+
+ # TEST #1 - the real test.
+ # ------------------------
+ run_make_test('
+ifneq ($(lastpos t,abcdefghijklmnopqrstuvwxyz),20)
+$(error sub-test 0 failed)
+endif
+ifneq ($(lastpos tu,abcdefghijklmnopqrstuvwxyz),20)
+$(error sub-test 1 failed)
+endif
+ifneq ($(lastpos tuv,abcdefghijklmnopqrstuvwxyz),20)
+$(error sub-test 2 failed)
+endif
+ifneq ($(lastpos tuvw,abcdefghijklmnopqrstuvwxyz),20)
+$(error sub-test 3 failed)
+endif
+ifneq ($(lastpos tuvwx,abcdefghijklmnopqrstuvwxyz),20)
+$(error sub-test 4 failed)
+endif
+ifneq ($(lastpos tuvwxy,abcdefghijklmnopqrstuvwxyz),20)
+$(error sub-test 5 failed)
+endif
+ifneq ($(lastpos tuvwxyz,abcdefghijklmnopqrstuvwxyz),20)
+$(error sub-test 6 failed)
+endif
+ifneq ($(lastpos tuvwxyz!,abcdefghijklmnopqrstuvwxyz),0)
+$(error sub-test 7 failed)
+endif
+
+ifneq ($(lastpos a,ababababab),9)
+$(error sub-test 10 failed)
+endif
+ifneq ($(lastpos a,ababababab,8),7)
+$(error sub-test 11 failed)
+endif
+ifneq ($(lastpos a,ababababab,7),7)
+$(error sub-test 12 failed)
+endif
+ifneq ($(lastpos a,ababababab,4),3)
+$(error sub-test 13 failed)
+endif
+ifneq ($(lastpos a,ababababab,3),3)
+$(error sub-test 14 failed)
+endif
+ifneq ($(lastpos a,ababababab,2),1)
+$(error sub-test 15 failed)
+endif
+ifneq ($(lastpos a,ababababab,1),1)
+$(error sub-test 16 failed)
+endif
+ifneq ($(lastpos a,ababababab,-1),9)
+$(error sub-test 17 failed)
+endif
+ifneq ($(lastpos a,ababababab,-2),9)
+$(error sub-test 18 failed)
+endif
+ifneq ($(lastpos a,ababababab,-10),1)
+$(error sub-test 19 failed)
+endif
+ifneq ($(lastpos a,ababababab,-11),0)
+$(error sub-test 20 failed)
+endif
+
+
+.PHONY: all
+all: ; @:
+',
+'',
+'');
+}
+
+
+
+# Indicate that we're done.
+1;
+
diff --git a/src/kmk/tests/scripts/functions/length b/src/kmk/tests/scripts/functions/length
new file mode 100644
index 0000000..c8ea34d
--- /dev/null
+++ b/src/kmk/tests/scripts/functions/length
@@ -0,0 +1,71 @@
+# $Id: length 2413 2010-09-11 17:43:04Z bird $ -*-perl-*-
+## @file
+# $(length text)
+#
+
+#
+# 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 $(length ) function";
+
+$details = "A few simple tests, nothing spectacular.";
+
+if ($is_kmk) {
+
+ # TEST #0 - check that the feature is present.
+ # --------------------------------------------
+ run_make_test('
+ifneq ($(length abcd),4)
+$(error sub-test 0 failed)
+endif
+.PHONY: all
+all: ; @:
+',
+'',
+'');
+
+ # TEST #1 - the real test.
+ # ------------------------
+ run_make_test('
+ifneq ($(length asdf),4)
+$(error sub-test 0 failed)
+endif
+ifneq ($(length a),1)
+$(error sub-test 1 failed)
+endif
+ifneq ($(length 0123456789),10)
+$(error sub-test 2 failed)
+endif
+ifneq ($(length 0123456789 ),11)
+$(error sub-test 3 failed)
+endif
+
+.PHONY: all
+all: ; @:
+',
+'',
+'');
+}
+
+
+
+# Indicate that we're done.
+1;
+
diff --git a/src/kmk/tests/scripts/functions/length-var b/src/kmk/tests/scripts/functions/length-var
new file mode 100644
index 0000000..0583713
--- /dev/null
+++ b/src/kmk/tests/scripts/functions/length-var
@@ -0,0 +1,75 @@
+# $Id: length-var 2413 2010-09-11 17:43:04Z bird $ -*-perl-*-
+## @file
+# $(length-var var)
+#
+
+#
+# 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 $(length-var ) function";
+
+$details = "A few simple tests, nothing spectacular.";
+
+if ($is_kmk) {
+
+ # TEST #0 - check that the feature is present.
+ # --------------------------------------------
+ run_make_test('
+ifneq ($(length-var non-existing-variable),0)
+$(error sub-test 0 failed)
+endif
+.PHONY: all
+all: ; @:
+',
+'',
+'');
+
+ # TEST #1 - the real test.
+ # ------------------------
+ run_make_test('
+VAR0 := asdf
+ifneq ($(length-var VAR0),4)
+$(error sub-test 0 failed)
+endif
+VAR1 = a
+ifneq ($(length-var VAR1),1)
+$(error sub-test 1 failed)
+endif
+VAR2 = 0123456789
+ifneq ($(length-var VAR2),10)
+$(error sub-test 2 failed)
+endif
+VAR2 = $(VAR1) $(VAR0)
+ifneq ($(length-var VAR2),15)
+$(error sub-test 3 failed)
+endif
+
+.PHONY: all
+all: ; @:
+',
+'',
+'');
+}
+
+
+
+# Indicate that we're done.
+1;
+
diff --git a/src/kmk/tests/scripts/functions/notdir b/src/kmk/tests/scripts/functions/notdir
new file mode 100644
index 0000000..4ed8f9c
--- /dev/null
+++ b/src/kmk/tests/scripts/functions/notdir
@@ -0,0 +1,44 @@
+$description = "The following test creates a makefile to test the notdir "
+ ."function.";
+
+$details = "";
+
+# IF YOU NEED >1 MAKEFILE FOR THIS TEST, USE &get_tmpfile; TO GET
+# THE NAME OF THE MAKEFILE. THIS INSURES CONSISTENCY AND KEEPS TRACK OF
+# HOW MANY MAKEFILES EXIST FOR EASY DELETION AT THE END.
+# EXAMPLE: $makefile2 = &get_tmpfile;
+
+
+open(MAKEFILE,"> $makefile");
+
+# The Contents of the MAKEFILE ...
+
+print MAKEFILE "string := \$(notdir ${pathsep}src${pathsep}foo.c hacks) \n"
+ ."all: \n"
+ ."\t\@echo \$(string) \n";
+
+# END of Contents of MAKEFILE
+
+close(MAKEFILE);
+
+&run_make_with_options($makefile,"",&get_logfile,0);
+
+# Create the answer to what should be produced by this Makefile
+$answer = "foo.c hacks\n";
+
+# COMPARE RESULTS
+
+# In this call to compare output, you should use the call &get_logfile(1)
+# to send the name of the last logfile created. You may also use
+# the special call &get_logfile(1) which returns the same as &get_logfile(1).
+
+&compare_output($answer,&get_logfile(1));
+
+# This tells the test driver that the perl test script executed properly.
+1;
+
+
+
+
+
+
diff --git a/src/kmk/tests/scripts/functions/origin b/src/kmk/tests/scripts/functions/origin
new file mode 100644
index 0000000..7a6a9fa
--- /dev/null
+++ b/src/kmk/tests/scripts/functions/origin
@@ -0,0 +1,54 @@
+# -*-perl-*-
+
+$description = "Test the origin function.";
+
+$details = "This is a test of the origin function in gnu make.
+This function will report on where a variable was
+defined per the following list:
+
+'undefined' never defined
+'default' default definition
+'environment' environment var without -e
+'environment override' environment var with -e
+'file' defined in makefile
+'command line' defined on the command line
+'override' defined by override in makefile
+'automatic' Automatic variable\n";
+
+# kmk: CC isn't a default.
+$CC_origin = $is_kmk ? "undefined" : "default";
+
+# Set an environment variable
+$extraENV{MAKETEST} = 1;
+
+run_make_test('
+foo := bletch garf
+auto_var = undefined CC MAKETEST MAKE foo CFLAGS WHITE @
+av = $(foreach var, $(auto_var), $(origin $(var)) )
+override WHITE := BLACK
+all: auto
+ @echo $(origin undefined)
+ @echo $(origin CC)
+ @echo $(origin MAKETEST)
+ @echo $(origin MAKE)
+ @echo $(origin foo)
+ @echo $(origin CFLAGS)
+ @echo $(origin WHITE)
+ @echo $(origin @)
+auto :
+ @echo $(av)',
+ '-e WHITE=WHITE CFLAGS=',
+ 'undefined '. $CC_origin .' environment default file command line override automatic
+undefined
+'. $CC_origin .'
+environment
+default
+file
+command line
+override
+automatic');
+
+# Reset an environment variable
+delete $extraENV{MAKETEST};
+
+1;
diff --git a/src/kmk/tests/scripts/functions/pos b/src/kmk/tests/scripts/functions/pos
new file mode 100644
index 0000000..bdc3d40
--- /dev/null
+++ b/src/kmk/tests/scripts/functions/pos
@@ -0,0 +1,118 @@
+# $Id: pos 2413 2010-09-11 17:43:04Z bird $ -*-perl-*-
+## @file
+# $(pos needle, haystack[, start])
+#
+
+#
+# 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 $(pos ) function";
+
+$details = "A few simple tests, nothing spectacular.";
+
+if ($is_kmk) {
+
+ # TEST #0 - check that the feature is present.
+ # --------------------------------------------
+ run_make_test('
+ifneq ($(pos b,abc),2)
+$(error sub-test 0 failed)
+endif
+.PHONY: all
+all: ; @:
+',
+'',
+'');
+
+ # TEST #1 - the real test.
+ # ------------------------
+ run_make_test('
+ifneq ($(pos t,abcdefghijklmnopqrstuvwxyz),20)
+$(error sub-test 0 failed)
+endif
+ifneq ($(pos tu,abcdefghijklmnopqrstuvwxyz),20)
+$(error sub-test 1 failed)
+endif
+ifneq ($(pos tuv,abcdefghijklmnopqrstuvwxyz),20)
+$(error sub-test 2 failed)
+endif
+ifneq ($(pos tuvw,abcdefghijklmnopqrstuvwxyz),20)
+$(error sub-test 3 failed)
+endif
+ifneq ($(pos tuvwx,abcdefghijklmnopqrstuvwxyz),20)
+$(error sub-test 4 failed)
+endif
+ifneq ($(pos tuvwxy,abcdefghijklmnopqrstuvwxyz),20)
+$(error sub-test 5 failed)
+endif
+ifneq ($(pos tuvwxyz,abcdefghijklmnopqrstuvwxyz),20)
+$(error sub-test 6 failed)
+endif
+ifneq ($(pos tuvwxyz!,abcdefghijklmnopqrstuvwxyz),0)
+$(error sub-test 7 failed)
+endif
+
+ifneq ($(pos a,ababababab),1)
+$(error sub-test 10 failed)
+endif
+ifneq ($(pos a,ababababab,2),3)
+$(error sub-test 11 failed)
+endif
+ifneq ($(pos a,ababababab,3),3)
+$(error sub-test 12 failed)
+endif
+ifneq ($(pos a,ababababab,8),9)
+$(error sub-test 13 failed)
+endif
+ifneq ($(pos a,ababababab,8),9)
+$(error sub-test 14 failed)
+endif
+ifneq ($(pos a,ababababab,9),9)
+$(error sub-test 15 failed)
+endif
+ifneq ($(pos a,ababababab,10),0)
+$(error sub-test 16 failed)
+endif
+ifneq ($(pos a,ababababab,-1),0)
+$(error sub-test 17 failed)
+endif
+ifneq ($(pos a,ababababab,-2),9)
+$(error sub-test 18 failed)
+endif
+ifneq ($(pos a,ababababab,-10),1)
+$(error sub-test 19 failed)
+endif
+ifneq ($(pos a,ababababab,-11),0)
+$(error sub-test 20 failed)
+endif
+
+
+.PHONY: all
+all: ; @:
+',
+'',
+'');
+}
+
+
+
+# Indicate that we're done.
+1;
+
diff --git a/src/kmk/tests/scripts/functions/printf b/src/kmk/tests/scripts/functions/printf
new file mode 100644
index 0000000..cb20168
--- /dev/null
+++ b/src/kmk/tests/scripts/functions/printf
@@ -0,0 +1,80 @@
+# $Id: printf 2413 2010-09-11 17:43:04Z bird $ -*-perl-*-
+## @file
+# $(printf fmt[,args...])
+#
+
+#
+# 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 $(printf ) function";
+
+$details = "A few simple tests, nothing spectacular.";
+
+if ($is_kmk) {
+
+ # TEST #0 - check that the feature is present.
+ # --------------------------------------------
+ run_make_test('
+ifneq ($(printf abcd),abcd)
+$(error sub-test 0 failed)
+endif
+.PHONY: all
+all: ; @:
+',
+'',
+'');
+
+ # TEST #1 - the real test.
+ # ------------------------
+ run_make_test('
+ifneq ($(printf %s,abcde),abcde)
+$(error sub-test 0 failed)
+endif
+ifneq ($(printf %.4s,abcde),abcd)
+$(error sub-test 1 failed)
+endif
+ifneq ($(printf %.8s,abc),abc)
+$(error sub-test 2 failed)
+endif
+ifneq ($(printf %.2s%.3s,abc,zde),abzde)
+$(error sub-test 3 failed)
+endif
+define HASH
+#
+endef
+ifneq ($(printf %$(HASH)x,127),0x7f)
+$(error sub-test 4 failed)
+endif
+ifneq ($(printf %$(HASH)X,127),0X7F)
+$(error sub-test 5 failed)
+endif
+
+.PHONY: all
+all: ; @:
+',
+'',
+'');
+}
+
+
+
+# Indicate that we're done.
+1;
+
diff --git a/src/kmk/tests/scripts/functions/realpath b/src/kmk/tests/scripts/functions/realpath
new file mode 100644
index 0000000..9b503b4
--- /dev/null
+++ b/src/kmk/tests/scripts/functions/realpath
@@ -0,0 +1,82 @@
+# -*-perl-*-
+$description = "Test the realpath functions.";
+
+$details = "";
+
+run_make_test('
+ifneq ($(realpath .),$(CURDIR))
+ $(error )
+endif
+
+ifneq ($(realpath ./),$(CURDIR))
+ $(error )
+endif
+
+ifneq ($(realpath .///),$(CURDIR))
+ $(error )
+endif
+
+ifneq ($(realpath /),/)
+ $(error )
+endif
+
+ifneq ($(realpath /.),/)
+ $(error )
+endif
+
+ifneq ($(realpath /./),/)
+ $(error )
+endif
+
+ifneq ($(realpath /.///),/)
+ $(error )
+endif
+
+ifneq ($(realpath /..),/)
+ $(error )
+endif
+
+ifneq ($(realpath /../),/)
+ $(error )
+endif
+
+ifneq ($(realpath /..///),/)
+ $(error )
+endif
+
+ifneq ($(realpath . /..),$(CURDIR) /)
+ $(error )
+endif
+
+.PHONY: all
+all: ; @:
+',
+ '',
+ '');
+
+# On Windows platforms, "//" means something special. So, don't do these
+# tests there.
+
+if ($port_type ne 'W32') {
+ run_make_test('
+ifneq ($(realpath ///),/)
+ $(error )
+endif
+
+ifneq ($(realpath ///.),/)
+ $(error )
+endif
+
+ifneq ($(realpath ///..),/)
+ $(error )
+endif
+
+.PHONY: all
+all: ; @:',
+ '',
+ '');
+}
+
+
+# This tells the test driver that the perl test script executed properly.
+1;
diff --git a/src/kmk/tests/scripts/functions/root b/src/kmk/tests/scripts/functions/root
new file mode 100644
index 0000000..46abbd1
--- /dev/null
+++ b/src/kmk/tests/scripts/functions/root
@@ -0,0 +1,172 @@
+# $Id: root 2413 2010-09-11 17:43:04Z bird $ -*-perl-*-
+## @file
+# $(root path...)
+#
+
+#
+# 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 $(path ) function";
+
+$details = "Testing edges and some simple stuff.";
+
+if ($is_kmk) {
+
+ # TEST #0 - check that the feature is present.
+ # --------------------------------------------
+ run_make_test('
+ifneq ($(root /a),/)
+$(error sub-test 0 failed)
+endif
+.PHONY: all
+all: ; @:
+',
+'',
+'');
+
+ # TEST #1 - the real test.
+ # ------------------------
+ run_make_test('
+ifneq ($(root /asdf/asdf/adsf),/)
+$(error sub-test 0 failed:$(root /asdf/asdf/adsf))
+endif
+ifneq ($(root asdf/asdf/adsf),)
+$(error sub-test 1 failed)
+endif
+ifneq ($(root asdf/asdf/adsf/),)
+$(error sub-test 2 failed)
+endif
+ifneq ($(root asdf/asdf/adsf/),)
+$(error sub-test 3 failed)
+endif
+ifneq ($(root a),)
+$(error sub-test 4 failed)
+endif
+ifneq ($(root ),)
+$(error sub-test 5 failed)
+endif
+ifneq ($(root //a),//)
+$(error sub-test 6 failed)
+endif
+ifneq ($(root /a),/)
+$(error sub-test 7 failed)
+endif
+ifneq ($(root ///a),///)
+$(error sub-test 8 failed)
+endif
+ifneq ($(root /a /b /c d /e),/ / / /)
+$(error sub-test 9 failed)
+endif
+
+.PHONY: all
+all: ; @:
+',
+'',
+'');
+
+
+ # TEST #2 - DOS PATH stuff.
+ # ------------------------
+ if ($port_type eq 'W32' || $port_type eq 'OS/2' || $port_type eq 'DOS') {
+ run_make_test('
+ifneq ($(root D:),D:)
+$(error sub-test 0 failed)
+endif
+ifneq ($(root D:/),D:/)
+$(error sub-test 1 failed)
+endif
+ifneq ($(root D:\\),D:\\)
+$(error sub-test 2 failed)
+endif
+ifneq ($(root D:\\\\),D:\\\\)
+$(error sub-test 3 failed)
+endif
+ifneq ($(root D:\\\\a),D:\\\\)
+$(error sub-test 4 failed)
+endif
+ifneq ($(root D:\\/a),D:\\/)
+$(error sub-test 5 failed)
+endif
+ifneq ($(root a:\\\\//asdf/asdf\\asdf),a:\\\\//)
+$(error sub-test 6 failed)
+endif
+ifneq ($(root z://\\\\asdf/asdf\\asdf),z://\\\\)
+$(error sub-test 7 failed)
+endif
+
+.PHONY: all
+all: ; @:
+',
+'',
+'');
+ }
+
+ # TEST #3 - UNC PATH stuff.
+ # ------------------------
+ if ($port_type eq 'W32' || $port_type eq 'OS/2') {
+ run_make_test('
+ifneq ($(root //./),//./)
+$(error sub-test 0 failed)
+endif
+ifneq ($(root \\\\.\\),\\\\.\\)
+$(error sub-test 1 failed)
+endif
+ifneq ($(root \\\\\\.\\),\\\\\\)
+$(error sub-test 2 failed)
+endif
+ifneq ($(root ///.\\),///)
+$(error sub-test 3 failed)
+endif
+ifneq ($(root /\\.\\),/\\.\\)
+$(error sub-test 4 failed)
+endif
+ifneq ($(root \\/.\\),\\/.\\)
+$(error sub-test 5 failed)
+endif
+ifneq ($(root //srv/),//srv/)
+$(error sub-test 6 failed)
+endif
+ifneq ($(root //srv),)
+$(error sub-test 7 failed)
+endif
+ifneq ($(root //srv/share),//srv/share)
+$(error sub-test 8 failed)
+endif
+ifneq ($(root //srv/share/),//srv/share/)
+$(error sub-test 9 failed)
+endif
+ifneq ($(root //srv/share/asdf),//srv/share/)
+$(error sub-test 10 failed)
+endif
+
+.PHONY: all
+all: ; @:
+',
+'',
+'');
+ }
+
+}
+
+
+
+# Indicate that we're done.
+1;
+
diff --git a/src/kmk/tests/scripts/functions/select b/src/kmk/tests/scripts/functions/select
new file mode 100644
index 0000000..843ff2e
--- /dev/null
+++ b/src/kmk/tests/scripts/functions/select
@@ -0,0 +1,96 @@
+# $Id: select 2413 2010-09-11 17:43:04Z bird $ -*-perl-*-
+## @file
+# $(select when1-cond, when1-body[,whenN-cond, whenN-body])
+#
+
+#
+# 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 $(select ) conditional function";
+
+$details = "A few simple tests, nothing spectacular.";
+
+if ($is_kmk) {
+
+ # TEST #0 - check that the feature is present.
+ # --------------------------------------------
+ run_make_test('
+ifneq ($(select 0,failed,1,success),success)
+$(error sub-test 0 failed)
+endif
+
+.PHONY: all
+all: ; @:
+',
+'',
+'');
+
+ # TEST #1 - the real test.
+ # ------------------------
+ run_make_test('
+
+ifneq ($(select 0,failed,1-1,failed2,otherwise,success),success)
+$(error sub-test 0 failed)
+endif
+ifneq ($(select 0,failed,1-1,failed2,otherwise:,success),success)
+$(error sub-test 1 failed)
+endif
+ifneq ($(select 0,failed,1-1,failed2, otherwise:,success),success)
+$(error sub-test 2 failed)
+endif
+ifneq ($(select 0,failed,1-1,failed2, otherwise: ,success),success)
+$(error sub-test 3 failed)
+endif
+ifneq ($(select 0,failed,1-1,failed2, otherwise : ,success),success)
+$(error sub-test 4 failed)
+endif
+ifneq ($(select 0,failed,1-1,failed2, default: ,success),success)
+$(error sub-test 5 failed)
+endif
+ifneq ($(select 0,failed,1-1,failed2,default,success),success)
+$(error sub-test 6 failed)
+endif
+
+ifneq ($(select 0,failed),)
+$(error sub-test 10 failed)
+endif
+ifneq ($(select 1,works),works)
+$(error sub-test 11 failed)
+endif
+ifneq ($(select 0,failed,1,success,1,failed3,otherwise,failed4),success)
+$(error sub-test 12 failed)
+endif
+
+
+.PHONY: all
+all: ; @:
+',
+'',
+'');
+}
+
+
+
+# Indicate that we're done.
+1;
+
+
+
+
diff --git a/src/kmk/tests/scripts/functions/shell b/src/kmk/tests/scripts/functions/shell
new file mode 100644
index 0000000..809c77f
--- /dev/null
+++ b/src/kmk/tests/scripts/functions/shell
@@ -0,0 +1,60 @@
+# -*-perl-*-
+
+$description = 'Test the $(shell ...) function.';
+
+$details = '';
+
+# Test standard shell
+run_make_test('.PHONY: all
+OUT := $(shell echo hi)
+all: ; @echo $(OUT)
+ ','','hi');
+
+# Test shells inside rules.
+run_make_test('.PHONY: all
+all: ; @echo $(shell echo hi)
+ ','','hi');
+
+# Verify .SHELLSTATUS
+run_make_test('.PHONY: all
+PRE := $(.SHELLSTATUS)
+$(shell exit 0)
+OK := $(.SHELLSTATUS)
+$(shell exit 1)
+BAD := $(.SHELLSTATUS)
+all: ; @echo PRE=$(PRE) OK=$(OK) BAD=$(BAD)
+ ','','PRE= OK=0 BAD=1');
+
+
+# Test unescaped comment characters in shells. Savannah bug #20513
+if ($all_tests) {
+ run_make_test(q!
+FOO := $(shell echo '#')
+foo: ; echo '$(FOO)'
+!,
+ '', "#\n");
+}
+
+# Test shells inside exported environment variables.
+# This is the test that fails if we try to put make exported variables into
+# the environment for a $(shell ...) call.
+run_make_test('
+export HI = $(shell echo hi)
+.PHONY: all
+all: ; @echo $$HI
+ ','','hi');
+
+# Test shell errors in recipes including offset
+run_make_test('
+all:
+ @echo hi
+ $(shell ./basdfdfsed there)
+ @echo there
+',
+ '', "#MAKE#: ./basdfdfsed: Command not found\nhi\nthere\n");
+
+1;
+
+### Local Variables:
+### eval: (setq whitespace-action (delq 'auto-cleanup whitespace-action))
+### End:
diff --git a/src/kmk/tests/scripts/functions/sort b/src/kmk/tests/scripts/functions/sort
new file mode 100644
index 0000000..e6e1343
--- /dev/null
+++ b/src/kmk/tests/scripts/functions/sort
@@ -0,0 +1,51 @@
+# -*-perl-*-
+
+$description = "The following test creates a makefile to verify
+the ability of make to sort lists of object. Sort
+will also remove any duplicate entries. This will also
+be tested.";
+
+$details = "The make file is built with a list of object in a random order
+and includes some duplicates. Make should sort all of the elements
+remove all duplicates\n";
+
+run_make_test('
+foo := moon_light days
+foo1:= jazz
+bar := captured
+bar2 = boy end, has rise A midnight
+bar3:= $(foo)
+s1 := _by
+s2 := _and_a
+t1 := $(addsuffix $(s1), $(bar) )
+t2 := $(addsuffix $(s2), $(foo1) )
+t3 := $(t2) $(t2) $(t2) $(t2) $(t2) $(t2) $(t2) $(t2) $(t2) $(t2)
+t4 := $(t3) $(t3) $(t3) $(t3) $(t3) $(t3) $(t3) $(t3) $(t3) $(t3)
+t5 := $(t4) $(t4) $(t4) $(t4) $(t4) $(t4) $(t4) $(t4) $(t4) $(t4)
+t6 := $(t5) $(t5) $(t5) $(t5) $(t5) $(t5) $(t5) $(t5) $(t5) $(t5)
+t7 := $(t6) $(t6) $(t6)
+p1 := $(addprefix $(foo1), $(s2) )
+blank:=
+all:
+ @echo $(sort $(bar2) $(foo) $(addsuffix $(s1), $(bar) ) $(t2) $(bar2) $(bar3))
+ @echo $(sort $(blank) $(foo) $(bar2) $(t1) $(p1) )
+ @echo $(sort $(foo) $(bar2) $(t1) $(t4) $(t5) $(t7) $(t6) )
+',
+ '', 'A boy captured_by days end, has jazz_and_a midnight moon_light rise
+A boy captured_by days end, has jazz_and_a midnight moon_light rise
+A boy captured_by days end, has jazz_and_a midnight moon_light rise
+');
+
+
+# Test with non-space/tab whitespace. Note that you can't see the
+# original bug except using valgrind.
+
+run_make_test("FOO = a b\tc\rd\fe \f \f \f \f \ff
+all: ; \@echo \$(words \$(sort \$(FOO)))\n",
+ '', "6\n");
+
+1;
+
+### Local Variables:
+### eval: (setq whitespace-action (delq 'auto-cleanup whitespace-action))
+### End:
diff --git a/src/kmk/tests/scripts/functions/strip b/src/kmk/tests/scripts/functions/strip
new file mode 100644
index 0000000..8222433
--- /dev/null
+++ b/src/kmk/tests/scripts/functions/strip
@@ -0,0 +1,57 @@
+# -*-perl-*-
+$description = "The following test creates a makefile to verify
+the ability of make to strip white space from lists of object.\n";
+
+
+$details = "The make file is built with a list of objects that contain white space
+These are then run through the strip command to remove it. This is then
+verified by echoing the result.\n";
+
+open(MAKEFILE,"> $makefile");
+
+# The Contents of the MAKEFILE ...
+
+print MAKEFILE <<'EOMAKE';
+TEST1 := "Is this TERMINAL fun? What makes you believe is this terminal fun? JAPAN is a WONDERFUL planet -- I wonder if we will ever reach their level of COMPARATIVE SHOPPING..."
+E :=
+TEST2 := $E try this and this $E
+
+define TEST3
+
+and these test out
+
+
+some
+blank lines
+
+
+
+endef
+
+.PHONY: all
+all:
+ @echo '$(strip $(TEST1) )'
+ @echo '$(strip $(TEST2) )'
+ @echo '$(strip $(TEST3) )'
+
+space: ; @echo '$(strip ) $(strip )'
+
+EOMAKE
+
+# END of Contents of MAKEFILE
+
+close(MAKEFILE);
+
+&run_make_with_options($makefile,"",&get_logfile);
+$answer = "\"Is this TERMINAL fun? What makes you believe is this terminal fun? JAPAN is a WONDERFUL planet -- I wonder if we will ever reach their level of COMPARATIVE SHOPPING...\"
+try this and this
+and these test out some blank lines
+";
+&compare_output($answer,&get_logfile(1));
+
+
+&run_make_with_options($makefile,"space",&get_logfile);
+$answer = " \n";
+&compare_output($answer,&get_logfile(1));
+
+1;
diff --git a/src/kmk/tests/scripts/functions/substitution b/src/kmk/tests/scripts/functions/substitution
new file mode 100644
index 0000000..0d2f6a2
--- /dev/null
+++ b/src/kmk/tests/scripts/functions/substitution
@@ -0,0 +1,38 @@
+# -*-perl-*-
+
+$description = "Test the subst and patsubst functions";
+
+$details = "";
+
+# Generic patsubst test: test both the function and variable form.
+
+run_make_test('
+foo := a.o b.o c.o
+bar := $(foo:.o=.c)
+bar2:= $(foo:%.o=%.c)
+bar3:= $(patsubst %.c,%.o,x.c.c bar.c)
+all:;@echo $(bar); echo $(bar2); echo $(bar3)',
+'',
+'a.c b.c c.c
+a.c b.c c.c
+x.c.o bar.o');
+
+# Patsubst without '%'--shouldn't match because the whole word has to match
+# in patsubst. Based on a bug report by Markus Mauhart <qwe123@chello.at>
+
+run_make_test('all:;@echo $(patsubst Foo,Repl,FooFoo)', '', 'FooFoo');
+
+# Variable subst where a pattern matches multiple times in a single word.
+# Based on a bug report by Markus Mauhart <qwe123@chello.at>
+
+run_make_test('
+A := fooBARfooBARfoo
+all:;@echo $(A:fooBARfoo=REPL)', '', 'fooBARREPL');
+
+1;
+
+
+
+
+
+
diff --git a/src/kmk/tests/scripts/functions/substr b/src/kmk/tests/scripts/functions/substr
new file mode 100644
index 0000000..bf0eba9
--- /dev/null
+++ b/src/kmk/tests/scripts/functions/substr
@@ -0,0 +1,125 @@
+# $Id: substr 2413 2010-09-11 17:43:04Z bird $ -*-perl-*-
+## @file
+# $(substr str, start[, length[, pad]])
+#
+
+#
+# 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 $(substr ) function";
+
+$details = "A few simple tests and edge cases.";
+
+if ($is_kmk) {
+
+ # TEST #0 - check that the feature is present.
+ # --------------------------------------------
+ run_make_test('
+ifneq ($(substr asdf,4),f)
+$(error sub-test 0 failed)
+endif
+.PHONY: all
+all: ; @:
+',
+'',
+'');
+
+ # TEST #1 - the real test.
+ # ------------------------
+ run_make_test('
+ifneq ($(substr abcdefghijklmnopqrstuvwxyz,20),tuvwxyz)
+$(error sub-test 0 failed)
+endif
+ifneq ($(substr abcdefghijklmnopqrstuvwxyz,20,1),t)
+$(error sub-test 1 failed)
+endif
+ifneq ($(substr abcdefghijklmnopqrstuvwxyz,20,2),tu)
+$(error sub-test 2 failed)
+endif
+ifneq ($(substr abcdefghijklmnopqrstuvwxyz,20,0),)
+$(error sub-test 3 failed)
+endif
+ifneq ($(substr abcdefghijklmnopqrstuvwxyz,-1),z)
+$(error sub-test 4 failed)
+endif
+ifneq ($(substr abcdefghijklmnopqrstuvwxyz,-2),yz)
+$(error sub-test 5 failed)
+endif
+ifneq ($(substr abcdefghijklmnopqrstuvwxyz,-2,2),yz)
+$(error sub-test 6 failed)
+endif
+ifneq ($(substr abcdefghijklmnopqrstuvwxyz,-2,3),yz)
+$(error sub-test 7 failed)
+endif
+ifneq ($(substr abcdefghijklmnopqrstuvwxyz,-2,5,XYZ),yzXYZ)
+$(error sub-test 8 failed)
+endif
+ifneq ($(substr abcdefghijklmnopqrstuvwxyz,-25,1),b)
+$(error sub-test 9 failed)
+endif
+ifneq ($(substr abcdefghijklmnopqrstuvwxyz,-26,1),a)
+$(error sub-test 10 failed)
+endif
+ifneq ($(substr abcdefghijklmnopqrstuvwxyz,-27,1),)
+$(error sub-test 11 failed)
+endif
+ifneq ($(substr abcdefghijklmnopqrstuvwxyz,-27,2),a)
+$(error sub-test 12 failed)
+endif
+ifneq ($(substr abcdefghijklmnopqrstuvwxyz,-27,3),ab)
+$(error sub-test 13 failed)
+endif
+ifneq ($(substr abcdefghijklmnopqrstuvwxyz,-27,3,_),_ab)
+$(error sub-test 14 failed)
+endif
+ifneq ($(substr abcdefghijklmnopqrstuvwxyz,-28,4,.^),.^ab)
+$(error sub-test 15 failed)
+endif
+ifneq ($(substr abcdefghijklmnopqrstuvwxyz,-50,4),)
+$(error sub-test 16 failed)
+endif
+ifneq ($(substr abcdefghijklmnopqrstuvwxyz,-50,4,.^),.^.^)
+$(error sub-test 17 failed)
+endif
+ifneq ($(substr abcdefghijklmnopqrstuvwxyz,27,4,.^),.^.^)
+$(error sub-test 18 failed)
+endif
+ifneq ($(substr abcdefghijklmnopqrstuvwxyz,28,3,.^),.^.)
+$(error sub-test 19 failed)
+endif
+SP := $(subst ., ,.)
+ifneq (.$(substr abcdefghijklmnopqrstuvwxyz,100,3, ).,. .)
+$(error sub-test 20 failed)
+endif
+ifneq ($(substr abcdefghijklmnopqrstuvwxyz,100,3, ),$(SP)$(SP)$(SP))
+$(error sub-test 21 failed)
+endif
+
+.PHONY: all
+all: ; @:
+',
+'',
+'');
+}
+
+
+# Indicate that we're done.
+1;
+
diff --git a/src/kmk/tests/scripts/functions/suffix b/src/kmk/tests/scripts/functions/suffix
new file mode 100644
index 0000000..0c4f919
--- /dev/null
+++ b/src/kmk/tests/scripts/functions/suffix
@@ -0,0 +1,57 @@
+$description = "The following test creates a makefile to test the suffix\n"
+ ."function. \n";
+
+$details = "The suffix function will return the string following the last _._\n"
+ ."the list provided. It will provide all of the unique suffixes found\n"
+ ."in the list. The long strings are sorted to remove duplicates.\n";
+
+# IF YOU NEED >1 MAKEFILE FOR THIS TEST, USE &get_tmpfile; TO GET
+# THE NAME OF THE MAKEFILE. THIS INSURES CONSISTENCY AND KEEPS TRACK OF
+# HOW MANY MAKEFILES EXIST FOR EASY DELETION AT THE END.
+# EXAMPLE: $makefile2 = &get_tmpfile;
+
+
+open(MAKEFILE,"> $makefile");
+
+# The Contents of the MAKEFILE ...
+
+print MAKEFILE "string := word.pl general_test2.pl1 FORCE.pl word.pl3 generic_test.perl /tmp.c/bar foo.baz/bar.c MAKEFILES_variable.c\n"
+ ."string2 := \$(string) \$(string) \$(string) \$(string) \$(string) \$(string) \$(string)\n"
+ ."string3 := \$(string2) \$(string2) \$(string2) \$(string2) \$(string2) \$(string2) \$(string2)\n"
+ ."string4 := \$(string3) \$(string3) \$(string3) \$(string3) \$(string3) \$(string3) \$(string3)\n"
+ ."all: \n"
+ ."\t\@echo \$(suffix \$(string)) \n"
+ ."\t\@echo \$(sort \$(suffix \$(string4))) \n"
+ ."\t\@echo \$(suffix \$(string) a.out) \n"
+ ."\t\@echo \$(sort \$(suffix \$(string3))) \n";
+
+
+
+# END of Contents of MAKEFILE
+
+close(MAKEFILE);
+
+&run_make_with_options($makefile,"",&get_logfile,0);
+
+# Create the answer to what should be produced by this Makefile
+
+# COMPARE RESULTS
+$answer = ".pl .pl1 .pl .pl3 .perl .c .c\n"
+ .".c .perl .pl .pl1 .pl3\n"
+ .".pl .pl1 .pl .pl3 .perl .c .c .out\n"
+ .".c .perl .pl .pl1 .pl3\n";
+
+# In this call to compare output, you should use the call &get_logfile(1)
+# to send the name of the last logfile created. You may also use
+# the special call &get_logfile(1) which returns the same as &get_logfile(1).
+
+&compare_output($answer,&get_logfile(1));
+
+# This tells the test driver that the perl test script executed properly.
+1;
+
+
+
+
+
+
diff --git a/src/kmk/tests/scripts/functions/translate b/src/kmk/tests/scripts/functions/translate
new file mode 100644
index 0000000..2dcf83f
--- /dev/null
+++ b/src/kmk/tests/scripts/functions/translate
@@ -0,0 +1,76 @@
+# $Id: translate 2413 2010-09-11 17:43:04Z bird $ -*-perl-*-
+## @file
+# $(translate string, from-set[, to-set[, pad-char]])
+#
+
+#
+# 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 $(translate ) function";
+
+$details = "A few simple tests and edge cases.";
+
+if ($is_kmk) {
+
+ # TEST #0 - check that the feature is present.
+ # --------------------------------------------
+ run_make_test('
+ifneq ($(translate abcdefghijklmnopqrstuvwxyz,abcde,01234),01234fghijklmnopqrstuvwxyz)
+$(error sub-test 0 failed)
+endif
+.PHONY: all
+all: ; @:
+',
+'',
+'');
+
+ # TEST #1 - the real test.
+ # ------------------------
+ run_make_test('
+ifneq ($(translate abcdefghijklmnopqrstuvwxyz,abcde,01234),01234fghijklmnopqrstuvwxyz)
+$(error sub-test 0 failed)
+endif
+ifneq ($(translate abcdefghijklmnopqrstuvwxyz,abcde,,.),.....fghijklmnopqrstuvwxyz)
+$(error sub-test 1 failed)
+endif
+ifneq ($(translate abcdefghijklmnopqrstuvwxyz,abcde,),fghijklmnopqrstuvwxyz)
+$(error sub-test 2 failed)
+endif
+ifneq ($(translate abcdefghijklmnopqrstuvwxyz,abcde,x1),x1fghijklmnopqrstuvwxyz)
+$(error sub-test 3 failed)
+endif
+ifneq ($(translate abcdefghijklmnopqrstuvwxyz,bfh),acdegijklmnopqrstuvwxyz)
+$(error sub-test 4 failed)
+endif
+ifneq ($(translate abcdefghijklmnopqrstuvwxyz,z,Z),abcdefghijklmnopqrstuvwxyZ)
+$(error sub-test 5 failed)
+endif
+
+.PHONY: all
+all: ; @:
+',
+'',
+'');
+}
+
+
+# Indicate that we're done.
+1;
+
diff --git a/src/kmk/tests/scripts/functions/value b/src/kmk/tests/scripts/functions/value
new file mode 100644
index 0000000..8e1a6f0
--- /dev/null
+++ b/src/kmk/tests/scripts/functions/value
@@ -0,0 +1,30 @@
+# -*-perl-*-
+
+$description = "Test the value function.";
+
+$details = "This is a test of the value function in GNU make.
+This function will evaluate to the value of the named variable with no
+further expansion performed on it.\n";
+
+open(MAKEFILE,"> $makefile");
+
+print MAKEFILE <<'EOF';
+export FOO = foo
+
+recurse = FOO = $FOO
+static := FOO = $(value FOO)
+
+all: ; @echo $(recurse) $(value recurse) $(static) $(value static)
+EOF
+
+close(MAKEFILE);
+
+&run_make_with_options($makefile, "", &get_logfile);
+
+# Create the answer to what should be produced by this Makefile
+$answer = "FOO = OO FOO = foo FOO = foo FOO = foo\n";
+
+
+&compare_output($answer,&get_logfile(1));
+
+1;
diff --git a/src/kmk/tests/scripts/functions/warning b/src/kmk/tests/scripts/functions/warning
new file mode 100644
index 0000000..16eb83b
--- /dev/null
+++ b/src/kmk/tests/scripts/functions/warning
@@ -0,0 +1,83 @@
+# -*-Perl-*-
+
+$description = "\
+The following test creates a makefile to test the warning function.";
+
+$details = "";
+
+open(MAKEFILE,"> $makefile");
+
+print MAKEFILE <<'EOF';
+ifdef WARNING1
+$(warning warning is $(WARNING1))
+endif
+
+ifdef WARNING2
+$(warning warning is $(WARNING2))
+endif
+
+ifdef WARNING3
+all: some; @echo hi $(warning warning is $(WARNING3))
+endif
+
+ifdef WARNING4
+all: some; @echo hi
+ @echo there $(warning warning is $(WARNING4))
+endif
+
+some: ; @echo Some stuff
+
+EOF
+
+close(MAKEFILE);
+
+# Test #1
+
+&run_make_with_options($makefile, "WARNING1=yes", &get_logfile, 0);
+$answer = "$makefile:2: warning is yes\nSome stuff\n";
+&compare_output($answer,&get_logfile(1));
+
+# Test #2
+
+&run_make_with_options($makefile, "WARNING2=no", &get_logfile, 0);
+$answer = "$makefile:6: warning is no\nSome stuff\n";
+&compare_output($answer,&get_logfile(1));
+
+# Test #3
+
+&run_make_with_options($makefile, "WARNING3=maybe", &get_logfile, 0);
+$answer = "Some stuff\n$makefile:10: warning is maybe\nhi\n";
+&compare_output($answer,&get_logfile(1));
+
+# Test #4
+
+&run_make_with_options($makefile, "WARNING4=definitely", &get_logfile, 0);
+$answer = "Some stuff\n$makefile:15: warning is definitely\nhi\nthere\n";
+&compare_output($answer,&get_logfile(1));
+
+# Test linenumber offset
+
+run_make_test(q!
+all: one two
+ $(warning in $@ line 3)
+ @true
+ $(warning in $@ line 5)
+
+one two:
+ $(warning in $@ line 8)
+ @true
+ $(warning in $@ line 10)
+!,
+ '', "#MAKEFILE#:8: in one line 8
+#MAKEFILE#:10: in one line 10
+#MAKEFILE#:8: in two line 8
+#MAKEFILE#:10: in two line 10
+#MAKEFILE#:3: in all line 3
+#MAKEFILE#:5: in all line 5\n");
+
+# This tells the test driver that the perl test script executed properly.
+1;
+
+### Local Variables:
+### eval: (setq whitespace-action (delq 'auto-cleanup whitespace-action))
+### End:
diff --git a/src/kmk/tests/scripts/functions/while b/src/kmk/tests/scripts/functions/while
new file mode 100644
index 0000000..c0e6481
--- /dev/null
+++ b/src/kmk/tests/scripts/functions/while
@@ -0,0 +1,73 @@
+# $Id: while 2413 2010-09-11 17:43:04Z bird $ -*-perl-*-
+## @file
+# $(while condition,body)
+#
+
+#
+# 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 $(while ) loop function";
+
+$details = "A few simple tests, nothing spectacular.";
+
+if ($is_kmk) {
+
+ # TEST #0 - check that the feature is present.
+ # --------------------------------------------
+ run_make_test('
+VAR := 0
+OUTPUT := $(while $(VAR)==0,$(eval VAR=1)works)
+ifneq ($(OUTPUT),works)
+$(error sub-test 0 failed:$(OUTPUT))
+endif
+
+.PHONY: all
+all: ; @:
+',
+'',
+'');
+
+ # TEST #1 - the real test.
+ # ------------------------
+ run_make_test('
+VAR := 0
+OUTPUT := $(while $(VAR) < 3,$(eval VAR:=$(expr $(VAR) + 1))$(VAR))
+ifneq ($(OUTPUT),1 2 3)
+$(error sub-test 0 failed:$(OUTPUT))
+endif
+
+ifneq (.$(while 0,asdfasdfadsf).,..)
+$(error sub-test 1 failed)
+endif
+
+.PHONY: all
+all: ; @:
+',
+'',
+'');
+}
+
+
+
+# Indicate that we're done.
+1;
+
+
+
diff --git a/src/kmk/tests/scripts/functions/wildcard b/src/kmk/tests/scripts/functions/wildcard
new file mode 100644
index 0000000..bcd84ad
--- /dev/null
+++ b/src/kmk/tests/scripts/functions/wildcard
@@ -0,0 +1,103 @@
+# -*-perl-*-
+
+$description = "The following test creates a makefile to test wildcard
+expansions and the ability to put a command on the same
+line as the target name separated by a semi-colon.";
+
+$details = "\
+This test creates 4 files by the names of 1.example,
+two.example and 3.example. We execute three tests. The first
+executes the print1 target which tests the '*' wildcard by
+echoing all filenames by the name of '*.example'. The second
+test echo's all files which match '?.example' and
+[a-z0-9].example. Lastly we clean up all of the files using
+the '*' wildcard as in the first test";
+
+open(MAKEFILE,"> $makefile");
+
+# The Contents of the MAKEFILE ...
+
+print MAKEFILE <<EOM;
+.PHONY: print1 print2 clean
+print1: ;\@echo \$(sort \$(wildcard example.*))
+print2:
+\t\@echo \$(sort \$(wildcard example.?))
+\t\@echo \$(sort \$(wildcard example.[a-z0-9]))
+\t\@echo \$(sort \$(wildcard example.[!A-Za-z_\\!]))
+clean:
+\t$delete_command \$(sort \$(wildcard example.*))
+EOM
+
+# END of Contents of MAKEFILE
+
+close(MAKEFILE);
+
+&touch("example.1");
+&touch("example.two");
+&touch("example.3");
+&touch("example.for");
+&touch("example._");
+
+# TEST #1
+# -------
+
+$answer = "example.1 example.3 example._ example.for example.two\n";
+
+&run_make_with_options($makefile,"print1",&get_logfile);
+
+&compare_output($answer,&get_logfile(1));
+
+
+# TEST #2
+# -------
+
+$answer = "example.1 example.3 example._\n"
+ ."example.1 example.3\n"
+ ."example.1 example.3\n";
+
+&run_make_with_options($makefile,"print2",&get_logfile);
+
+&compare_output($answer,&get_logfile(1));
+
+
+# TEST #3
+# -------
+
+$answer = "$delete_command example.1 example.3 example._ example.for example.two";
+if ($vos)
+{
+ $answer .= " \n";
+}
+else
+{
+ $answer .= "\n";
+}
+
+&run_make_with_options($makefile,"clean",&get_logfile);
+
+if ((-f "example.1")||(-f "example.two")||(-f "example.3")||(-f "example.for")) {
+ $test_passed = 0;
+}
+
+&compare_output($answer,&get_logfile(1));
+
+# TEST #4: Verify that failed wildcards don't return the pattern
+
+run_make_test(q!
+all: ; @echo $(wildcard xz--y*.7)
+!,
+ '', "\n");
+
+# TEST #5: wildcard used to verify file existence
+
+touch('xxx.yyy');
+
+run_make_test(q!exists: ; @echo file=$(wildcard xxx.yyy)!,
+ '', "file=xxx.yyy\n");
+
+unlink('xxx.yyy');
+
+run_make_test(q!exists: ; @echo file=$(wildcard xxx.yyy)!,
+ '', "file=\n");
+
+1;
diff --git a/src/kmk/tests/scripts/functions/word b/src/kmk/tests/scripts/functions/word
new file mode 100644
index 0000000..4dcc940
--- /dev/null
+++ b/src/kmk/tests/scripts/functions/word
@@ -0,0 +1,167 @@
+# -*-perl-*-
+$description = "\
+Test the word, words, wordlist, firstword, and lastword functions.\n";
+
+$details = "\
+Produce a variable with a large number of words in it,
+determine the number of words, and then read each one back.\n";
+
+open(MAKEFILE,"> $makefile");
+print MAKEFILE <<'EOF';
+string := word.pl general_test2.pl FORCE.pl word.pl generic_test.perl MAKEFILES_variable.pl
+string2 := $(string) $(string) $(string) $(string) $(string) $(string) $(string)
+string3 := $(string2) $(string2) $(string2) $(string2) $(string2) $(string2) $(string2)
+string4 := $(string3) $(string3) $(string3) $(string3) $(string3) $(string3) $(string3)
+all:
+ @echo $(words $(string))
+ @echo $(words $(string4))
+ @echo $(word 1, $(string))
+ @echo $(word 100, $(string))
+ @echo $(word 1, $(string))
+ @echo $(word 1000, $(string3))
+ @echo $(wordlist 3, 4, $(string))
+ @echo $(wordlist 4, 3, $(string))
+ @echo $(wordlist 1, 6, $(string))
+ @echo $(wordlist 5, 7, $(string))
+ @echo $(wordlist 100, 110, $(string))
+ @echo $(wordlist 7, 10, $(string2))
+EOF
+close(MAKEFILE);
+
+&run_make_with_options($makefile, "", &get_logfile);
+$answer = "6\n"
+ ."2058\n"
+ ."word.pl\n"
+ ."\n"
+ ."word.pl\n"
+ ."\n"
+ ."FORCE.pl word.pl\n"
+ ."\n"
+ ."word.pl general_test2.pl FORCE.pl word.pl generic_test.perl MAKEFILES_variable.pl\n"
+ ."generic_test.perl MAKEFILES_variable.pl\n"
+ ."\n"
+ ."word.pl general_test2.pl FORCE.pl word.pl\n";
+&compare_output($answer, &get_logfile(1));
+
+
+# Test error conditions
+
+run_make_test('FOO = foo bar biz baz
+
+word-e1: ; @echo $(word ,$(FOO))
+word-e2: ; @echo $(word abc ,$(FOO))
+word-e3: ; @echo $(word 1a,$(FOO))
+
+wordlist-e1: ; @echo $(wordlist ,,$(FOO))
+wordlist-e2: ; @echo $(wordlist abc ,,$(FOO))
+wordlist-e3: ; @echo $(wordlist 1, 12a ,$(FOO))',
+ 'word-e1',
+ "#MAKEFILE#:3: *** non-numeric first argument to 'word' function: ''. Stop.",
+ 512);
+
+run_make_test(undef,
+ 'word-e2',
+ "#MAKEFILE#:4: *** non-numeric first argument to 'word' function: 'abc '. Stop.",
+ 512);
+
+run_make_test(undef,
+ 'word-e3',
+ "#MAKEFILE#:5: *** non-numeric first argument to 'word' function: '1a'. Stop.",
+ 512);
+
+run_make_test(undef,
+ 'wordlist-e1',
+ "#MAKEFILE#:7: *** non-numeric first argument to 'wordlist' function: ''. Stop.",
+ 512);
+
+run_make_test(undef,
+ 'wordlist-e2',
+ "#MAKEFILE#:8: *** non-numeric first argument to 'wordlist' function: 'abc '. Stop.",
+ 512);
+
+run_make_test(undef,
+ 'wordlist-e3',
+ "#MAKEFILE#:9: *** non-numeric second argument to 'wordlist' function: ' 12a '. Stop.",
+ 512);
+
+# Test error conditions again, but this time in a variable reference
+
+run_make_test('FOO = foo bar biz baz
+
+W = $(word $x,$(FOO))
+WL = $(wordlist $s,$e,$(FOO))
+
+word-e: ; @echo $(W)
+wordlist-e: ; @echo $(WL)',
+ 'word-e x=',
+ "#MAKEFILE#:3: *** non-numeric first argument to 'word' function: ''. Stop.",
+ 512);
+
+run_make_test(undef,
+ 'word-e x=abc',
+ "#MAKEFILE#:3: *** non-numeric first argument to 'word' function: 'abc'. Stop.",
+ 512);
+
+run_make_test(undef,
+ 'word-e x=0',
+ "#MAKEFILE#:3: *** first argument to 'word' function must be greater than 0. Stop.",
+ 512);
+
+run_make_test(undef,
+ 'wordlist-e s= e=',
+ "#MAKEFILE#:4: *** non-numeric first argument to 'wordlist' function: ''. Stop.",
+ 512);
+
+run_make_test(undef,
+ 'wordlist-e s=abc e=',
+ "#MAKEFILE#:4: *** non-numeric first argument to 'wordlist' function: 'abc'. Stop.",
+ 512);
+
+run_make_test(undef,
+ 'wordlist-e s=4 e=12a',
+ "#MAKEFILE#:4: *** non-numeric second argument to 'wordlist' function: '12a'. Stop.",
+ 512);
+
+run_make_test(undef,
+ 'wordlist-e s=0 e=12',
+ "#MAKEFILE#:4: *** invalid first argument to 'wordlist' function: '0'. Stop.",
+ 512);
+
+
+# TEST #8 -- test $(firstword )
+#
+run_make_test('
+void :=
+list := $(void) foo bar baz #
+
+a := $(word 1,$(list))
+b := $(firstword $(list))
+
+.PHONY: all
+
+all:
+ @test "$a" = "$b" && echo $a
+',
+'',
+'foo');
+
+
+# TEST #9 -- test $(lastword )
+#
+run_make_test('
+void :=
+list := $(void) foo bar baz #
+
+a := $(word $(words $(list)),$(list))
+b := $(lastword $(list))
+
+.PHONY: all
+
+all:
+ @test "$a" = "$b" && echo $a
+',
+'',
+'baz');
+
+# This tells the test driver that the perl test script executed properly.
+1;