-
Notifications
You must be signed in to change notification settings - Fork 4
Integration with editors
Warning
Again, this is now outdated, the switch to JSON reports made integration with text editors a lot easier
Currently, Catch2 has no official editor integration facilities, but if your editor can take it; you can easily configure it to do what you want when you want and in the way you want.
Catch2 already has most of the functionality required to integrate with most text editors and IDEs. Mainly, the output from XML reporters is structured in a simple straightforward way which makes it easy to convert those reports to JSON, a format most text editors understand.
There is a Alltest.oneFile script
which compiles and executes tests only mentioned in a single file you pass to the script.
The report is consolidated into reports/<libName>.xml
which can be fed to xq
(a utility to convert XML to JSON and treat in a jq
style).
You don't have to wait for tests in other files to compile and execute. We make test results available to the text editor as soon as possible by compiling and executing only tests in the file you pass to the script as an argument
A sample of what can be done by integrating foamUT tests with Neovim for example is shown bellow (This can be done in approx. 150 lines of Lua code):
To parse the generated consolidated XML report into usable JSON objects,
you can use the following xq
command:
# This supports multiple expressions in a test case:
# TEST_CASE("....", "[case1][case2][serial][parallel]")
# {
# REQUIRE(...);
# CHECK(...);
# }
#
# To install (yes, it's a y, not x): pip install yq
#
# $par denotes the parent <TestCase> tag, which you can use to retrieve some metadata about the
# test run.
xq '[ .AllTestsForFile.Catch2TestRun[]
| select(.) as $par | .. | select(.Expression? // empty) |
if (.Expression | type == "array") then
.Expression[] |
{
"name": $par."@name",
"proc": $par."@proc",
"version": $par."@catch2-version",
"filters": $par."@filters",
"success": ."@success",
"filename": ."@filename",
"line": ."@line",
"version": $par."@catch2-version",
"full": .
}
else
{
"name": $par."@name",
"proc": $par."@proc",
"version": $par."@catch2-version",
"filters": $par."@filters",
"success": .Expression."@success",
"filename": .Expression."@filename",
"line": .Expression."@line",
"version": $par."@catch2-version"
}
end
]' reports/exampleTests.xml
“This offering is not approved or endorsed by OpenCFD Limited, the producer of the OpenFOAM software and owner of the OPENFOAM® and OpenCFD® trade marks.”
This is foamUT Wiki, here is a link back to Home