From bea35b5996a346421c2841f0ad7def7554591b89 Mon Sep 17 00:00:00 2001 From: Sam Heavner Date: Fri, 9 Feb 2024 16:01:47 -0700 Subject: [PATCH 1/3] Fix missing expected lines in code coverage fixes >100% coverage reporting - add all `getFuncCallText` to coverageMap recording - format `expectedCoverageMap` keys as key:value objects instead of arrays to match reporting Note: this doesn't add full branch tracking, but at least stops the incorrect percentage stats --- bsc-plugin/src/lib/rooibos/CodeCoverageProcessor.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/bsc-plugin/src/lib/rooibos/CodeCoverageProcessor.ts b/bsc-plugin/src/lib/rooibos/CodeCoverageProcessor.ts index d065db1..b0a4848 100644 --- a/bsc-plugin/src/lib/rooibos/CodeCoverageProcessor.ts +++ b/bsc-plugin/src/lib/rooibos/CodeCoverageProcessor.ts @@ -157,8 +157,11 @@ export class CodeCoverageProcessor { } }), { walkMode: WalkMode.visitAllRecursive }); - - this.expectedCoverageMap[this.fileId.toString().trim()] = Array.from(this.coverageMap); + const coverageMapObject = {}; + for (let key of this.coverageMap.keys()) { + coverageMapObject[key] = this.coverageMap.get(key); + } + this.expectedCoverageMap[this.fileId.toString().trim()] = coverageMapObject; this.filePathMap[this.fileId] = file.pkgPath; this.addBrsAPIText(file, astEditor); } @@ -188,6 +191,7 @@ export class CodeCoverageProcessor { } private getFuncCallText(lineNumber: number, lineType: CodeCoverageLineType) { + this.coverageMap.set(lineNumber, lineType); return `RBS_CC_${this.fileId}_reportLine("${lineNumber.toString().trim()}", ${lineType.toString().trim()})`; } } From 82e088e410a8996b1084e64c66d47b4bfc1b9a4f Mon Sep 17 00:00:00 2001 From: Christopher Dwyer-Perkins Date: Fri, 9 Feb 2024 21:28:01 -0400 Subject: [PATCH 2/3] Added some samples that would result in more then 100 percent covrage before the fix --- tests/bsconfig.json | 3 ++- tests/src/source/CodeCoverage.bs | 36 +++++++++++++++++++++++++++ tests/src/source/CodeCoverage.spec.bs | 15 +++++++++++ 3 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 tests/src/source/CodeCoverage.bs create mode 100644 tests/src/source/CodeCoverage.spec.bs diff --git a/tests/bsconfig.json b/tests/bsconfig.json index ce469c4..08ba2e3 100644 --- a/tests/bsconfig.json +++ b/tests/bsconfig.json @@ -32,7 +32,8 @@ "failFast": false, "sendHomeOnFinish": false, "keepAppOpen": true, - "isGlobalMethodMockingEnabled": true + "isGlobalMethodMockingEnabled": true, + "isRecordingCodeCoverage": false }, "sourceMap": true } \ No newline at end of file diff --git a/tests/src/source/CodeCoverage.bs b/tests/src/source/CodeCoverage.bs new file mode 100644 index 0000000..960ead8 --- /dev/null +++ b/tests/src/source/CodeCoverage.bs @@ -0,0 +1,36 @@ +function hitAllStatements() as dynamic + loopCount = 0 + for i = 0 to 10 + loopCount++ + end for + + tryAgain: + if loopCount = 11 then + loopCount++ + goto tryAgain + else if loopCount = 12 then + loopCount++ + goto tryAgain + else + loopCount++ + end if + + while loopCount > 0 + loopCount-- + if loopCount = 1 then + exit while + end if + end while + + obj = { + one: 1 + } + obj["two"] = 2 + obj.three = 3 + + for each key in obj + print obj[key] + end for + + return false +end function \ No newline at end of file diff --git a/tests/src/source/CodeCoverage.spec.bs b/tests/src/source/CodeCoverage.spec.bs new file mode 100644 index 0000000..67d54d3 --- /dev/null +++ b/tests/src/source/CodeCoverage.spec.bs @@ -0,0 +1,15 @@ +namespace tests + + @suite + class CodeCovTests extends rooibos.BaseTestSuite + '+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + @describe("Samples for validating code coverage") + '+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + + @it("tests statements for code coverage") + function _() + m.assertFalse(hitAllStatements()) + end function + + end class +end namespace \ No newline at end of file From ffdc3ca5662af46c6586ff3f072ba2ac05080325 Mon Sep 17 00:00:00 2001 From: Christopher Dwyer-Perkins Date: Fri, 9 Feb 2024 21:59:22 -0400 Subject: [PATCH 3/3] Fixed failed tests and upgraded brighterscript --- bsc-plugin/package.json | 2 +- bsc-plugin/src/plugin.spec.ts | 6 +- tests/package-lock.json | 152 ++-------------------------------- tests/package.json | 2 +- 4 files changed, 13 insertions(+), 149 deletions(-) diff --git a/bsc-plugin/package.json b/bsc-plugin/package.json index 198f7bb..71848fb 100644 --- a/bsc-plugin/package.json +++ b/bsc-plugin/package.json @@ -27,7 +27,7 @@ "@types/node": "^14.18.41", "@typescript-eslint/eslint-plugin": "^5.27.0", "@typescript-eslint/parser": "^5.27.0", - "brighterscript": "^0.65.15", + "brighterscript": "^0.65.22", "chai": "^4.2.0", "chai-subset": "^1.6.0", "coveralls": "^3.0.0", diff --git a/bsc-plugin/src/plugin.spec.ts b/bsc-plugin/src/plugin.spec.ts index 1951c30..009a2b6 100644 --- a/bsc-plugin/src/plugin.spec.ts +++ b/bsc-plugin/src/plugin.spec.ts @@ -372,7 +372,8 @@ describe('RooibosPlugin', () => { sub main() Rooibos_init("RooibosScene") print "hello" - end sub'//# sourceMappingURL=./test.spec.bs.map + end sub + '//# sourceMappingURL=./test.spec.brs.map `, [ // print "h|ello" => print |"hello" { dest: [2, 12], src: [2, 26] } @@ -408,7 +409,8 @@ describe('RooibosPlugin', () => { instance = __ATest_builder() instance.new() return instance - end function'//# sourceMappingURL=./test.spec.bs.map + end function + '//# sourceMappingURL=./test.spec.brs.map `, [ // m.assert|Equal("123", ("alpha-" + bslib_toString(number) + "-beta")) => m.|assertEqual("123", `alpha-${number}-beta`) { dest: [6, 16], src: [8, 26] }, diff --git a/tests/package-lock.json b/tests/package-lock.json index 6ec48df..7eff43d 100644 --- a/tests/package-lock.json +++ b/tests/package-lock.json @@ -9,7 +9,7 @@ "version": "4.1.1", "license": "MIT", "devDependencies": { - "brighterscript": "^0.65.15", + "brighterscript": "^0.65.22", "ts-node": "^10.7.0", "typescript": "^4.6.4" } @@ -261,12 +261,6 @@ "integrity": "sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==", "dev": true }, - "node_modules/argparse": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz", - "integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==", - "dev": true - }, "node_modules/array-flat-polyfill": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/array-flat-polyfill/-/array-flat-polyfill-1.0.1.tgz", @@ -388,11 +382,10 @@ } }, "node_modules/brighterscript": { - "version": "0.65.16", - "resolved": "https://registry.npmjs.org/brighterscript/-/brighterscript-0.65.16.tgz", - "integrity": "sha512-2RJMF8itkrPXtZ92JkJf3emvzcCl5ETXGVyPsdO/hMKbUGinEGMRFG07FR0bzjRotbALzsozGE/Hjzw412Sjww==", + "version": "0.65.22", + "resolved": "https://registry.npmjs.org/brighterscript/-/brighterscript-0.65.22.tgz", + "integrity": "sha512-rDSdO33xRnFGB9nr54awTUucpd4oZpZmDMvVUSAb6jmFU1jz+SYhwV9ezc8U5m3Kswap7uV+BmS1O69QZ9MuSw==", "dev": true, - "license": "MIT", "dependencies": { "@rokucommunity/bslib": "^0.1.1", "@xml-tools/parser": "^1.0.7", @@ -401,7 +394,6 @@ "chevrotain": "^7.0.1", "chokidar": "^3.5.1", "clear": "^0.1.0", - "coveralls-next": "^4.2.0", "cross-platform-clear-console": "^2.3.0", "debounce-promise": "^3.1.0", "eventemitter3": "^4.0.0", @@ -555,25 +547,6 @@ "integrity": "sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ==", "dev": true }, - "node_modules/coveralls-next": { - "version": "4.2.0", - "resolved": "https://registry.npmjs.org/coveralls-next/-/coveralls-next-4.2.0.tgz", - "integrity": "sha512-zg41a/4QDSASPtlV6gp+6owoU43U5CguxuPZR3nPZ26M5ZYdEK3MdUe7HwE+AnCZPkucudfhqqJZehCNkz2rYg==", - "dev": true, - "dependencies": { - "form-data": "4.0.0", - "js-yaml": "4.1.0", - "lcov-parse": "1.0.0", - "log-driver": "1.2.7", - "minimist": "1.2.7" - }, - "bin": { - "coveralls": "bin/coveralls.js" - }, - "engines": { - "node": ">=14" - } - }, "node_modules/create-require": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/create-require/-/create-require-1.1.1.tgz", @@ -759,20 +732,6 @@ "node": "*" } }, - "node_modules/form-data": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", - "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", - "dev": true, - "dependencies": { - "asynckit": "^0.4.0", - "combined-stream": "^1.0.8", - "mime-types": "^2.1.12" - }, - "engines": { - "node": ">= 6" - } - }, "node_modules/fs-extra": { "version": "8.1.0", "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-8.1.0.tgz", @@ -964,18 +923,6 @@ "integrity": "sha512-Yljz7ffyPbrLpLngrMtZ7NduUgVvi6wG9RJ9IUcyCd59YQ911PBJphODUcbOVbqYfxe1wuYf/LJ8PauMRwsM/g==", "dev": true }, - "node_modules/js-yaml": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.0.tgz", - "integrity": "sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA==", - "dev": true, - "dependencies": { - "argparse": "^2.0.1" - }, - "bin": { - "js-yaml": "bin/js-yaml.js" - } - }, "node_modules/jsbn": { "version": "0.1.1", "resolved": "https://registry.npmjs.org/jsbn/-/jsbn-0.1.1.tgz", @@ -1042,15 +989,6 @@ "setimmediate": "^1.0.5" } }, - "node_modules/lcov-parse": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/lcov-parse/-/lcov-parse-1.0.0.tgz", - "integrity": "sha512-aprLII/vPzuQvYZnDRU78Fns9I2Ag3gi4Ipga/hxnVMCZC8DnR2nI7XBqrPoywGfxqIx/DgarGvDJZAD3YBTgQ==", - "dev": true, - "bin": { - "lcov-parse": "bin/cli.js" - } - }, "node_modules/lie": { "version": "3.3.0", "resolved": "https://registry.npmjs.org/lie/-/lie-3.3.0.tgz", @@ -1066,15 +1004,6 @@ "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==", "dev": true }, - "node_modules/log-driver": { - "version": "1.2.7", - "resolved": "https://registry.npmjs.org/log-driver/-/log-driver-1.2.7.tgz", - "integrity": "sha512-U7KCmLdqsGHBLeWqYlFA0V0Sl6P08EE1ZrmA9cxjUE0WVqT9qnyVDPz1kzpFEP0jdJuFnasWIfSd7fsaNXkpbg==", - "dev": true, - "engines": { - "node": ">=0.8.6" - } - }, "node_modules/long": { "version": "3.2.0", "resolved": "https://registry.npmjs.org/long/-/long-3.2.0.tgz", @@ -1154,15 +1083,6 @@ "node": "*" } }, - "node_modules/minimist": { - "version": "1.2.7", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.7.tgz", - "integrity": "sha512-bzfL1YUZsP41gmu/qjrEk0Q6i2ix/cVeAhbCbqH9u3zYutS1cLg00qhrD0M2MVdCcx4Sc0UpP2eBWo9rotpq6g==", - "dev": true, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, "node_modules/moment": { "version": "2.30.1", "resolved": "https://registry.npmjs.org/moment/-/moment-2.30.1.tgz", @@ -2177,12 +2097,6 @@ "integrity": "sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==", "dev": true }, - "argparse": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz", - "integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==", - "dev": true - }, "array-flat-polyfill": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/array-flat-polyfill/-/array-flat-polyfill-1.0.1.tgz", @@ -2275,9 +2189,9 @@ } }, "brighterscript": { - "version": "0.65.16", - "resolved": "https://registry.npmjs.org/brighterscript/-/brighterscript-0.65.16.tgz", - "integrity": "sha512-2RJMF8itkrPXtZ92JkJf3emvzcCl5ETXGVyPsdO/hMKbUGinEGMRFG07FR0bzjRotbALzsozGE/Hjzw412Sjww==", + "version": "0.65.22", + "resolved": "https://registry.npmjs.org/brighterscript/-/brighterscript-0.65.22.tgz", + "integrity": "sha512-rDSdO33xRnFGB9nr54awTUucpd4oZpZmDMvVUSAb6jmFU1jz+SYhwV9ezc8U5m3Kswap7uV+BmS1O69QZ9MuSw==", "dev": true, "requires": { "@rokucommunity/bslib": "^0.1.1", @@ -2287,7 +2201,6 @@ "chevrotain": "^7.0.1", "chokidar": "^3.5.1", "clear": "^0.1.0", - "coveralls-next": "^4.2.0", "cross-platform-clear-console": "^2.3.0", "debounce-promise": "^3.1.0", "eventemitter3": "^4.0.0", @@ -2418,19 +2331,6 @@ "integrity": "sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ==", "dev": true }, - "coveralls-next": { - "version": "4.2.0", - "resolved": "https://registry.npmjs.org/coveralls-next/-/coveralls-next-4.2.0.tgz", - "integrity": "sha512-zg41a/4QDSASPtlV6gp+6owoU43U5CguxuPZR3nPZ26M5ZYdEK3MdUe7HwE+AnCZPkucudfhqqJZehCNkz2rYg==", - "dev": true, - "requires": { - "form-data": "4.0.0", - "js-yaml": "4.1.0", - "lcov-parse": "1.0.0", - "log-driver": "1.2.7", - "minimist": "1.2.7" - } - }, "create-require": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/create-require/-/create-require-1.1.1.tgz", @@ -2583,17 +2483,6 @@ "integrity": "sha512-j0KLYPhm6zeac4lz3oJ3o65qvgQCcPubiyotZrXqEaG4hNagNYO8qdlUrX5vwqv9ohqeT/Z3j6+yW067yWWdUw==", "dev": true }, - "form-data": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", - "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", - "dev": true, - "requires": { - "asynckit": "^0.4.0", - "combined-stream": "^1.0.8", - "mime-types": "^2.1.12" - } - }, "fs-extra": { "version": "8.1.0", "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-8.1.0.tgz", @@ -2741,15 +2630,6 @@ "integrity": "sha512-Yljz7ffyPbrLpLngrMtZ7NduUgVvi6wG9RJ9IUcyCd59YQ911PBJphODUcbOVbqYfxe1wuYf/LJ8PauMRwsM/g==", "dev": true }, - "js-yaml": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.0.tgz", - "integrity": "sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA==", - "dev": true, - "requires": { - "argparse": "^2.0.1" - } - }, "jsbn": { "version": "0.1.1", "resolved": "https://registry.npmjs.org/jsbn/-/jsbn-0.1.1.tgz", @@ -2813,12 +2693,6 @@ "setimmediate": "^1.0.5" } }, - "lcov-parse": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/lcov-parse/-/lcov-parse-1.0.0.tgz", - "integrity": "sha512-aprLII/vPzuQvYZnDRU78Fns9I2Ag3gi4Ipga/hxnVMCZC8DnR2nI7XBqrPoywGfxqIx/DgarGvDJZAD3YBTgQ==", - "dev": true - }, "lie": { "version": "3.3.0", "resolved": "https://registry.npmjs.org/lie/-/lie-3.3.0.tgz", @@ -2834,12 +2708,6 @@ "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==", "dev": true }, - "log-driver": { - "version": "1.2.7", - "resolved": "https://registry.npmjs.org/log-driver/-/log-driver-1.2.7.tgz", - "integrity": "sha512-U7KCmLdqsGHBLeWqYlFA0V0Sl6P08EE1ZrmA9cxjUE0WVqT9qnyVDPz1kzpFEP0jdJuFnasWIfSd7fsaNXkpbg==", - "dev": true - }, "long": { "version": "3.2.0", "resolved": "https://registry.npmjs.org/long/-/long-3.2.0.tgz", @@ -2898,12 +2766,6 @@ "brace-expansion": "^1.1.7" } }, - "minimist": { - "version": "1.2.7", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.7.tgz", - "integrity": "sha512-bzfL1YUZsP41gmu/qjrEk0Q6i2ix/cVeAhbCbqH9u3zYutS1cLg00qhrD0M2MVdCcx4Sc0UpP2eBWo9rotpq6g==", - "dev": true - }, "moment": { "version": "2.30.1", "resolved": "https://registry.npmjs.org/moment/-/moment-2.30.1.tgz", diff --git a/tests/package.json b/tests/package.json index 2c9b455..2fe2581 100644 --- a/tests/package.json +++ b/tests/package.json @@ -7,7 +7,7 @@ "watch": "npx bsc --project bsconfig.json --watch" }, "devDependencies": { - "brighterscript": "^0.65.15", + "brighterscript": "^0.65.22", "ts-node": "^10.7.0", "typescript": "^4.6.4" },