Announcement

Collapse
No announcement yet.

automate unit test for nsis installer

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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

  • #2
    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

    PHP Code:
    Function DoubleIt
    Exch 
    $0
    IntOp 
    $$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?
    IntOp $PostCount $PostCount + 1

    Comment


    • #3
      what is general practice followed for macros and functions? i agree for sections that it is herculean task and easy way there.

      Comment


      • #4
        For functions, one thing you can verify is that they don't clobber the registers.

        PHP Code:
        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...
        IntOp $PostCount $PostCount + 1

        Comment


        • #5
          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 ?

          Comment


          • #6
            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.
            IntOp $PostCount $PostCount + 1

            Comment


            • #7
              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.
              IntOp $PostCount $PostCount + 1

              Comment


              • #8
                i have to execute it silently. so i cannot uncheck sections every time. it has be done silently

                Comment


                • #9
                  You can use an answer file or check the command line for switches.
                  IntOp $PostCount $PostCount + 1

                  Comment

                  Working...
                  X