Skip to content

Commit

Permalink
Added an api to fail tests with an exception (#263)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisdp authored Jan 24, 2024
1 parent 4170974 commit 71ebf84
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
22 changes: 22 additions & 0 deletions framework/src/source/BaseTestSuite.bs
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,28 @@ namespace rooibos
return false
end function

' /**
' * @memberof module:BaseTestSuite
' * @name failCrash
' * @function
' * @instance
' * @description Fail immediately, with the given exception
' * @param {Dynamic} [error] - exception to fail on
' * @param {Dynamic} [msg=""] - message to display in the test report
' * @returns {boolean} - true if failure was set, false if the test is already failed
' */
function failCrash(error as dynamic, msg = "Error" as string) as dynamic
if m.currentResult.isFail
if m.throwOnFailedAssertion
throw m.currentResult.getMessage()
end if
return false
end if
m.currentResult.fail(msg, m.currentAssertLineNumber)
m.currentResult.crash(msg, error)
return true
end function

function failBecauseOfTimeOut() as dynamic
if m.currentResult.isFail
return false
Expand Down
17 changes: 17 additions & 0 deletions tests/src/source/Assertion.spec.bs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,23 @@ namespace tests
m.assertTrue(isFail)
end function

@it("FailCrash")
function _()

try
result = 2 / 0
catch e
m.failCrash(e)
end try

isFail = m.currentResult.isFail
isCrash = m.currentResult.isCrash
m.currentResult.Reset()

m.assertTrue(isCrash)
m.assertTrue(isFail)
end function

@it("AssertTrue")
@params(true, true)
@params(false, false)
Expand Down

0 comments on commit 71ebf84

Please sign in to comment.