Catch2 and Google Test Explorer for Visual Studio Code (with code lens)IMPORTANT: This is fork of original Catch2 and Google Test Explorer for Visual Studio Code repo I've added ability to present code lens, directly in code: IMPORTANT: This only works on Windows with OpenCppCoverage and compiler able to produce PDB files. If you cannot met the requirenments, please use original version of this plugin. Important: This plugin is not actively maintained. Use at your own risk. If you wish so, feel free to fork this and update code. Below you can find original readme This extension allows you to run your Catch2 and Google Test tests using the Test Explorer for VS Code. Configuration
Note that this extension is built upon the Test Explorer so it's configuration and commands can be used. catch2TestExplorer.executablesThis variable can be
If it is an object it can contains the following properties:
The Test executables and Note that there is a mechanism which will filter out every possible executable which:
It won't filter out If the pattern is too general like Variables which can be used in
|
Variable | Description |
---|---|
${absPath} |
Absolute path of the test executable |
${relPath} |
Relative path of the test executable to the workspace folder |
${absDirpath} |
Absolute path of the test executable's parent directory |
${relDirpath} |
Relative path of the test executable's parent directory to the workspace folder |
${filename} |
Filename (Path withouth directories; "d/a.b.c " => "a.b.c ") |
${baseFilename} |
Filename without extension ("d/a.b.c " => "a.b ") |
${extFilename} |
Filename extension. ("d/a.b.c " => ".c ") |
${base2Filename} |
Filename without second extension ("d/a.b.c " => "a ") |
${ext2Filename} |
Filename's second level extension. ("d/a.b.c " => ".b ") |
${base3Filename} |
Filename without third extension ("d/a.b.c " => "a ") |
${ext3Filename} |
Filename's third level extension. ("d/a.b.c " => "") |
${workspaceDirectory} |
(You can only guess once.) |
${workspaceFolder} |
Alias of ${workspaceDirectory} |
${workspaceName} |
Workspace name can be custom in case of workspace file . |
${name} |
The resolved executables 's name. Can be used only in cwd and env . |
${cwd} |
The resolved executables 's cwd. Can be used only in env . |
Examples:
"catch2TestExplorer.executables": "dir/test.exe"
"catch2TestExplorer.executables": ["dir/test1.exe", "dir/test2.exe"]
"catch2TestExplorer.executables": {
"name": "${filename} (${relDirpath}/)",
"pattern": "{build,Build,BUILD,out,Out,OUT}/**/*{test,Test,TEST}*",
"cwd": "${absDirpath}",
"env": {
"ExampleENV1": "You can use variables here too, like ${absPath}"
}
}
"catch2TestExplorer.executables": [
{
"name": "Test1 suite",
"pattern": "dir/test.exe"
},
"singleTest.exe",
{
"pattern": "dir2/{t,T}est",
"cwd": "out/tmp",
"env": {}
}
]
catch2TestExplorer.debugConfigTemplate
If catch2TestExplorer.debugConfigTemplate
value is null
(default),
it will look after
extensions in order. If it founds one of it, it will use it automatically. For further details check VSCode launch config.
Remark: This feature to work automatically (value: null
) has a lot of requirements which are not listed here.
If it works it is good for you.
If it isn't.. I suggest to create your own "catch2TestExplorer.debugConfigTemplate"
template.
If you read the Related documents and still have a question feel free to open an issue.
or user can manually fill it
For vadimcn.vscode-lldb
add something like this to settings.json:
"catch2TestExplorer.debugConfigTemplate": {
"type": "cppdbg",
"MIMode": "lldb",
"program": "${exec}",
"args": "${args}",
"cwd": "${cwd}",
"env": "${envObj}",
"externalConsole": false
}
Usable variables:
Variable name | Value meaning | Type |
---|---|---|
${label} |
The name of the test. Same as in the Test Explorer. | string |
${suiteLabel} |
The name of parent suites of the test. Same as in the Test Explorer. | string |
${exec} |
The path of the executable. | string |
${argsArray} |
The arguments for the executable. | string[] |
${argsStr} |
Concatenated arguments for the executable. | string |
${cwd} |
The current working directory for execution. | string |
${envObj} |
The environment variables as object properties. | { [prop: string]: string } |
These variables will be substituted when a DebugConfiguration is created.
Note that name
and request
are filled, if they are undefined, so it is not necessary to set them.
type
is necessary.
License
MIT/X11
Known issues
- (2018-09-03) On windows the navigate to source button isn't working. It is a framework bug.
- (2018-11-17) Catch2: Long (>80 character) filename, test-name or description can cause test-list parsing failures.
Workaround:
#define CATCH_CONFIG_CONSOLE_WIDTH 300
For solving issues use: catch2TestExplorer.logpanel: true
and check the output window.
TODOs
- Test cases: google test, catch2: info, warn, fail, stdout, stderr, capture, gtest_skip