Debian Codegraph @

Source/Tests/preprocessor.nsi

raw
1 ### Preprocessor Tests ###
2
3 !ifndef file_is_included
4 !define file_is_included
5
6 Name preprocessor
7 OutFile preprocessor.exe
8
9 # Line comment 1
10 ; Line comment 2
11
12 !ifdef some_define_that_doesnt_exist
13 this should not be executed, so no error should be raised
14 /*
15 code inside comments should not be executed
16 !ifdef
17 */
18 # invalid preprocessor should be ignored
19 !hello
20 !error valid_preprocessor_syntax_must_be_ignored
21 !define /foo /bar /baz and the same with invalid parameters
22 !endif
23
24 !ifdef d1
25 !error "d1 is not defined!"
26 !else ifdef d2
27 !error "d2 is not defined!"
28 !else
29 # this should be compiled
30 !endif
31
32 !define d1
33
34 !ifdef d1
35 # this should be compiled
36 !else ifdef d2
37 !error "d2 is not defined!"
38 !else
39 !error "d1 is defined!"
40 !endif
41
42 !undef d1
43 !define d2
44
45 !ifdef d1
46 !error "d1 is not defined!"
47 !else ifdef d2
48 # this should be compiled
49 !else
50 !error "d2 is defined!"
51 !endif
52
53 !ifdef some_define_that_doesnt_exist
54 the next !endif should be part of this line\
55 !endif
56 !\
57 e\
58 n\
59 d\
60 i\
61 f
62
63 !if 0
64 /*
65 this shouldn't be compiled
66 !endif
67 */
68 !endif
69
70 # tests for !if statement
71 !if 'test' == 'test'
72 !if 1 <= 2
73 !if ! 100 < 99.99
74 !if 2.2 > 1.12
75 !if ! 23 >= 37
76 !if 1 && 1
77 !if ! 0 || 0
78
79 # this should be compiled
80
81 !else
82 !error "!if ! 0 || 0 is true!"
83 !endif
84 !else
85 !error "!if 1 && 1 is true!"
86 !endif
87 !else
88 !error "!if ! 23 >= 37 is true!"
89 !endif
90 !else
91 !error "!if 2.2 > 1.12 is true!"
92 !endif
93 !else
94 !error "!if ! 100 < 99.99 is true!"
95 !endif
96 !else
97 !error "!if 1 <= 2 is true!"
98 !endif
99 !else
100 !error "!if 'test' == 'test' is true!"
101 !endif
102
103 ; !assert
104 !assert 1 "" ; No message
105 !assert 0 < 1 "Must be tiny" ; Custom message
106
107 ; Built-in defines that should always exist
108 !assert ${__LINE__} ""
109 !assert "${__FILE__}" != "" ""
110 !assert ${NSIS_CHAR_SIZE} ""
111 !assert ${NSIS_PTR_SIZE} >= 4 ""
112
113 !define ASSERT `!insertmacro ASSERT "${U+24}{__FILE__}" ${U+24}{__LINE__} `
114 !macro ASSERT __file __line __xpr
115 !if ${__xpr}
116 !else
117 !error `ASSERT: ${__xpr} (${__file}:${__line})`
118 !endif
119 !macroend
120
121
122 ; test macros
123 !macro TM_0
124 !macroend
125 !macro TM_1
126 !error "Wrong TM_1"
127 !macroend
128 !macro TM_2
129 !error "Wrong TM_2"
130 !macroend
131 !macroundef TM_2 ; Undefine the last macro
132 !macro TM_2
133 !if 0
134 !endif
135 !macroend
136 !ifmacrodef TM_1
137 !macroundef TM_1 ; Undefine "in the middle" macro
138 !endif
139 !macro TM_1
140 !macroend
141 !insertmacro TM_1
142 !insertmacro TM_2
143
144 !macro TM_Recursion def
145 !if '${${def}}' < 42
146 !define /redef /math ${def} '${${def}}' + 1
147 !insertmacro ${__MACRO__} ${def}
148 !endif
149 !macroend
150 !define /redef OUT1 0
151 !insertmacro TM_Recursion OUT1
152 ${ASSERT} '${OUT1} = 42'
153
154
155 ; testing of two math functions and a macro hack :)
156 !define increase "!insertmacro increase"
157 !macro increase DEFINE
158 !define /math ${DEFINE}_MACROTEMP ${${DEFINE}} + 1
159 !undef ${DEFINE}
160 !define ${DEFINE} ${${DEFINE}_MACROTEMP}
161 !undef ${DEFINE}_MACROTEMP
162 !macroend
163
164 !define number1 1 # 1
165 !define /math number2 2 + 3
166 !define /math number3 ${number2} - ${number1}
167 ${increase} number3
168 !define /math number4 2 * ${number3}
169 !define /math number5 ${number4} % 3
170
171 !if ${number1} != 1
172 !error "number1 != 1"
173 !endif
174
175 !if ${number2} != 5
176 !error "number2 != 5"
177 !endif
178
179 !if ${number3} != 5
180 !error "number3 != 5"
181 !endif
182
183 !if ${number4} != 10
184 !error "number4 != 10"
185 !endif
186
187 !if ${number5} != 1
188 !error "number5 != 1"
189 !endif
190
191 !define /redef /math OUT1 0xffffffff >> 31
192 ${ASSERT} '${OUT1} = -1'
193 !define /redef /math OUT1 0xffffffff >>> 31
194 ${ASSERT} '${OUT1} = 1'
195 !define /redef /math OUT1 1 << 31
196 ${ASSERT} '${OUT1} = 0x80000000'
197
198 !define /redef /math OUT1 0x80000000 ^ 0x40000000
199 ${ASSERT} '${OUT1} = 0xC0000000'
200
201 !define /redef /intfmt OUT1 "0x%.3X" 42
202 ${ASSERT} '${OUT1} = 0x02A'
203
204 !pragma internal x OUT "0x10 | 0x40" ; NSD requires this when using LoadAndSetImage
205 !if "${OUT}" <> 80
206 !error "math expression failed"
207 !endif
208
209 ; end math functions
210
211
212 # this should just give a warning, not an error
213 !include /NONFATAL file_that_doesnt_exist.nsh
214
215 # this should include this file just one time.
216 !include preprocessor.nsi
217
218
219 # test scopes
220
221 Section
222 Return
223 WriteUninstaller uninst.exe # avoid warning
224 SectionEnd
225
226 !macro TEST_SCOPE scope def should_exist
227
228 !if ${should_exist} == y
229 !ifndef ${def}
230 !error "${def} not defined in ${scope} scope"
231 !endif
232 !else
233 !ifdef ${def}
234 !error "${def} defined in ${scope} scope"
235 !endif
236 !endif
237
238 !macroend
239
240 !macro TEST_SCOPES scope global section function pageex uninstall
241
242 !insertmacro TEST_SCOPE "${scope}" __GLOBAL__ ${global}
243 !insertmacro TEST_SCOPE "${scope}" __SECTION__ ${section}
244 !insertmacro TEST_SCOPE "${scope}" __FUNCTION__ ${function}
245 !insertmacro TEST_SCOPE "${scope}" __PAGEEX__ ${pageex}
246 !insertmacro TEST_SCOPE "${scope}" __UNINSTALL__ ${uninstall}
247
248 !macroend
249
250 !insertmacro TEST_SCOPE "macro" __MACRO__ y
251 !insertmacro TEST_SCOPES "global" y n n n n
252
253 Section test
254 !insertmacro TEST_SCOPES "section" n y n n n
255 !if ${__SECTION__} != test
256 !error "invalid __SECTION__ value"
257 !endif
258 SectionEnd
259
260 Section un.test
261 !insertmacro TEST_SCOPES "uninstall section" n y n n y
262 !if ${__SECTION__} != test
263 !error "invalid __SECTION__ value"
264 !endif
265 SectionEnd
266
267 Function test
268 Call test # avoid warning
269 !insertmacro TEST_SCOPES "function" n n y n n
270 !if ${__FUNCTION__} != test
271 !error "invalid __FUNCTION__ value"
272 !endif
273 FunctionEnd
274
275 Function un.test
276 Call un.test # avoid warning
277 !insertmacro TEST_SCOPES "uninstall function" n n y n y
278 !if ${__FUNCTION__} != test
279 !error "invalid __FUNCTION__ value"
280 !endif
281 FunctionEnd
282
283 PageEx instfiles
284 !insertmacro TEST_SCOPES "pageex" n n n y n
285 !if ${__PAGEEX__} != instfiles
286 !error "invalid __PAGEEX__ value"
287 !endif
288 PageExEnd
289
290 PageEx un.instfiles
291 !insertmacro TEST_SCOPES "uninstall pageex" n n n y y
292 !if ${__PAGEEX__} != instfiles
293 !error "invalid __PAGEEX__ value"
294 !endif
295 PageExEnd
296
297 !insertmacro TEST_SCOPES "global" y n n n n
298
299
300 # test !pragma
301 !pragma warning push
302 !pragma warning disable 7000
303 !include /NONFATAL doesnt_exist_nor_can_you_see_me.nsh
304 !pragma warning pop
305
306 !pragma warning push
307 !pragma warning disable all
308 !include /NONFATAL doesnt_exist_nor_can_you_see_me.nsh
309 !pragma warning push
310 !pragma warning error all
311 !pragma warning pop
312 !warning "You can't see me" ; "disable all" is still in effect
313 !pragma warning pop
314
315 !if ! 1 <> 0
316 !error "1 is not 0"
317 !endif
318 !pragma warning push
319 !pragma warning disable 7070 ; Invalid number
320 !if Hello <> 0
321 !error "Hello is not a number"
322 !endif
323 !pragma warning pop
324
325 # test !searchparse
326 !searchparse "AbcDef" "Abc" OUT1
327 ${ASSERT} '${OUT1} S== "Def"'
328
329 !define /redef OUT1 FAILED
330 !searchparse /noerrors "AbcDef" "FailThis" OUT1
331 ${ASSERT} '${OUT1} S== "FAILED"'
332
333 !searchparse /ignorecase "AbcDef" "ABC" OUT1
334 ${ASSERT} '${OUT1} S== "Def"'
335
336 !searchparse "AbcDef" "Ab" OUT1 "D" OUT2
337 ${ASSERT} '"${OUT1}${OUT2}" S== "cef"'
338
339 !searchparse /ignorecase /file "${__FILE__}" "### " OUT1 " Tests"
340 ${ASSERT} '${OUT1} == "Preprocessor"'
341
342 !searchparse "AbcDef" "" OUT1 "Def" ; Empty first search string and chopping off the end without defining OUTPUTSYMBOL2
343 ${ASSERT} '${OUT1} S== "Abc"'
344
345
346 # test !searchreplace
347 !searchreplace OUT1 "FooBar" "Bar" "Baz"
348 ${ASSERT} '${OUT1} S== "FooBaz"'
349
350 !searchreplace OUT1 "FooBarBar" "Bar" "Baz" ; "replacing all instances"
351 ${ASSERT} '${OUT1} S== "FooBazBaz"'
352
353 !searchreplace OUT1 "FooBar" "BAR" "Baz"
354 ${ASSERT} '${OUT1} S== "FooBar"'
355
356 !searchreplace /ignorecase OUT1 "FooBar" "BAR" "Baz"
357 ${ASSERT} '${OUT1} S== "FooBaz"'
358
359 !searchreplace OUT1 "FooBar" "FailThis" "Baz" ; "allows you to redefine symbol_out without warning or error"
360 ${ASSERT} '${OUT1} S== "FooBar"'
361
362
363 !verbose 4
364 !echo "Completed tests"
365 !verbose 2
366 !pragma whip 0 # EOF
367 !else
368
369 # this should just give a warning, not an error
370 !include /NONFATAL another_file_that_doesnt_exist.nsh
371
372 !endif