File: preprocessor.nsi

package info (click to toggle)
nsis 3.11-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 12,496 kB
  • sloc: cpp: 39,326; ansic: 27,284; python: 1,386; asm: 712; xml: 409; pascal: 231; makefile: 225; javascript: 67
file content (372 lines) | stat: -rwxr-xr-x 8,120 bytes parent folder | download
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
### Preprocessor Tests ###

!ifndef file_is_included
!define file_is_included

Name preprocessor
OutFile preprocessor.exe

# Line comment 1
; Line comment 2

!ifdef some_define_that_doesnt_exist
this should not be executed, so no error should be raised
/*
code inside comments should not be executed
!ifdef
*/
# invalid preprocessor should be ignored
!hello
!error valid_preprocessor_syntax_must_be_ignored
!define /foo /bar /baz and the same with invalid parameters
!endif

!ifdef d1
!error "d1 is not defined!"
!else ifdef d2
!error "d2 is not defined!"
!else
# this should be compiled
!endif

!define d1

!ifdef d1
# this should be compiled
!else ifdef d2
!error "d2 is not defined!"
!else
!error "d1 is defined!"
!endif

!undef d1
!define d2

!ifdef d1
!error "d1 is not defined!"
!else ifdef d2
# this should be compiled
!else
!error "d2 is defined!"
!endif

!ifdef some_define_that_doesnt_exist
the next !endif should be part of this line\
!endif
!\
e\
n\
d\
i\
f

!if 0
/*
this shouldn't be compiled
!endif
*/
!endif

# tests for !if statement
!if 'test' == 'test'
 !if 1 <= 2
  !if ! 100 < 99.99
   !if 2.2 > 1.12
    !if ! 23 >= 37
     !if 1 && 1
      !if ! 0 || 0

        # this should be compiled

      !else
       !error "!if ! 0 || 0 is true!"
      !endif
     !else
      !error "!if 1 && 1 is true!"
     !endif
    !else
     !error "!if ! 23 >= 37 is true!"
    !endif
   !else
    !error "!if 2.2 > 1.12 is true!"
   !endif
  !else
   !error "!if ! 100 < 99.99 is true!"
  !endif
 !else
  !error "!if 1 <= 2 is true!"
 !endif
!else
 !error "!if 'test' == 'test' is true!"
!endif

; !assert
!assert 1 "" ; No message
!assert 0 < 1 "Must be tiny" ; Custom message

; Built-in defines that should always exist
!assert ${__LINE__} ""
!assert "${__FILE__}" != "" ""
!assert ${NSIS_CHAR_SIZE} ""
!assert ${NSIS_PTR_SIZE} >= 4 ""

!define ASSERT `!insertmacro ASSERT "${U+24}{__FILE__}" ${U+24}{__LINE__} `
!macro ASSERT __file __line __xpr
!if ${__xpr}
!else
!error `ASSERT: ${__xpr} (${__file}:${__line})`
!endif
!macroend


; test macros
!macro TM_0
!macroend
!macro TM_1
!error "Wrong TM_1"
!macroend
!macro TM_2
!error "Wrong TM_2"
!macroend
!macroundef TM_2 ; Undefine the last macro
!macro TM_2
!if 0
!endif
!macroend
!ifmacrodef TM_1
!macroundef TM_1 ; Undefine "in the middle" macro
!endif
!macro TM_1
!macroend
!insertmacro TM_1
!insertmacro TM_2

!macro TM_Recursion def
!if '${${def}}' < 42
  !define /redef /math ${def} '${${def}}' + 1
  !insertmacro ${__MACRO__} ${def}
!endif
!macroend
!define /redef OUT1 0
!insertmacro TM_Recursion OUT1
${ASSERT} '${OUT1} = 42'


; testing of two math functions and a macro hack :)
!define increase "!insertmacro increase"
!macro increase DEFINE
  !define /math ${DEFINE}_MACROTEMP ${${DEFINE}} + 1
  !undef ${DEFINE}
  !define ${DEFINE} ${${DEFINE}_MACROTEMP}
  !undef ${DEFINE}_MACROTEMP
!macroend

!define number1 1 #  1
!define /math number2 2 + 3
!define /math number3 ${number2} - ${number1}
${increase} number3
!define /math number4 2 * ${number3}
!define /math number5 ${number4} % 3

!if ${number1} != 1
  !error "number1 != 1"
!endif

!if ${number2} != 5
  !error "number2 != 5"
!endif

!if ${number3} != 5
  !error "number3 != 5"
!endif

!if ${number4} != 10
  !error "number4 != 10"
!endif

!if ${number5} != 1
  !error "number5 != 1"
!endif

!define /redef /math OUT1 0xffffffff >> 31
${ASSERT} '${OUT1} = -1'
!define /redef /math OUT1 0xffffffff >>> 31
${ASSERT} '${OUT1} = 1'
!define /redef /math OUT1 1 << 31
${ASSERT} '${OUT1} = 0x80000000'

!define /redef /math OUT1 0x80000000 ^ 0x40000000
${ASSERT} '${OUT1} = 0xC0000000'

!define /redef /intfmt OUT1 "0x%.3X" 42
${ASSERT} '${OUT1} = 0x02A'

