matepek / vscode-catch2-test-adapter

Catch2, Google Test and doctest Adapter for the VSCode
https://marketplace.visualstudio.com/items?itemName=matepek.vscode-catch2-test-adapter
MIT License
210 stars 52 forks source link

Label merging is broken after adding current working directory in the advanced executables configuration #427

Closed rafalborczuch closed 8 months ago

rafalborczuch commented 9 months ago

Checklist

Describe the bug

Label merging stops working after adding cwd property to the advanced executables configuration. The cwd path exists on the filesystem and tests have the correct cwd set when running/debugging. I use a multi-root workspace.

To Reproduce

The following config correctly merges the labels in the tree view. Note that the cwd property is commented.

"testMate.cpp.test.advancedExecutables": [
    {
        "pattern": "${command:cmake.activeFolderName}/bin/linux/${command:cmake.buildType}/**/*{test,Test,TEST}*",
        // "cwd": "${relDirpath}/ctest_cwds/${filename}",
        "gtest": {
            "testGrouping": {
                "groupByExecutable": {
                    "label": "${absDirpath[-4:-3]}",
                    "description": "${relDirpath}",
                    "mergeByLabel": true,
                    "groupByExecutable": {
                        "label": "${filename}",
                        "description": "${workspaceName}",
                        "groupByTags": {
                            "tags": [],
                            "tagFormat": "${tag}"
                        }
                    },
                }
            }
        }
    }
],

producing the following tree view in the Test Explorer:

projectA
    executable1
        TestClassA
            testA1
            tetsA2
        TestClassB
            testB1
            tetsB2
    executable2
        TestClassC
            testC1
            tetsC2
        TestClassD
            testD1
            tetsD2

After uncommenting the cwd line:

"testMate.cpp.test.advancedExecutables": [
    {
        "pattern": "${command:cmake.activeFolderName}/bin/linux/${command:cmake.buildType}/**/*{test,Test,TEST}*",
        "cwd": "${relDirpath}/ctest_cwds/${filename}",
        "gtest": {
            "testGrouping": {
                "groupByExecutable": {
                    "label": "${absDirpath[-4:-3]}",
                    "description": "${relDirpath}",
                    "mergeByLabel": true,
                    "groupByExecutable": {
                        "label": "${filename}",
                        "description": "${workspaceName}",
                        "groupByTags": {
                            "tags": [],
                            "tagFormat": "${tag}"
                        }
                    },
                }
            }
        }
    }
],

tree view in the Test Explorer doesn't merge 1st level label:

projectA
    executable1
        TestClassA
            testA1
            tetsA2
        TestClassB
            testB1
            tetsB2
projectA
    executable2
        TestClassC
            testC1
            tetsC2
        TestClassD
            testD1
            tetsD2

Each executable has its own 1st level node (projectA in the example).

Desktop

matepek commented 8 months ago

where is the ProjectA coming from?

rafalborczuch commented 8 months ago

The above assumes that the directory structure is as follows:

repo
    projectA
    projectB
    repo.code-workspace

and it is opened in the VS Code as a mutli-root workspace file repo.code-workspace that has the following folders defined:

"folders": [
    {
        "path": "projectA"
    },
    {
        "path": "projectB"
    }
]

The build output binaries are placed under projectA/bin/linux/Debug and projectB/bin/linux/Debug and the "label": "${absDirpath[-4:-3]}", results in projectA or projectB.

matepek commented 8 months ago

And what is the expectations for that label? It's a but unclear what is the current value and what you expect. Have you tried using ${relDirpath[0]}?

rafalborczuch commented 8 months ago

${relDirpath[0]} gives the same result. The expected top level label is projectA or projectB.

rafalborczuch commented 8 months ago

The problem is here: https://github.com/matepek/vscode-catch2-test-adapter/blob/master/src/framework/AbstractExecutable.ts#L293 The this.shared.options has cwd which has different value for each executable (due to the advancedExecutable config "cwd": "${relDirpath}/ctest_cwds/${filename}") resulting in different options hash value that is used to construct the id. The mergeByLabel configuration works more like mergeByEnvAndCwd.

matepek commented 8 months ago

is ${relDirpath}/ctest_cwds/${filename} a directory or a file?

matepek commented 8 months ago
Fixed in v4.11.0. This issue was mentioned in [CHANGELOG.md](./CHANGELOG.md) under a released entry so it is assumed to be fixed. User verifications are always welcome.
rafalborczuch commented 8 months ago

Thanks, I have successfully verified the fix.