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

Use an AA to index test suites #287

Merged
merged 3 commits into from
Jul 1, 2024
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
27 changes: 6 additions & 21 deletions bsc-plugin/src/lib/rooibos/RooibosSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,7 @@ export class RooibosSession {
let classStatement = (runtimeConfig.ast.statements[0] as NamespaceStatement).body.statements[0] as ClassStatement;
this.updateRunTimeConfigFunction(classStatement, editor);
this.updateVersionTextFunction(classStatement, editor);
this.updateClassLookupFunction(classStatement, editor);
this.updateGetAllTestSuitesNames(classStatement, editor);
this.updateClassMapFunction(classStatement, editor);
this.createIgnoredTestsInfoFunction(classStatement, editor);
}
}
Expand Down Expand Up @@ -191,32 +190,18 @@ export class RooibosSession {
}
}

updateClassLookupFunction(classStatement: ClassStatement, editor: AstEditor) {
let method = classStatement.methods.find((m) => m.name.text === 'getTestSuiteClassWithName');
updateClassMapFunction(classStatement: ClassStatement, editor: AstEditor) {
let method = classStatement.methods.find((m) => m.name.text === 'getTestSuiteClassMap');
if (method) {
editor.arrayPush(method.func.body.statements, ...Parser.parse(undent`
if false
? "noop" ${this.sessionInfo.testSuitesToRun.map(suite => `
else if name = "${suite.name}"
return ${suite.classStatement.getName(ParseMode.BrightScript)}`).join('')}
end if
return {${this.sessionInfo.testSuitesToRun.map(suite => `
"${suite.name}": ${suite.classStatement.getName(ParseMode.BrightScript)}`).join('')}
}
`).ast.statements);
}
}

updateGetAllTestSuitesNames(classStatement: ClassStatement, editor: AstEditor) {
let method = classStatement.methods.find((m) => m.name.text === 'getAllTestSuitesNames');
if (method) {
editor.arrayPush(method.func.body.statements, ...Parser.parse([
'return [',
...this.sessionInfo.testSuitesToRun.map((s) => ` "${s.name}"`),
']'
].join('\n')).ast.statements);
}
}

createNodeFiles(program: Program) {

for (let suite of this.sessionInfo.testSuitesToRun.filter((s) => s.isNodeTest)) {
this.createNodeFile(program, suite);
}
Expand Down
1 change: 1 addition & 0 deletions bsc-plugin/src/lib/rooibos/RooibosSessionInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ export class SessionInfo {
}
}
this.testSuitesToRun = [...this.testSuites.values()].filter((s) => s.isIncluded);
this.testSuitesToRun.sort((a, b) => a.name.localeCompare(b.name));
}

isExcludedByTag(item: TestCase | TestGroup | TestSuite, isParentIncluded) {
Expand Down
44 changes: 21 additions & 23 deletions bsc-plugin/src/plugin.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2031,8 +2031,7 @@ describe('RooibosPlugin', () => {
//the methods should be empty by default
expect(findMethod('getVersionText').func.body.statements).to.be.empty;
expect(findMethod('getRuntimeConfig').func.body.statements).to.be.empty;
expect(findMethod('getTestSuiteClassWithName').func.body.statements).to.be.empty;
expect(findMethod('getAllTestSuitesNames').func.body.statements).to.be.empty;
expect(findMethod('getTestSuiteClassMap').func.body.statements).to.be.empty;
expect(findMethod('getIgnoredTestInfo').func.body.statements).to.be.empty;

await builder.transpile();
Expand Down Expand Up @@ -2062,8 +2061,9 @@ describe('RooibosPlugin', () => {
).to.eql(undent`
function __rooibos_RuntimeConfig_builder()
instance = {}
instance.new = sub()
end sub
instance.new = function()
m.testSuites = m.getTestSuiteClassMap()
end function
instance.getVersionText = function()
return "${version}"
end function
Expand All @@ -2086,20 +2086,17 @@ describe('RooibosPlugin', () => {
"isRecordingCodeCoverage": false
}
end function
instance.getTestSuiteClassMap = function()
return {
"ATest1": ATest1
"ATest2": ATest2
}
end function
instance.getTestSuiteClassWithName = function(name)
if false
? "noop"
else if name = "ATest1"
return ATest1
else if name = "ATest2"
return ATest2
end if
return m.testSuites[name]
end function
instance.getAllTestSuitesNames = function()
return [
"ATest1"
"ATest2"
]
return m.testSuites.keys()
end function
instance.getIgnoredTestInfo = function()
return {
Expand All @@ -2119,8 +2116,7 @@ describe('RooibosPlugin', () => {
//the methods should be empty again after transpile has finished
expect(findMethod('getVersionText').func.body.statements).to.be.empty;
expect(findMethod('getRuntimeConfig').func.body.statements).to.be.empty;
expect(findMethod('getTestSuiteClassWithName').func.body.statements).to.be.empty;
expect(findMethod('getAllTestSuitesNames').func.body.statements).to.be.empty;
expect(findMethod('getTestSuiteClassMap').func.body.statements).to.be.empty;
expect(findMethod('getIgnoredTestInfo').func.body.statements).to.be.empty;
});

Expand Down Expand Up @@ -2152,8 +2148,9 @@ describe('RooibosPlugin', () => {
).to.eql(undent`
function __rooibos_RuntimeConfig_builder()
instance = {}
instance.new = sub()
end sub
instance.new = function()
m.testSuites = m.getTestSuiteClassMap()
end function
instance.getVersionText = function()
return "${version}"
end function
Expand All @@ -2176,13 +2173,14 @@ describe('RooibosPlugin', () => {
"isRecordingCodeCoverage": false
}
end function
instance.getTestSuiteClassMap = function()
return {}
end function
instance.getTestSuiteClassWithName = function(name)
if false
? "noop"
end if
return m.testSuites[name]
end function
instance.getAllTestSuitesNames = function()
return []
return m.testSuites.keys()
end function
instance.getIgnoredTestInfo = function()
return {
Expand Down
2 changes: 1 addition & 1 deletion framework/src/source/BaseTestSuite.bs
Original file line number Diff line number Diff line change
Expand Up @@ -1908,7 +1908,7 @@ namespace rooibos
' m.currentResult.fail("Setting up mock failed: " + error.message, m.currentAssertLineNumber)
' return false
' end try
return false
' return false
end function

' /**
Expand Down
9 changes: 9 additions & 0 deletions framework/src/source/RuntimeConfig.bs
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
namespace rooibos
class RuntimeConfig

function new()
m.testSuites = m.getTestSuiteClassMap()
end function

function getVersionText()
end function

function getRuntimeConfig()
end function

function getTestSuiteClassMap()
end function

function getTestSuiteClassWithName(name)
return m.testSuites[name]
end function

function getAllTestSuitesNames()
return m.testSuites.keys()
end function

function getIgnoredTestInfo()
Expand Down