Skip to content

Commit

Permalink
Merge pull request #274 from georgejecook/lcov-fixes-and-improvments
Browse files Browse the repository at this point in the history
Lcov fixes
  • Loading branch information
chrisdp authored Feb 13, 2024
2 parents 9471f48 + 6875bac commit 7265306
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 15 deletions.
3 changes: 2 additions & 1 deletion bsc-plugin/src/lib/rooibos/RooibosSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export class RooibosSession {
prepareForTranspile(editor: AstEditor, program: Program, mockUtil: MockUtil) {
this.addTestRunnerMetadata(editor);
this.addLaunchHookToExistingMain(editor);

// Make sure to create the node files before running the global mock logic
// We realy on them in order to check the component scope for the global functions
for (let testSuite of this.sessionInfo.testSuitesToRun) {
Expand Down Expand Up @@ -149,6 +149,7 @@ export class RooibosSession {
"catchCrashes": ${this.config.catchCrashes ? 'true' : 'false'}
"throwOnFailedAssertion": ${this.config.throwOnFailedAssertion ? 'true' : 'false'}
"keepAppOpen": ${this.config.keepAppOpen === undefined || this.config.keepAppOpen ? 'true' : 'false'}
"isRecordingCodeCoverage": ${this.config.isRecordingCodeCoverage ? 'true' : 'false'}
}
`).ast.statements[0]
);
Expand Down
1 change: 1 addition & 0 deletions bsc-plugin/src/plugin.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2103,6 +2103,7 @@ describe('RooibosPlugin', () => {
"catchCrashes": true
"throwOnFailedAssertion": false
"keepAppOpen": true
"isRecordingCodeCoverage": false
}
end function
instance.getTestSuiteClassWithName = function(name)
Expand Down
41 changes: 30 additions & 11 deletions framework/src/source/Coverage.bs
Original file line number Diff line number Diff line change
Expand Up @@ -72,51 +72,70 @@ namespace rooibos.Coverage
? "+++++++++++++++++++++++++++++++++++++++++++"
end function

function createLCovOutput()
function createLCovOutput(logToConsole = true as boolean)
? "Generating lcov.info file..."

cc = m.global._rbs_ccn
expectedMap = cc.expectedMap
filePathMap = cc.filePathMap
resolvedMap = cc.resolvedMap

buffer = ""
results = []

for each module in filePathMap.items()
buffer = ""
moduleNumber = module.key
filePath = module.value
packageName = "."

relativePath = filePath.replace("pkg:", packageName)
sanitizedPath = relativePath.replace("\\", "/")

buffer = buffer + "TN:" + chr(10)
buffer = buffer + "SF:" + sanitizedPath + chr(10)
buffer += "TN:" + chr(10)
buffer += "SF:" + sanitizedPath + chr(10)

for each expected in expectedMap[moduleNumber]
lineNumber = expected[0]
lineNumber = val(expected)
SHIFT = 1

if resolvedMap[moduleNumber] <> invalid and resolvedMap[moduleNumber].doesExist(str(lineNumber))
buffer = buffer + "DA:" + str(lineNumber + SHIFT) + ",1" + chr(10)
if resolvedMap[moduleNumber] <> invalid and resolvedMap[moduleNumber].doesExist(expected)
buffer += "DA:" + str(lineNumber + SHIFT).trim() + "," + str(resolvedMap[moduleNumber][expected]).trim() + chr(10)
else
buffer = buffer + "DA:" + str(lineNumber + SHIFT) + ",0" + chr(10)
buffer += "DA:" + str(lineNumber + SHIFT).trim() + ",0" + chr(10)
end if
end for

buffer = buffer + "end_of_record" + chr(10)
buffer += "LF:" + str(expectedMap[moduleNumber].count()).trim() + chr(10)

if resolvedMap[moduleNumber] <> invalid
buffer += "LH:" + str(resolvedMap[moduleNumber].count()).trim() + chr(10)
else
buffer += "LH:0" + chr(10)
end if

buffer += "end_of_record"
if logToConsole
? buffer
' When logging to the console it is very possible to flood the buffer and cause the application to exit.
' Sleep for a short amount of time so as to give console scrapers time to empty the buffer
sleep(30)
else
results.push(buffer)
end if
end for
return buffer

return results.join(chr(10))
end function

function printLCovInfo()

?
? "+++++++++++++++++++++++++++++++++++++++++++"
? "LCOV.INFO FILE"
? "+++++++++++++++++++++++++++++++++++++++++++"
?
? "+-=-coverage:start"
? rooibos.coverage.createLCovOutput()
rooibos.coverage.createLCovOutput()
? "+-=-coverage:end"
end function

Expand Down
4 changes: 1 addition & 3 deletions framework/src/source/TestRunner.bs
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,7 @@ namespace rooibos
}
m.nodeContext.global.testsScene.rooibosTestResult = rooibosResult

'bs:disable-next-line
if rooibos.common.isFunction(rooibos.Coverage.reportCodeCoverage)
'bs:disable-next-line
if m.config.isRecordingCodeCoverage
rooibos.Coverage.reportCodeCoverage()

if m.config.printLcov = true
Expand Down

0 comments on commit 7265306

Please sign in to comment.