Can I make _Assert write to console instead of a message box?
Asked Answered
E

1

1

I am writing a script in AutoIt to test a windows application, and I am using the _Assert function to verify certain actions.

In the documentation I found there is a parameter to say whether or not the script should end if an assertion fails, which is great because in some cases I would like the script to continue, but unfortunately it is still halted by a message box.

Can I override the _Assert function somehow to only print to the console when certain assertions fail, so the script can continue without user interaction?

Elegant answered 5/6, 2015 at 18:38 Comment(0)
C
1

Desired behavior can not be achieved using _Assert(). However, _Assert() can be adjusted to do so (replaced MsgBox() by ConsoleWrite()):

Func _AssertCustom($sCondition, $bExit = True, $nCode = 0x7FFFFFFF, $sLine = @ScriptLineNumber, Const $iCurERR = @error, Const $iCurEXT = @extended)
    Local $bCondition = Execute($sCondition)
    If Not $bCondition Then
        ConsoleWrite("Assertion Failed (Line " & $sLine & "): " & $sCondition & @CRLF)
        If $bExit Then Exit $nCode
    EndIf
    Return SetError($iCurERR, $iCurEXT, $bCondition)
EndFunc

Best to declare as new function (not to change Debug.au3).

Canonize answered 7/6, 2015 at 19:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.