Modify

Opened 17 years ago

Closed 17 years ago

Last modified 6 years ago

#957 closed Feature Request (Completed)

Assert keyword or function

Reported by: Nutster Owned by: J-Paul Mesnage
Milestone: 3.3.1.0 Component: AutoIt
Version: Severity: None
Keywords: Cc:

Description

Could we add an Assert keyword of function that would break execution with an error message indicating the assertion that failed.

e.g.

Assert($sABC > "")

If $sABC is empty (so the $sABC fails) the engine reports an error and exits the program.


AutoIt: Assertion on line 78 failed: $sABC > ""

Attachments (0)

Change History (3)

comment:1 by TicketCleanup, 17 years ago

Version: 3.3.0.0

Automatic ticket cleanup.

comment:2 by Valik, 17 years ago

Doesn't a function like this accomplish what you want?

; ===================================================================
; _Assert($bCondition, $sMsg, $bExit = True, $nCode = 0x7FFFFFFF, $sLine = @ScriptLineNumber)
;
; Asserts that a condition is true.
; Parameters:
;	$bCondition - IN - The condition that must evaluate to true.
;	$sMsg - IN - The message to display if the condition is false.
;	$bExit - IN/OPTIONAL - If true, the script is aborted.
;	$nCode - IN/OPTIONAL - The exit code to use if the script is aborted.
;	$sLine - IN/OPTIONAL - Displays the line number where the assertion failed.  If this value is not
;		changed, then the default value will show the correct line.
; Returns:
;	The result of the condition (Only valid when not exiting).
; ===================================================================
Func _Assert($bCondition, $sMsg, $bExit = True, $nCode = 0x7FFFFFFF, $sLine = @ScriptLineNumber)
	If Not $bCondition Then
		MsgBox($MB_ERROR, "Assert", "Assertion Failed (Line " & $sLine & "): " & @CRLF & @CRLF & $sMsg)
		If $bExit Then Exit $nCode
	EndIf
	Return $bCondition
EndFunc	; _Assert()

Note, $MB_ERROR is:

Global Const $MB_ERROR = 4096 + 16	; Standard error flags (Stop icon)

comment:3 by J-Paul Mesnage, 17 years ago

Milestone: 3.3.1.0
Owner: set to J-Paul Mesnage
Resolution: Completed
Status: newclosed

Added in version: 3.3.1.0

Modify Ticket

Action
as closed The owner will remain J-Paul Mesnage.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.