summaryrefslogtreecommitdiff
path: root/tests/scripts/features/conditionals
blob: 2ece60bbd66d3fa43f177f44c5f87949548f7dc6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#                                                                    -*-perl-*-
$description = "Check GNU make conditionals.";

$details = "Attempt various different flavors of GNU make conditionals.";

run_make_test('
arg1 = first
arg2 = second
arg3 = third
arg4 = cc
arg5 = second

all:
ifeq ($(arg1),$(arg2))
	@echo arg1 equals arg2
else
	@echo arg1 NOT equal arg2
endif

ifeq \'$(arg2)\' "$(arg5)"
	@echo arg2 equals arg5
else
	@echo arg2 NOT equal arg5
endif

ifneq \'$(arg3)\' \'$(arg4)\'
	@echo arg3 NOT equal arg4
else
	@echo arg3 equal arg4
endif

ifndef undefined
	@echo variable is undefined
else
	@echo variable undefined is defined
endif
ifdef arg4
	@echo arg4 is defined
else
	@echo arg4 is NOT defined
endif',
              '',
              'arg1 NOT equal arg2
arg2 equals arg5
arg3 NOT equal arg4
variable is undefined
arg4 is defined');


# Test expansion of variables inside ifdef.

run_make_test('
foo = 1

FOO = foo
F = f

DEF = no
DEF2 = no

ifdef $(FOO)
DEF = yes
endif

ifdef $(F)oo
DEF2 = yes
endif


DEF3 = no
FUNC = $1
ifdef $(call FUNC,DEF)3
  DEF3 = yes
endif

all:; @echo DEF=$(DEF) DEF2=$(DEF2) DEF3=$(DEF3)',
              '',
              'DEF=yes DEF2=yes DEF3=yes');


# Test all the different "else if..." constructs

run_make_test('
arg1 = first
arg2 = second
arg3 = third
arg4 = cc
arg5 = fifth

result =

ifeq ($(arg1),$(arg2))
  result += arg1 equals arg2
else ifeq \'$(arg2)\' "$(arg5)"
  result += arg2 equals arg5
else ifneq \'$(arg3)\' \'$(arg3)\'
  result += arg3 NOT equal arg4
else ifndef arg5
  result += variable is undefined
else ifdef undefined
  result += arg4 is defined
else
  result += success
endif


all: ; @echo $(result)',
              '',
              'success');


# Test some random "else if..." construct nesting

run_make_test('
arg1 = first
arg2 = second
arg3 = third
arg4 = cc
arg5 = second

ifeq ($(arg1),$(arg2))
  $(info failed 1)
else ifeq \'$(arg2)\' "$(arg2)"
  ifdef undefined
    $(info failed 2)
  else
    $(info success)
  endif
else ifneq \'$(arg3)\' \'$(arg3)\'
  $(info failed 3)
else ifdef arg5
  $(info failed 4)
else ifdef undefined
  $(info failed 5)
else
  $(info failed 6)
endif

.PHONY: all
all: ; @:',
              '',
              'success');


# This tells the test driver that the perl test script executed properly.
1;