DavidSchuldenfrei / gtest-adapter

Other
18 stars 9 forks source link

Sample Configuration #10

Open lukasdiem opened 6 years ago

lukasdiem commented 6 years ago

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

DavidSchuldenfrei commented 6 years ago

@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.

lukasdiem commented 6 years ago

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.

DavidSchuldenfrei commented 6 years ago

Great. Let me know how it goes

goloap commented 6 years ago

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.

DavidSchuldenfrei commented 6 years ago

@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

goloap commented 6 years ago

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?

DavidSchuldenfrei commented 6 years ago

@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

DavidSchuldenfrei commented 6 years ago

@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)

goloap commented 6 years ago

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.

katjie commented 6 years ago

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)

goloap commented 6 years ago

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.

goloap commented 6 years ago

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

cdunford commented 5 years ago

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.

Jekton commented 5 years ago

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.

DavidSchuldenfrei commented 5 years ago

@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 5 years ago

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() ?

piaodangdang commented 5 years ago

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 5 years ago

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'?

bochen87 commented 3 years ago

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

ekusiadadus commented 2 years ago

@bochen87

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