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

邮差的信 提交于 2019-12-11 13:12:36

问题


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?


回答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).



来源:https://stackoverflow.com/questions/30673577/can-i-make-assert-write-to-console-instead-of-a-message-box

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!