Skip to content

Is it possible to check if an error was raised? #239

Answered by MikeSchulze
stephannv asked this question in Q&A
Discussion options

You must be logged in to vote

Ok, if I understand you correctly, you want to test if a certain call generates an error and test for it.

class MyClass:
	
	func foo(value :int):
		match value:
			1: assert(false, "foo failed")
			2: push_error("foo failed")

func test_foo():
	assert_error(func(): 
		MyClass.new().foo(0) # success
	).is_success()

	assert_error(func(): 
		MyClass.new().foo(1) # fails by an assert
	).is_failed().has_message("foo failed")
	
	assert_error(func(): 
		MyClass.new().foo(2) # fails by an push_error
	).is_failed().has_message("foo failed")

sorry, for this kind of scenario no asserts exists at the moment, feel free to create a feature request

Replies: 3 comments 7 replies

Comment options

You must be logged in to vote
5 replies
@stephannv
Comment options

@MikeSchulze
Comment options

@stephannv
Comment options

@MikeSchulze
Comment options

@stephannv
Comment options

Comment options

You must be logged in to vote
1 reply
@stephannv
Comment options

Answer selected by stephannv
Comment options

You must be logged in to vote
1 reply
@stephannv
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
help wanted Extra attention is needed clarified
2 participants