Skip to content

fix(extract): derive unique names for GoogleTest macros to prevent same-file node collisions (#1266) - #1329

Open
harshitaajoshi wants to merge 1 commit into
DeusData:mainfrom
harshitaajoshi:fix/cpp-gtest-name-collision-1266
Open

fix(extract): derive unique names for GoogleTest macros to prevent same-file node collisions (#1266)#1329
harshitaajoshi wants to merge 1 commit into
DeusData:mainfrom
harshitaajoshi:fix/cpp-gtest-name-collision-1266

Conversation

@harshitaajoshi

@harshitaajoshi harshitaajoshi commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Fixes #1266

Multiple GoogleTest TEST(...) cases defined in the same file collapse into a single graph node because cbm_resolve_func_name returns the bare macro name TEST with no argument-derived identity. Every test case in the file maps to the same qualified name (e.g. proj.file.TEST), so the graph upsert keeps only the last one and the call edges of all previous test cases are dropped.

This PR adds a GoogleTest macro detection step in extract_func_def that composes a unique name from the two macro arguments: TEST(WidgetSuite, DoublesSmallSize) becomes TEST_WidgetSuite_DoublesSmallSize. This gives each test case its own qualified name, preventing node collisions. The fix covers TEST, TEST_F, TEST_P, TYPED_TEST, and TYPED_TEST_P. It also sets is_test = true for these nodes so test exclusion queries work correctly.

Changes:

  • internal/cbm/extract_defs.c: Add is_cpp_test_macro() and resolve_cpp_test_macro_name() helpers; call them in extract_func_def before QN computation; set is_test flag
  • tests/test_extraction.c: Two regression tests using the exact fixture from the issue (TEST() three-case collision and TEST_F() two-case collision)

Checklist

  • Every commit is signed off (git commit -s) -- required, CI rejects unsigned commits (DCO, see CONTRIBUTING.md)
  • Tests pass locally (make -f Makefile.cbm test)
    ASan test-runner hangs on startup on macOS Tahoe (Apple Clang 17), a pre-existing environment issue unrelated to this change.
  • Lint passes (make -f Makefile.cbm lint-ci)
  • New behavior is covered by a test (reproduce-first for bug fixes)

Note: the local test checkbox is unchecked because the ASan test-runner hangs on startup for all suites locally (pre-existing environment issue unrelated to this change). The production build compiles cleanly with -Werror and clang-format passes on all changed files. CI will run the full test suite.

…me-file node collisions (DeusData#1266)

Signed-off-by: Harshita Joshi <j.harshitaa06@gmail.com>
@harshitaajoshi
harshitaajoshi requested a review from DeusData as a code owner July 29, 2026 04:29
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.

C++: same-named TEST cases in one file collapse into a single node, dropping their call edges

1 participant