!pragma internal x OUT "0x10 | 0x40" ; NSD requires this when using LoadAndSetImage
!if "${OUT}" <> 80
  !error "math expression failed"
!endif

; end math functions


# this should just give a warning, not an error
!include /NONFATAL file_that_doesnt_exist.nsh

# this should include this file just one time.
!include preprocessor.nsi


# test scopes

Section
Return
WriteUninstaller uninst.exe # avoid warning
SectionEnd

!macro TEST_SCOPE scope def should_exist

  !if ${should_exist} == y
    !ifndef ${def}
      !error "${def} not defined in ${scope} scope"
    !endif
  !else
    !ifdef ${def}
      !error "${def} defined in ${scope} scope"
    !endif
  !endif

!macroend

!macro TEST_SCOPES scope global section function pageex uninstall

  !insertmacro TEST_SCOPE "${scope}" __GLOBAL__    ${global}
  !insertmacro TEST_SCOPE "${scope}" __SECTION__   ${section}
  !insertmacro TEST_SCOPE "${scope}" __FUNCTION__  ${function}
  !insertmacro TEST_SCOPE "${scope}" __PAGEEX__    ${pageex}
  !insertmacro TEST_SCOPE "${scope}" __UNINSTALL__ ${uninstall}

!macroend

!insertmacro TEST_SCOPE "macro" __MACRO__ y
!insertmacro TEST_SCOPES "global" y n n n n

Section test
!insertmacro TEST_SCOPES "section" n y n n n
!if ${__SECTION__} != test
  !error "invalid __SECTION__ value"
!endif
SectionEnd

Section un.test
!insertmacro TEST_SCOPES "uninstall section" n y n n y
!if ${__SECTION__} != test
  !error "invalid __SECTION__ value"
!endif
SectionEnd

Function test
Call test # avoid warning
!insertmacro TEST_SCOPES "function" n n y n n
!if ${__FUNCTION__} != test
  !error "invalid __FUNCTION__ value"
!endif
FunctionEnd

Function un.test
Call un.test # avoid warning
!insertmacro TEST_SCOPES "uninstall function" n n y n y
!if ${__FUNCTION__} != test
  !error "invalid __FUNCTION__ value"
!endif
FunctionEnd

PageEx instfiles
!insertmacro TEST_SCOPES "pageex" n n n y n
!if ${__PAGEEX__} != instfiles
  !error "invalid __PAGEEX__ value"
!endif
PageExEnd

PageEx un.instfiles
!insertmacro TEST_SCOPES "uninstall pageex" n n n y y
!if ${__PAGEEX__} != instfiles
  !error "invalid __PAGEEX__ value"
!endif
PageExEnd

!insertmacro TEST_SCOPES "global" y n n n n


# test !pragma
!pragma warning push
  !pragma warning disable 7000
  !include /NONFATAL doesnt_exist_nor_can_you_see_me.nsh
!pragma warning pop

!pragma warning push
  !pragma warning disable all
  !include /NONFATAL doesnt_exist_nor_can_you_see_me.nsh
  !pragma warning push
    !pragma warning error all
  !pragma warning pop
  !warning "You can't see me" ; "disable all" is still in effect
!pragma warning pop

!if ! 1 <> 0
  !error "1 is not 0"
!endif
!pragma warning push
!pragma warning disable 7070 ; Invalid number
!if Hello <> 0
  !error "Hello is not a number"
!endif
!pragma warning pop

# test !searchparse
!searchparse "AbcDef" "Abc" OUT1
${ASSERT} '${OUT1} S== "Def"'

!define /redef OUT1 FAILED
!searchparse /noerrors "AbcDef" "FailThis" OUT1
${ASSERT} '${OUT1} S== "FAILED"'

!searchparse /ignorecase "AbcDef" "ABC" OUT1
${ASSERT} '${OUT1} S== "Def"'

!searchparse "AbcDef" "Ab" OUT1 "D" OUT2
${ASSERT} '"${OUT1}${OUT2}" S== "cef"'

!searchparse /ignorecase /file "${__FILE__}" "### " OUT1 " Tests"
${ASSERT} '${OUT1} == "Preprocessor"'

!searchparse "AbcDef" "" OUT1 "Def" ; Empty first search string and chopping off the end without defining OUTPUTSYMBOL2
${ASSERT} '${OUT1} S== "Abc"'


# test !searchreplace
!searchreplace OUT1 "FooBar" "Bar" "Baz"
${ASSERT} '${OUT1} S== "FooBaz"'

!searchreplace OUT1 "FooBarBar" "Bar" "Baz" ; "replacing all instances"
${ASSERT} '${OUT1} S== "FooBazBaz"'

!searchreplace OUT1 "FooBar" "BAR" "Baz"
${ASSERT} '${OUT1} S== "FooBar"'

!searchreplace /ignorecase OUT1 "FooBar" "BAR" "Baz"
${ASSERT} '${OUT1} S== "FooBaz"'

!searchreplace OUT1 "FooBar" "FailThis" "Baz" ; "allows you to redefine symbol_out without warning or error"
${ASSERT} '${OUT1} S== "FooBar"'


!verbose 4
!echo "Completed tests"
!verbose 2
!pragma whip 0 # EOF
!else

# this should just give a warning, not an error
!include /NONFATAL another_file_that_doesnt_exist.nsh

!endif