| 1 | # $Id: evalcall 2413 2010-09-11 17:43:04Z bird $ -*-perl-*-
|
|---|
| 2 | ## @file
|
|---|
| 3 | # $(evalcall var,argN...)
|
|---|
| 4 | #
|
|---|
| 5 |
|
|---|
| 6 | #
|
|---|
| 7 | # Copyright (c) 2008-2010 knut st. osmundsen <bird-kBuild-spamx@anduin.net>
|
|---|
| 8 | #
|
|---|
| 9 | # This file is part of kBuild.
|
|---|
| 10 | #
|
|---|
| 11 | # kBuild is free software; you can redistribute it and/or modify
|
|---|
| 12 | # it under the terms of the GNU General Public License as published by
|
|---|
| 13 | # the Free Software Foundation; either version 3 of the License, or
|
|---|
| 14 | # (at your option) any later version.
|
|---|
| 15 | #
|
|---|
| 16 | # kBuild is distributed in the hope that it will be useful,
|
|---|
| 17 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 18 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|---|
| 19 | # GNU General Public License for more details.
|
|---|
| 20 | #
|
|---|
| 21 | # You should have received a copy of the GNU General Public License
|
|---|
| 22 | # along with kBuild. If not, see <http://www.gnu.org/licenses/>
|
|---|
| 23 | #
|
|---|
| 24 | #
|
|---|
| 25 |
|
|---|
| 26 | $description = "Tests the $(evalcall ) function";
|
|---|
| 27 |
|
|---|
| 28 | $details = "A few simple tests, nothing spectacular.";
|
|---|
| 29 |
|
|---|
| 30 | if ($is_kmk) {
|
|---|
| 31 |
|
|---|
| 32 | # TEST #0 - check that the feature is present.
|
|---|
| 33 | # --------------------------------------------
|
|---|
| 34 | run_make_test('
|
|---|
| 35 | FUNC = local .RETURN = $2 $1
|
|---|
| 36 | ifneq ($(evalcall FUNC,a,b),b a)
|
|---|
| 37 | $(error sub-test 0 failed: $(evalcall FUNC,a,b))
|
|---|
| 38 | endif
|
|---|
| 39 |
|
|---|
| 40 | .PHONY: all
|
|---|
| 41 | all: ; @:
|
|---|
| 42 | ',
|
|---|
| 43 | '',
|
|---|
| 44 | '');
|
|---|
| 45 |
|
|---|
| 46 | # TEST #1 - the real test.
|
|---|
| 47 | # ------------------------
|
|---|
| 48 | run_make_test('
|
|---|
| 49 |
|
|---|
| 50 | FUNC = local .RETURN = $2 $1
|
|---|
| 51 | ifneq ($(evalcall FUNC,a,b),b a)
|
|---|
| 52 | $(error sub-test 0 failed)
|
|---|
| 53 | endif
|
|---|
| 54 |
|
|---|
| 55 | ADD = local .RETURN = $(expr $1 + $2)
|
|---|
| 56 | ifneq ($(evalcall ADD,1,2),3)
|
|---|
| 57 | $(error sub-test 1 failed)
|
|---|
| 58 | endif
|
|---|
| 59 |
|
|---|
| 60 | define POP
|
|---|
| 61 | local words := $(words $($1))
|
|---|
| 62 | local .RETURN := $(word $(words), $($1))
|
|---|
| 63 | $1 := $(wordlist 1, $(expr $(words) - 1), $($1))
|
|---|
| 64 | endef
|
|---|
| 65 | stack-var = a b c d
|
|---|
| 66 | ifneq ($(evalcall POP,stack-var),d)
|
|---|
| 67 | $(error sub-test 2d failed)
|
|---|
| 68 | endif
|
|---|
| 69 | ifneq ($(evalcall POP,stack-var),c)
|
|---|
| 70 | $(error sub-test 2c failed)
|
|---|
| 71 | endif
|
|---|
| 72 | ifneq ($(evalcall POP,stack-var),b)
|
|---|
| 73 | $(error sub-test 2b failed)
|
|---|
| 74 | endif
|
|---|
| 75 | ifneq ($(evalcall POP,stack-var),a)
|
|---|
| 76 | $(error sub-test 2a failed)
|
|---|
| 77 | endif
|
|---|
| 78 |
|
|---|
| 79 |
|
|---|
| 80 | # Negative tests:
|
|---|
| 81 |
|
|---|
| 82 | .RETURN = $2 $1
|
|---|
| 83 | FUNC =
|
|---|
| 84 | ifneq ($(evalcall FUNC,a,b),)
|
|---|
| 85 | $(error sub-test 10 failed)
|
|---|
| 86 | endif
|
|---|
| 87 |
|
|---|
| 88 | .RETURN =
|
|---|
| 89 | FUNC = .RETURN = $2 $1
|
|---|
| 90 | ifneq ($(evalcall FUNC,a,b),)
|
|---|
| 91 | $(error sub-test 11 failed)
|
|---|
| 92 | endif
|
|---|
| 93 |
|
|---|
| 94 |
|
|---|
| 95 | # Test .ARGC:
|
|---|
| 96 |
|
|---|
| 97 | FUNC = local .RETURN = $(.ARGC)
|
|---|
| 98 | ifneq ($(evalcall FUNC,a,b),2)
|
|---|
| 99 | $(error sub-test 20 failed)
|
|---|
| 100 | endif
|
|---|
| 101 | ifneq ($(evalcall FUNC),0)
|
|---|
| 102 | $(error sub-test 21 failed)
|
|---|
| 103 | endif
|
|---|
| 104 | ifneq ($(evalcall FUNC,aasdfasdf),1)
|
|---|
| 105 | $(error sub-test 22 failed)
|
|---|
| 106 | endif
|
|---|
| 107 |
|
|---|
| 108 |
|
|---|
| 109 | .PHONY: all
|
|---|
| 110 | all: ; @:
|
|---|
| 111 | ',
|
|---|
| 112 | '',
|
|---|
| 113 | '');
|
|---|
| 114 | }
|
|---|
| 115 |
|
|---|
| 116 |
|
|---|
| 117 | # Indicate that we're done.
|
|---|
| 118 | 1;
|
|---|
| 119 |
|
|---|