Skip to content

[Feature] Give test suite nodes a source locationΒ #5067

Description

Request Overview

Written with the help of AI; reviewed by me πŸ˜‰

With cmake.ctest.testSuiteDelimiter set, tests are grouped into suite nodes in the Test
Explorer. The leaf tests get a source location β€” we supply DEF_SOURCE_LINE β€” so they show run
decorations in the editor gutter and "Go to Test" works. Suite nodes have no location, so neither
does.

Running a suite already works from the panel, so all that seems to be missing is the location: a
TestItem with a uri and range gets a gutter decoration from VS Code, and activating it goes
through the same run handler, which already expands a suite to its leaf tests via flattenTests.
So a suite would become runnable from the editor for free.

The catch is that suite nodes are synthesised by splitting test names, so there's no obvious place
for a location to come from. One idea: if a registered test's name is exactly the prefix that
would otherwise become a synthesised suite β€” a test named unit.GgaSentenceTests alongside
unit.GgaSentenceTests.parses_a_valid_case β€” use that test as the suite node, taking its
DEF_SOURCE_LINE. That needs no new property, and it would also remove the duplicate entry
reported in #4408, where such a test currently appears as a sibling of the suite instead of being
it.

Additional Information

Suite items are created without a uri today, while the leaf item just below gets one
(createTestItemAndSuiteTree in src/ctest.ts):

suiteItem = initializedTestExplorer.createTestItem(suiteId, suiteId);
...
testItem = initializedTestExplorer.createTestItem(testName, testLabel, uri);

TestItem.uri is readonly, so the location has to be known at creation time.

Worth flagging: falling back to the location of the suite's first child wouldn't help. The
decoration would land on the first test case's line instead of the suite declaration, so you'd get
two decorations on one line and still nothing on the suite. Only the suite's own line is useful.

For context we're on Boost.Test, where this maps cleanly. --list_content=DOT reports file and
line for suites as well as cases, and --run_test=<suite> runs a whole suite, so we can register
unit.GgaSentenceTests with a correct DEF_SOURCE_LINE and a working command today β€” it just
ends up beside the suite node rather than becoming it. Happy to test a change against a real
project.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementan enhancement to the product that is either not present or an improvement to an existing feature

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions