diff --git a/src/lib/rooibos/TestGroup.ts b/src/lib/rooibos/TestGroup.ts index 1a41d68a..ff53f184 100644 --- a/src/lib/rooibos/TestGroup.ts +++ b/src/lib/rooibos/TestGroup.ts @@ -50,6 +50,15 @@ export class TestGroup extends TestBlock { const callPath = util.getAllDottedGetParts(callExpression.callee.obj)?.map((part) => part.text).join('.'); if (callPath) { + // Skip if callPath starts with a namespace name — this is a namespace + // function call (e.g. some.space.assertEqual()), not a method call on + // an object like m. Injecting assertion tracking on a namespace prefix + // produces invalid output (e.g. some_space.currentAssertLineNumber). + const callPathFirstPart = callPath.split('.')[0].toLowerCase(); + if (namespaceLookup.has(callPathFirstPart) || scope?.namespaceLookup?.has(callPathFirstPart)) { + return; + } + if (dge.name.text === 'stubCall') { this.modifyModernRooibosExpectCallExpression(callExpression, editor, namespaceLookup, scope); return expressionStatement; diff --git a/src/plugin.spec.ts b/src/plugin.spec.ts index f3e8aff5..e006440e 100644 --- a/src/plugin.spec.ts +++ b/src/plugin.spec.ts @@ -867,6 +867,39 @@ describe('RooibosPlugin', () => { })).not.to.exist; }); + it('does not inject assertion tracking for namespace function calls with assertion-like names', async () => { + // Regression test: some.space.assertEqual(...) inside a test method should NOT have + // currentAssertLineNumber injected with `some.space` as the target object. + // The call is a namespaced function, not a method call on an object. + program.setFile('source/someSpace.bs', ` + namespace some.space + function assertEqual(a, b) + end function + end namespace + `); + plugin.afterProgramCreate(program); + program.setFile('source/test.spec.bs', ` + @suite + class ATest extends rooibos.BaseTestSuite + @describe("groupA") + @it("is test1") + function Test_1() + some.space.assertEqual(1, 1) + m.assertEqual(2, 2) + end function + end class + `); + program.validate(); + await builder.transpile(); + const contents = getContents('test.spec.brs'); + // The namespace function call must NOT produce some_space.currentAssertLineNumber + expect(contents).not.to.include('some_space.currentAssertLineNumber'); + // The m.assertEqual assertion MUST still get currentAssertLineNumber injected + expect(contents).to.include('m.currentAssertLineNumber'); + // The namespace call must be transpiled correctly as underscored function + expect(contents).to.include('some_space_assertEqual(1, 1)'); + }); + it('handles groups that start with numbers', async () => { plugin.afterProgramCreate(program); // program.validate();