Skip to content

fix: skip assertion tracking injection for namespace function calls#385

Open
TwitchBronBron wants to merge 1 commit into
masterfrom
fix/namespace-call-assertion-injection
Open

fix: skip assertion tracking injection for namespace function calls#385
TwitchBronBron wants to merge 1 commit into
masterfrom
fix/namespace-call-assertion-injection

Conversation

@TwitchBronBron

Copy link
Copy Markdown
Member

Summary

  • Fixes a bug where calls like some.space.assertEqual(...) inside a test method incorrectly had assertion tracking (currentAssertLineNumber, currentResult?.isFail, done()) injected using some.space as the target object
  • Adds a namespace guard in TestGroup.modifyAssertions(): if the first part of the call path is a known namespace name, the call is a namespaced function (not a method on an object like m) and assertion tracking injection is skipped

Background

When a test contains a namespaced function call whose name matches the assertion regex (e.g. some.space.assertEqual(...)), the rewriter was computing callPath = "some.space" and injecting:

some.space.currentAssertLineNumber = 29
some_space_assertEqual(...)
if some_space_currentResult_isFail = true then ...

The bug was latent in Rooibos but became visible after BrighterScript 0.72.0 made namespace recognition more reliable during transpile (via the new ScopeNamespaceLookup), causing some.space in the injected code to be correctly transpiled to some_space..

Test plan

  • New regression test in plugin.spec.ts verifies that some.space.assertEqual(1, 1) inside a test method does NOT produce some_space.currentAssertLineNumber, while m.assertEqual(2, 2) still correctly gets m.currentAssertLineNumber injected
  • All 121 existing tests pass

🤖 Generated with Claude Code

When a test method contains a call like `some.space.assertEqual(...)`,
the assertion rewriter was computing `callPath = "some.space"` and
injecting `some.space.currentAssertLineNumber = N`. BrighterScript then
correctly transpiles `some.space` as a namespace to `some_space.`,
producing invalid output (`some_space.currentAssertLineNumber`).

The fix checks whether the first part of callPath is a known namespace
name before injecting assertion tracking. If it is, the call is a
namespaced function (not a method on an object like m) and tracking
is skipped.

The bug was always latent in Rooibos but became visible after
BrighterScript 0.72.0 made namespace recognition more reliable
during transpile via the new ScopeNamespaceLookup.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant