gtest-adapter icon indicating copy to clipboard operation
gtest-adapter copied to clipboard

Support of multi root workspaces

Open LacknerA opened this issue 4 years ago • 3 comments

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.

LacknerA avatar Jun 17 '20 12:06 LacknerA

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

cassie-nahar avatar Sep 11 '20 14:09 cassie-nahar

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 avatar Jun 04 '22 16:06 inhaledesign

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

inhaledesign avatar Jun 06 '22 22:06 inhaledesign