Skip to content

Commit

Permalink
Added a config value to crash when a assert fails (#248)
Browse files Browse the repository at this point in the history
brilliant idea, thanks!
  • Loading branch information
chrisdp authored Jan 6, 2024
1 parent f322b9a commit 8e08407
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 7 deletions.
1 change: 1 addition & 0 deletions bsc-plugin/src/lib/rooibos/RooibosConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export interface RooibosConfig {
includeFilters?: string[];
tags?: string[];
catchCrashes?: boolean;
throwOnFailedAssertion?: boolean;
sendHomeOnFinish?: boolean;
reporter?: string;
keepAppOpen?: boolean;
Expand Down
1 change: 1 addition & 0 deletions bsc-plugin/src/lib/rooibos/RooibosSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ export class RooibosSession {
"printLcov": ${this.config.printLcov ? 'true' : 'false'}
"port": "${this.config.port || 'invalid'}"
"catchCrashes": ${this.config.catchCrashes ? 'true' : 'false'}
"throwOnFailedAssertion": ${this.config.throwOnFailedAssertion ? 'true' : 'false'}
"keepAppOpen": ${this.config.keepAppOpen === undefined || this.config.keepAppOpen ? 'true' : 'false'}
}`
)
Expand Down
2 changes: 2 additions & 0 deletions bsc-plugin/src/plugin.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1610,6 +1610,7 @@ describe('RooibosPlugin', () => {
"printLcov": false
"port": "invalid"
"catchCrashes": true
"throwOnFailedAssertion": false
"keepAppOpen": true
}
end function
Expand Down Expand Up @@ -1671,6 +1672,7 @@ describe('RooibosPlugin', () => {
'rooibos': {
'showOnlyFailures': true,
'catchCrashes': true,
'throwOnFailedAssertion': false,
'lineWidth': 70,
'failFast': false,
'sendHomeOnFinish': false,
Expand Down
3 changes: 3 additions & 0 deletions bsc-plugin/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ export class RooibosPlugin implements CompilerPlugin {
if (config.catchCrashes === undefined) {
config.catchCrashes = true;
}
if (config.throwOnFailedAssertion === undefined) {
config.throwOnFailedAssertion = false;
}
if (config.sendHomeOnFinish === undefined) {
config.sendHomeOnFinish = true;
}
Expand Down
1 change: 1 addition & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ Here is the information converted into a Markdown table:
| printTestTimes? | boolean | If true, then the time each test took is output |
| lineWidth? | number | Width of test output lines in columns |
| catchCrashes? | boolean | If true, then any crashes will report CRASH statement, and note halt test execution - very useful for running a whole suite |
| throwOnFailedAssertion? | boolean | If true, then any failure will result in a runtime crash. Very useful for inspecting the stack frames and jumping right to the first failed test. |
| sendHomeOnFinish? | boolean | If true, then the app will exit upon finish. The default is true. Useful to set to false for local test suites |
| keepAppOpen? | boolean | When true, the app will remain open upon test completion. The default is true. Set false to return execution to Main |
| testsFilePattern? | string | The pattern to use to find tests. This is a glob. The default is "**/*.spec.bs" |
Expand Down
19 changes: 12 additions & 7 deletions framework/src/source/BaseTestSuite.bs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ namespace rooibos

protected global = invalid
protected catchCrashes = false
protected throwOnFailedAssertion = false

'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
'++ base methods to override
Expand Down Expand Up @@ -262,6 +263,7 @@ namespace rooibos
? ""

m.currentResult = test.result
m.currentResult.throwOnFailedAssertion = m.throwOnFailedAssertion
if m.catchCrashes and not test.noCatch and not m.noCatch
try
test.run()
Expand Down Expand Up @@ -302,6 +304,9 @@ namespace rooibos
' */
function fail(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)
Expand Down Expand Up @@ -1850,15 +1855,15 @@ namespace rooibos
' * @returns {Object} - mock that was wired into the real method
' */
function expectOnce(target, methodName, expectedArgs = invalid, returnValue = invalid, allowNonExistingMethods = false) as object
'HACK
'HACK
'HACK
'HACK
'HACK
'HACK
'HACK
'HACK
'HACK
'HACK
' try
return m.mock(target, methodName, 1, expectedArgs, returnValue, allowNonExistingMethods)
return m.mock(target, methodName, 1, expectedArgs, returnValue, allowNonExistingMethods)
' catch error
'bs:disable-next-line
'bs:disable-next-line
' m.currentResult.fail("Setting up mock failed: " + error.message, m.currentAssertLineNumber)
' return false
' end try
Expand Down
4 changes: 4 additions & 0 deletions framework/src/source/TestResult.bs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ namespace rooibos
public test = invalid
public time = 0
public error = invalid
public throwOnFailedAssertion = false

function new(test)
m.test = test
Expand Down Expand Up @@ -38,6 +39,9 @@ namespace rooibos
m.message = message
end if
end if
if m.throwOnFailedAssertion
throw m.getMessage()
end if
end function

function crash(message as string, error)
Expand Down
2 changes: 2 additions & 0 deletions framework/src/source/TestRunner.bs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ namespace rooibos
testSuite.top = m.nodeContext.top
testSuite.scene = m.nodeContext.global.testsScene
testSuite.catchCrashes = m.config.catchCrashes
testSuite.throwOnFailedAssertion = m.config.throwOnFailedAssertion
testSuite.scene.testText = `Running Suite ${i} of ${numSuites}: ${name}`
m.runTestSuite(testSuite)
if m.stats.hasFailures = true
Expand Down Expand Up @@ -138,6 +139,7 @@ namespace rooibos
testSuite.top = m.nodeContext.top
testSuite.scene = m.nodeContext.global.testsScene
testSuite.catchCrashes = m.config.catchCrashes
testSuite.throwOnFailedAssertion = m.config.throwOnFailedAssertion
m.nodeContext.testSuite = testSuite
m.nodeTestName = nodeTestName
m.nodeContext.testRunner = m
Expand Down

0 comments on commit 8e08407

Please sign in to comment.