Modify

Opened 16 years ago

Closed 16 years ago

Last modified 5 years ago

#957 closed Feature Request (Completed)

Assert keyword or function

Reported by: Nutster Owned by: Jpm
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 Changed 16 years ago by TicketCleanup

  • Version 3.3.0.0 deleted

Automatic ticket cleanup.

comment:2 Changed 16 years ago by Valik

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 Changed 16 years ago by Jpm

  • Milestone set to 3.3.1.0
  • Owner set to Jpm
  • Resolution set to Completed
  • Status changed from new to closed

Added in version: 3.3.1.0

Guidelines for posting comments:

  • You cannot re-open a ticket but you may still leave a comment if you have additional information to add.
  • In-depth discussions should take place on the forum.

For more information see the full version of the ticket guidelines here.

Add Comment

Modify Ticket

Action
as closed The owner will remain Jpm.
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.