Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Asserting Err Object #24

Closed
robodude666 opened this issue Aug 29, 2018 · 1 comment
Closed

Asserting Err Object #24

robodude666 opened this issue Aug 29, 2018 · 1 comment

Comments

@robodude666
Copy link

It would be useful to be able to assert the Err object and ensure that either no error occurred as expected, or that the expected error was called:

With Suite.Test("calling AcceptsLongsOnly with a long should not raise an error")
	On Error Resume Next
	Err.Clear
	MyModule.AcceptsLongsOnly 123
	.ToNotBeError Err
	On Error GoTo 0
End With

With Suite.Test("calling AcceptsLongsOnly with non-longs should raise an error")
	On Error Resume Next
	Err.Clear
	MyModule.AcceptsLongsOnly "ABC"
	.ToBeError Err, vbObjectError + 10001, "Expected value to be Long."
	On Error GoTo 0

	On Error Resume Next
	Err.Clear
	MyModule.AcceptsLongsOnly True
	.ToBeError Err, vbObjectError + 10001, "Expected value to be Long."
	On Error GoTo 0
End With

Of course, the naming of ToNotBeError and ToBeError are only examples. It may be possible to build them into IsOk and NotOk, but I'd prefer a dedicated method with Err or Error in the name for clarity.

@timhall
Copy link
Member

timhall commented Aug 29, 2018

Thanks for the suggestion, I've added IsError and NotError. I tried passing in Err, but it converts it to just the error number when you pass it around, so instead they just check the current global Err.

.IsError
.IsError vbObjectError + 1
.IsError Source:="..."
.IsError Description:="..."
.IsError vbObjectError + 1, "Source", "Description"

.NotError

Closed by d58af6e

@timhall timhall closed this as completed Aug 29, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants