DavidSchuldenfrei / gtest-adapter

Other
18 stars 9 forks source link

Support of multi root workspaces #55

Open LacknerA opened 4 years ago

LacknerA commented 4 years ago

It seems like the extension doesn't support multi root workspaces. I added the "gtest-adapter.debugConfig": setting with an existing debug config as value to the .code-workspace file but the extension is unable to find it. If i try to switch the configuration i get a popup saing "You first need to define a debug configuration, for your tests".

Is it correct that the gtest-adapter extension doesn't support multi root workspaces or is just my configuration wrong?

Edit: I now added a launch config to the .code-workspace file instead of the launch.json. Now it detects the configuration but it's nevertheless unable to parse any tests.

cassie-nahar commented 4 years ago

Related: https://github.com/DavidSchuldenfrei/gtest-adapter/issues/10#issuecomment-429835860

inhaledesign commented 2 years ago

The issue seems to be here: https://github.com/DavidSchuldenfrei/gtest-adapter/blob/0e428902abcdc9a55e85804ec6dd0b48fc588fa1/src/ConfigUtils.ts#L84-L85

Note that the scope passed to getConfiguration is null. This method can be passed a WorkspaceFolder as a ConfigurationScope.

So presumably it just needs a little extra work getting the WorkspaceFolders and searching through them. It might be a little hairy, because it sounds like things get messy when there's both workspace files and launch.json.

Unfortunately, Javascript is not my jam, and I'm not sure I have the mental bandwidth to put together a properly tested PR.

inhaledesign commented 2 years ago

So I did a dive into this, and here's what's actually going on.

In a multi root workspace, there are times when you need to scope a substitution variable, esp. ${workspaceFolder}, to a specific folder. For example, ${workspaceFolder:MyProject} substitutes the workspace path for your MyProject folder.

GoogleTestAdapter tries to parse your configuration manually, and it does not support such scoping:

https://github.com/DavidSchuldenfrei/gtest-adapter/blob/0e428902abcdc9a55e85804ec6dd0b48fc588fa1/src/ConfigUtils.ts#L55-L59

The easy remedy as a user is to get rid of such variables in your task configuration and hard code the values in, i.e. replace ${workspaceFolder:MyProject} wtih /path/to/MyProject. For me, this is making my test show up in the GoogleTests panel.

There's also another catch I found: GoogleTestAdapter will only read the folder that's specified first in your workspace file:

https://github.com/DavidSchuldenfrei/gtest-adapter/blob/0e428902abcdc9a55e85804ec6dd0b48fc588fa1/src/GTestWrapper.ts#L198-L204