From 2f703ea3cc9c7f8716192d63d58d0a27b8a75d7c Mon Sep 17 00:00:00 2001 From: Christopher Dwyer-Perkins Date: Sat, 10 Feb 2024 15:00:27 -0400 Subject: [PATCH 1/5] Prep work for more detailed lcov reports --- framework/src/source/BaseTestSuite.bs | 1 + framework/src/source/CodeCoverage.brs | 35 +++++++++++++++++++++++++++ framework/src/source/CodeCoverage.xml | 2 ++ 3 files changed, 38 insertions(+) diff --git a/framework/src/source/BaseTestSuite.bs b/framework/src/source/BaseTestSuite.bs index 5a031091..f7b5e810 100644 --- a/framework/src/source/BaseTestSuite.bs +++ b/framework/src/source/BaseTestSuite.bs @@ -262,6 +262,7 @@ namespace rooibos ? ` Location: file://${test.testSuite.filePath.trim()}:${test.lineNumber}` ? "" + m.global._rbs_ccn.testName = test.name m.currentResult = test.result m.currentResult.throwOnFailedAssertion = m.throwOnFailedAssertion if m.catchCrashes and not test.noCatch and not m.noCatch diff --git a/framework/src/source/CodeCoverage.brs b/framework/src/source/CodeCoverage.brs index 8bb7d5e0..38d47c18 100644 --- a/framework/src/source/CodeCoverage.brs +++ b/framework/src/source/CodeCoverage.brs @@ -1,7 +1,11 @@ +#const rooibos_poc_enhanced_lcov_support = false + function init() m.resolvedMap = {} + m.resolvedTestMap = {} m.top.observeField("entry", "onEntryChange") m.top.observeField("save", "onSave") + m.resultsByTest = {} m.results = [] end function @@ -16,6 +20,17 @@ end function function onEntryChange() entry = m.top.entry ' defer till later + + #if rooibos_poc_enhanced_lcov_support + testName = m.top.testName + if testName <> "" + if not m.resultsByTest.doesExist(testName) + m.resultsByTest[testName] = [] + end if + m.resultsByTest[testName].push(entry) + end if + #end if + m.results.push(entry) end function @@ -34,6 +49,26 @@ function onSave() end if end for m.top.resolvedMap = m.resolvedMap + + #if rooibos_poc_enhanced_lcov_support + for each testName in m.resultsByTest + resolvedTest = m.resultsByTest[testName] + m.resolvedTestMap[testName] = {} + for each entry in resolvedTest + if entry <> invalid + fileId = entry.f + lineMap = m.resolvedTestMap[testName][fileId] + + if lineMap = invalid + lineMap = {} + m.resolvedTestMap[testName][fileId] = lineMap + end if + lineMap[entry.l] = entry.r + end if + end for + end for + m.top.resolvedTestMap = m.resolvedTestMap + #end if setExpectedMap() setFilePathMap() end function \ No newline at end of file diff --git a/framework/src/source/CodeCoverage.xml b/framework/src/source/CodeCoverage.xml index e948d05f..3aaff6ee 100644 --- a/framework/src/source/CodeCoverage.xml +++ b/framework/src/source/CodeCoverage.xml @@ -6,8 +6,10 @@ + + From 73b4d95520477aa9dd562a000e8cae9517d68803 Mon Sep 17 00:00:00 2001 From: Christopher Dwyer-Perkins Date: Sat, 10 Feb 2024 15:01:20 -0400 Subject: [PATCH 2/5] Fixed some crashes and socket flooding issues in lcov --- framework/src/source/Coverage.bs | 41 +++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/framework/src/source/Coverage.bs b/framework/src/source/Coverage.bs index 1fac97e7..1a989bf4 100644 --- a/framework/src/source/Coverage.bs +++ b/framework/src/source/Coverage.bs @@ -72,7 +72,7 @@ namespace rooibos.Coverage ? "+++++++++++++++++++++++++++++++++++++++++++" end function - function createLCovOutput() + function createLCovOutput(logToConsole = true as boolean) ? "Generating lcov.info file..." cc = m.global._rbs_ccn @@ -80,9 +80,10 @@ namespace rooibos.Coverage filePathMap = cc.filePathMap resolvedMap = cc.resolvedMap - buffer = "" + results = [] for each module in filePathMap.items() + buffer = "" moduleNumber = module.key filePath = module.value packageName = "." @@ -90,33 +91,51 @@ namespace rooibos.Coverage 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 From d59ba42ed628fab8dac2dd9b20917ca1ca89d1d2 Mon Sep 17 00:00:00 2001 From: Christopher Dwyer-Perkins Date: Tue, 13 Feb 2024 14:21:31 -0400 Subject: [PATCH 3/5] Apply suggestions from code review --- framework/src/source/BaseTestSuite.bs | 1 - framework/src/source/CodeCoverage.brs | 35 --------------------------- framework/src/source/CodeCoverage.xml | 2 -- 3 files changed, 38 deletions(-) diff --git a/framework/src/source/BaseTestSuite.bs b/framework/src/source/BaseTestSuite.bs index f7b5e810..5a031091 100644 --- a/framework/src/source/BaseTestSuite.bs +++ b/framework/src/source/BaseTestSuite.bs @@ -262,7 +262,6 @@ namespace rooibos ? ` Location: file://${test.testSuite.filePath.trim()}:${test.lineNumber}` ? "" - m.global._rbs_ccn.testName = test.name m.currentResult = test.result m.currentResult.throwOnFailedAssertion = m.throwOnFailedAssertion if m.catchCrashes and not test.noCatch and not m.noCatch diff --git a/framework/src/source/CodeCoverage.brs b/framework/src/source/CodeCoverage.brs index 38d47c18..8bb7d5e0 100644 --- a/framework/src/source/CodeCoverage.brs +++ b/framework/src/source/CodeCoverage.brs @@ -1,11 +1,7 @@ -#const rooibos_poc_enhanced_lcov_support = false - function init() m.resolvedMap = {} - m.resolvedTestMap = {} m.top.observeField("entry", "onEntryChange") m.top.observeField("save", "onSave") - m.resultsByTest = {} m.results = [] end function @@ -20,17 +16,6 @@ end function function onEntryChange() entry = m.top.entry ' defer till later - - #if rooibos_poc_enhanced_lcov_support - testName = m.top.testName - if testName <> "" - if not m.resultsByTest.doesExist(testName) - m.resultsByTest[testName] = [] - end if - m.resultsByTest[testName].push(entry) - end if - #end if - m.results.push(entry) end function @@ -49,26 +34,6 @@ function onSave() end if end for m.top.resolvedMap = m.resolvedMap - - #if rooibos_poc_enhanced_lcov_support - for each testName in m.resultsByTest - resolvedTest = m.resultsByTest[testName] - m.resolvedTestMap[testName] = {} - for each entry in resolvedTest - if entry <> invalid - fileId = entry.f - lineMap = m.resolvedTestMap[testName][fileId] - - if lineMap = invalid - lineMap = {} - m.resolvedTestMap[testName][fileId] = lineMap - end if - lineMap[entry.l] = entry.r - end if - end for - end for - m.top.resolvedTestMap = m.resolvedTestMap - #end if setExpectedMap() setFilePathMap() end function \ No newline at end of file diff --git a/framework/src/source/CodeCoverage.xml b/framework/src/source/CodeCoverage.xml index 3aaff6ee..e948d05f 100644 --- a/framework/src/source/CodeCoverage.xml +++ b/framework/src/source/CodeCoverage.xml @@ -6,10 +6,8 @@ - - From 8f97e91a39ad079b03fe162abdbf2ff61ece0a6a Mon Sep 17 00:00:00 2001 From: Christopher Dwyer-Perkins Date: Tue, 13 Feb 2024 14:34:56 -0400 Subject: [PATCH 4/5] Fixed code cov report always printing --- bsc-plugin/src/lib/rooibos/RooibosSession.ts | 3 ++- framework/src/source/TestRunner.bs | 4 +--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/bsc-plugin/src/lib/rooibos/RooibosSession.ts b/bsc-plugin/src/lib/rooibos/RooibosSession.ts index e1f31017..bbbac930 100644 --- a/bsc-plugin/src/lib/rooibos/RooibosSession.ts +++ b/bsc-plugin/src/lib/rooibos/RooibosSession.ts @@ -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) { @@ -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] ); diff --git a/framework/src/source/TestRunner.bs b/framework/src/source/TestRunner.bs index 07bc9135..93517cfd 100644 --- a/framework/src/source/TestRunner.bs +++ b/framework/src/source/TestRunner.bs @@ -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 From 6875bac8257851ee3db10ce7991e041360366a01 Mon Sep 17 00:00:00 2001 From: Christopher Dwyer-Perkins Date: Tue, 13 Feb 2024 14:38:09 -0400 Subject: [PATCH 5/5] fixed a failing test --- bsc-plugin/src/plugin.spec.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/bsc-plugin/src/plugin.spec.ts b/bsc-plugin/src/plugin.spec.ts index 009a2b69..c4d66044 100644 --- a/bsc-plugin/src/plugin.spec.ts +++ b/bsc-plugin/src/plugin.spec.ts @@ -2103,6 +2103,7 @@ describe('RooibosPlugin', () => { "catchCrashes": true "throwOnFailedAssertion": false "keepAppOpen": true + "isRecordingCodeCoverage": false } end function instance.getTestSuiteClassWithName = function(name)