Skip to content

Record TEST_GROUP source locations for cmake-tools integration#49

Merged
thetic merged 3 commits into
mainfrom
group-location
Apr 14, 2026
Merged

Record TEST_GROUP source locations for cmake-tools integration#49
thetic merged 3 commits into
mainfrom
group-location

Conversation

@thetic
Copy link
Copy Markdown
Owner

@thetic thetic commented Apr 13, 2026

Description

Upstream PR cpputest/cpputest#1848 added DEF_SOURCE_LINE support to CTest discovery so VS Code's CMake Tools extension can navigate directly to test sources. It noted a limitation:

CppUTest doesn't record file paths or line numbers for test groups, only for tests, so when CPPUTEST_TESTS_DETAILED=0, use the lowest line number of the tests in that group.

This meant the "go to test" link for a group-level CTest entry jumped to the first TEST() in the group, not the TEST_GROUP() declaration.

This PR resolves that limitation.

Changes

New GroupLocation class (include/mutiny/test/GroupLocation.hpp, src/test/GroupLocation.cpp)

A self-registering node that captures the source location of each TEST_GROUP() declaration. Follows the same static linked-list pattern as OrderedShell. No heap allocation; no standard library dependency (works with MUTINY_USE_STD_CPP_LIB=OFF). The existing link-time duplicate-group guard (extern int) is replaced by the GroupLocation object, preserving the same linker error for duplicate group names.

Updated TEST_GROUP() macro (include/mutiny/test.hpp)

Now captures __FILE__ and __LINE__ via the GroupLocation constructor. TEST_GROUP_C_WRAPPER delegates to TEST_GROUP and picks this up automatically.

New -lgl flag — list group locations

Threads through CommandLineArgumentsCommandLineRunnerRegistry::list_test_group_locations(). Output format: group.file.line\n per group.

Updated cmake discovery script (cmake/_mutiny_discovery.cmake)

Calls -lgl after -ll and uses the real group declaration locations for DEF_SOURCE_LINE. Falls back gracefully to the previous lowest-test-line heuristic when -lgl exits non-zero (old binaries). The same fallback pattern is already used for -lo.

Related Issues

Addresses the limitation noted in cpputest/cpputest#1848.

Type of Change

  • New feature (non-breaking change which adds functionality)

Checklist

  • I have written/updated documentation in docs/ for any user-facing changes.
  • My code follows the project's naming conventions (mu::tiny namespace, INCLUDED_MUTINY_ guards, mutiny_ C-prefix).
  • For new features, I have considered if a C-interface adapter (.h and .c.cpp) is required for parity.
  • I have reviewed the CONTRIBUTING.md file to ensure compliance with architectural guidelines.

@coveralls
Copy link
Copy Markdown

coveralls commented Apr 14, 2026

Coverage Status

coverage: 98.953% (+0.009%) from 98.944% — group-location into main

The upstream PR cpputest/cpputest#1848 added DEF_SOURCE_LINE support to
CTest discovery so VS Code's CMake Tools extension can navigate to test
sources. It noted a limitation: group-mode entries pointed to the first
TEST() in the group rather than the TEST_GROUP() declaration itself.

Introduce GroupLocation, a self-registering class (same static linked-list
pattern as OrderedShell) that captures __FILE__ and __LINE__ at the
TEST_GROUP() macro site. Add a -lgl flag to list group declaration
locations in group.file.line format. Update the cmake discovery script to
call -lgl and use the real group locations for DEF_SOURCE_LINE, with a
graceful fallback to the previous heuristic for old binaries.
Bare get_head() can't resolve from a @file block without class/namespace
context. Use the fully-qualified name so Doxygen can link it correctly.
@thetic thetic merged commit 78dd94a into main Apr 14, 2026
39 of 40 checks passed
@thetic thetic deleted the group-location branch April 14, 2026 02:18
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.

2 participants