diff options
Diffstat (limited to '')
-rw-r--r-- | src/kmk/tests/scripts/functions/if | 33 | ||||
-rw-r--r-- | src/kmk/tests/scripts/functions/if-expr | 84 |
2 files changed, 117 insertions, 0 deletions
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; + |