Skip to content
⌘ NSIS Forum Archive

automate unit test for nsis installer

9 posts

shekara#

automate unit test for nsis installer

I have written installer with multiple sections in nsis. i would like have framework similar to java to unit test the code a developer writes. request all to share there practises
Anders#
Unit tests for macros and functions are possible but I'm not sure how you would do it for sections. Or to be more specific, the file installing and registry parts. It would make more sense to me to automate running the installer silently and performing tests on the thing you installed.

If you had something like

Function DoubleIt
Exch $0
IntOp $0 $0 * 2
Exch $0
FunctionEnd
Section
Push 42
Call DoubleIt
Pop $0
SetOutPath $InstDir\$0
File Foo.exe
File Bar.dll
SectionEnd 
DoubleIt assumes there is a parameter on the stack and it fails to handle overflow if the number is large and you could write tests for these things (at least the overflow) but how would you deal with the files?
shekara#
what is general practice followed for macros and functions? i agree for sections that it is herculean task and easy way there.
Anders#
For functions, one thing you can verify is that they don't clobber the registers.

StrCpy $0 Reg0
...
StrCpy $R9 RegR9
Push whatever
Call TheFunction
StrCmp $0 Reg0 ...
... 
(Some functions return their value in $0 etc. but you get the point)

For most functions/macros you need something custom for each.

If a function deals with paths for example then you can test it by calling it with "C:", "C:\", "C:foo", "C:\foo", "C:\foo\", "\foo" and ".\foo" and verify that the result is what you expect...
shekara#
for each sections, can we have a separate nsi file and then only that nsi file can be executed? for unit testing is this approach possible ?
Anders#
Yes you can, !include is really just a text insert command, it will insert any text.

A cleaner way is perhaps to uncheck the sections you don't want to execute, see Sections.nsh for this.
Anders#
Originally Posted by Anders View Post
For functions, one thing you can verify is that they don't clobber the registers.
I created a .nsh to help detect this.
shekara#
i have to execute it silently. so i cannot uncheck sections every time. it has be done silently