DavidSchuldenfrei/gtest-adapter

Sample Configuration

Opened this issue ยท 20 comments

Hi,

would it be possible to add a sample configuration to the readme. I tried to use your extension in combination with the Test Explorer UI (by Holger Benl), but I was not able to correctly configure your extension to find my tests.

Thanks in advance,
Lukas

@lukasdiem Sorry for taking so long to get back to you. This extension doesn't integrate with the Test Explorer extension, but is standalone.
To use the extension, you need to configure your launch.json, to debug your Google tests application. See debugging in vscode . Once this is setup, you can configure the extension by clicking on the switch configuration icon in the tree view.
Let me know if you need more information, or if I can close this issue.

Thanks for your answer. I had no time to test it yet, but I hope I have time tomorrow to look into this. The clarification the Test Explorer and the docu link is already helpful : ). I hope I'm able to get my config running.

Great. Let me know how it goes

Hi David,

I'm struggling with setting up the extension also. Every time I try to load the test list I get an error "You first need to define a debug configuration for your tests". I believe I've done that as I can hit F5 and it runs the tests. I've just started to use VSCode so I may be missing something. Here are my lauch.json

       {
            "name": "Debug",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/build-native-debug/MyApp_test",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": true,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        },

And I've also assigned the command in my workplace settings as follows:
"gtest-adapter.debugConfig": "Debug",

What am I missing? I agree that an example would be very helpful.

@goloap Hi,
This is weird, you seem to have it configured properly. Just to confirm, your launch.json was generated from VsCode? It starts with

{
    "version": "0.2.0",
    "configurations": [
    {
        "name": "Debug"

Also, what behavior do you get when you click the "Switch Test Configuration" command? Do you get a list asking you to select a debug configuration for your tests?

David

Hi David,

I confirm that launch.json was created by VSCode and has the correct version (hitting F5 does launch the correct command specified in the launch.json).

Clicking "Switch Test Configuration" results in the same error "You first need to define a debug configuration for your tests". The behavior is constant across relaunches of VScode. Any debug logs I get have a look to get more details on the error?

@goloap Hi,
I checked my code. I try to iterate through all debug configuration by calling workspace.getConfiguration("launch").get("configurations"). Do you have any idea why this would fail? Alternatively, do you have any suggestion for another way to iterate through debug configurations

@goloap Hi,
Do you still experience the same behavior with the latest version of the extension (1.3.0). If you do,
could you try running my extension in debug mode. Alternatively could you send me a copy of your project (the .vscode folder ought to be enough for now)

Hi @DavidSchuldenfrei,

I've run the extension in debug mode and I get strange results. The workpace object has no launch configuration (which is why the extension doesn't find it). I.e. workspace.getConfiguration("launch") returns an empty array. And I've also confirmed this by looking at the entire configuration retrieved by workspace.getConfiguration(). Interestingly, workspace.textDocuments returns 2 documents, one of which is my launch.json. I see the same behaviour on basic test project, any idea of why the configuration is not seen?

This is with 1.3.0 and latest git code.

Hi @goloap I was able to get it working (workaround) and the problem had to do with how my project/workspace was set up.

I had my VSCode Workspace, and within this I had the folder opened called "FOLDER". FOLDER had it's own .vscode/launch.json and this launch.json was where I was writing my debug configuartion. It was unable to find my debug config "Debug" in here, when I opened vscode with the workspace.

If instead of opening a workspace I open just FOLDER in vscode, then everything works and I have the option to choose the "Debug" configuration. If your set up is similar, maybe you can open just the folder you're working with and see if you have the same findings?

I would love to know/find a solution to get it working within a workspace, but maybe until then, this can be a work around for you as well. Alternatively, maybe you know of a way to have the launch.json apply to the workspace and not just to the folder.

(By working, I mean that it finds the configuration ... I still have problems setting up afterwards)

Hi @Kaatjie,

Thanks for the tip, this indeed seem to solve the issue even though it doesn't make sense to me. My structure is:

~/foo/
    foo.cpp
    foowkp.code-workspace
    .vscode/
          c_pp_properties.json
          launch.json
          settings.json
          tasks.json

If I select "Open Workspace" and select foowkp.code-workspace, no tests are shown. If I select "Open Folder" and select ~/foo/, then the tests show up.

Another workaround is to put the debug launch configuration in the workspace file (i.e. .code-workspace). This allows GTest to find it.

This workaround works for me as well, as I believe I was seeing the same issue. I think it would be good to enhance the extension to support multi root workspaces but loading the launch.json from each root folder and presenting those.

By putting the config in code-workspace, it doesn't work for me.

I am just using the "open folder" from now on, thanks all of you above.

@Jekton Could you send me the exact configs which aren't working for you (launch.json and settings.json) and your path?

Thanks you

A-Sam commented

Faced the same issue today. It seems the problem is the separate configs for "open as folder" and "open as workspace". I checked the code, it seems the problem is as @goloap . Maybe its a bug in vsc return of object.getConfiguration() ?

Hi,David:
I had config the launch.json like this:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(lldb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "enter program name, for example ${workspaceFolder}/a.out",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "lldb"
},
{
"gtest-adapter.debugConfig": "debug",
"gtest-adapter.showCodeLens": true,
"gtest-adapter.refreshAfterBuild": true,
"gtest-adapter.runAfterBuild": false,
"gtest-adapter.gotoTestTitle": "Go to Tree",
"gtest-adapter.runTitle": "Run",
"gtest-adapter.debugTitle": "Debug",
"gtest-adapter.supportLocation": false,
"gtest-adapter.showRunOutput": true,
"gtest-adapter.clearRunOutput": true,
}
]
}

but it does not work, can you give me a configuration json sample ? I alse config it in the workspace file ,

A-Sam commented

Hi,David:
I had config the launch.json like this:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(lldb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "enter program name, for example ${workspaceFolder}/a.out",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "lldb"
},
{
"gtest-adapter.debugConfig": "debug",
"gtest-adapter.showCodeLens": true,
"gtest-adapter.refreshAfterBuild": true,
"gtest-adapter.runAfterBuild": false,
"gtest-adapter.gotoTestTitle": "Go to Tree",
"gtest-adapter.runTitle": "Run",
"gtest-adapter.debugTitle": "Debug",
"gtest-adapter.supportLocation": false,
"gtest-adapter.showRunOutput": true,
"gtest-adapter.clearRunOutput": true,
}
]
}

but it does not work, can you give me a configuration json sample ? I alse config it in the workspace file ,

Did your try to open your folder as 'File -> open folder' instead of 'open a workspace'?

Hi, where and how do I assign this in VScode?
"gtest-adapter.debugConfig": "Debug",

@bochen87

Making .vscode directory and create launch.json file, then put them...
I think it will work.