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

Fix nested assertions causing compilation error when using sub _ #314

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bsc-plugin/src/lib/rooibos/TestGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export class TestGroup extends TestBlock {
let callExpression = expressionStatement.expression as CallExpression;
if (brighterscript.isCallExpression(callExpression) && brighterscript.isDottedGetExpression(callExpression.callee)) {
let dge = callExpression.callee;
let isSub = isFunctionExpression(callExpression.parent.parent.parent) && callExpression.parent.parent.parent.functionType.kind === TokenKind.Sub;
let isSub = callExpression.findAncestor<brighterscript.FunctionExpression>(isFunctionExpression)?.functionType.kind === TokenKind.Sub;
let assertRegex = /(?:fail|assert(?:[a-z0-9]*)|expect(?:[a-z0-9]*)|stubCall)/i;
if (dge && assertRegex.test(dge.name.text)) {
if (dge.name.text === 'stubCall') {
Expand Down
85 changes: 83 additions & 2 deletions bsc-plugin/src/plugin.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,24 @@ describe('RooibosPlugin', () => {
@it("is test1")
@slow(1000)
function Test_3()
m.assertEqual(1, 1)
if 1 = 1
m.assertEqual(2, 2)
if 2 = 2
m.assertTrue(false)
end if
end if
end function
@it("is test2")
sub Test_4()
m.assertEqual(1, 1)
if 1 = 1
m.assertEqual(2, 2)
if 2 = 2
m.assertTrue(false)
end if
end if
end sub
end class
`);
program.validate();
Expand All @@ -680,7 +697,7 @@ describe('RooibosPlugin', () => {
expect(plugin.session.sessionInfo.testSuitesToRun).to.not.be.empty;
expect(plugin.session.sessionInfo.suitesCount).to.equal(1);
expect(plugin.session.sessionInfo.groupsCount).to.equal(1);
expect(plugin.session.sessionInfo.testsCount).to.equal(1);
expect(plugin.session.sessionInfo.testsCount).to.equal(2);

expect(
getContents('rooibosMain.brs')
Expand All @@ -699,7 +716,53 @@ describe('RooibosPlugin', () => {
m.super0_new()
end sub
instance.groupA_is_test1 = function()
end function
m.currentAssertLineNumber = 8
m.assertEqual(1, 1)
if m.currentResult?.isFail = true then
m.done()
return invalid
end if
if 1 = 1
m.currentAssertLineNumber = 10
m.assertEqual(2, 2)
if m.currentResult?.isFail = true then
m.done()
return invalid
end if
if 2 = 2
m.currentAssertLineNumber = 12
m.assertTrue(false)
if m.currentResult?.isFail = true then
m.done()
return invalid
end if
end if
end if
end function
instance.groupA_is_test2 = sub()
m.currentAssertLineNumber = 18
m.assertEqual(1, 1)
if m.currentResult?.isFail = true then
m.done()
return
end if
if 1 = 1
m.currentAssertLineNumber = 20
m.assertEqual(2, 2)
if m.currentResult?.isFail = true then
m.done()
return
end if
if 2 = 2
m.currentAssertLineNumber = 22
m.assertTrue(false)
if m.currentResult?.isFail = true then
m.done()
return
end if
end if
end if
end sub
instance.super0_getTestSuiteData = instance.getTestSuiteData
instance.getTestSuiteData = function()
return {
Expand Down Expand Up @@ -756,6 +819,24 @@ describe('RooibosPlugin', () => {
expectedNumberOfParams: 0
isParamsValid: true
}
{
isSolo: false
noCatch: false
funcName: "groupA_is_test2"
isIgnored: false
isAsync: false
asyncTimeout: 2000
slow: 75
isParamTest: false
name: "is test2"
lineNumber: 17
paramLineNumber: 0
assertIndex: 0
rawParams: invalid
paramTestIndex: 0
expectedNumberOfParams: 0
isParamsValid: true
}
]
}
]
Expand Down