Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I assert in VBScript scripts?

What is a good way to use asserts in VBScript scripts?

Is there built-in functionality for it or will it have to be emulated? What is best practice?

One application is to test for objects being Nothing during development.

like image 304
Peter Mortensen Avatar asked Jan 22 '23 13:01

Peter Mortensen


1 Answers

An operational answer (for others that may need it) is to define this function, from Rosetta Code:

    sub Assert( boolExpr, strOnFail )
        if not boolExpr then
            Err.Raise vbObjectError + 99999, , strOnFail
        end if
    end sub

Invocation:

    Set obj2 = Nothing
    Assert Not obj2 Is Nothing, "obj2 is Nothing!"

Output:

    someScript.vbs(17, 3) (null): obj2 is Nothing!
like image 183
Peter Mortensen Avatar answered Feb 24 '23 14:02

Peter Mortensen