New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
clang-tidy gives warnings of unused variables in test cases when compiled without doctest #691
Comments
I was originally looking into introducing a custom config option to consume the input of the macro invocations, but on second thought the combination of defining |
It's closer, but not quite there. Try the following code: #include "doctest/doctest.h"
#include <string>
static std::string read_file(const std::string &filename) {
return filename; // just for quick test
}
TEST_CASE("export") {
auto input = "test1";
CHECK(input == read_file(input));
} Compile like this: cc -c -std=c++20 -Wall -Wpedantic -Werror -g -DDOCTEST_CONFIG_DISABLE -DDOCTEST_CONFIG_EVALUATE_ASSERTS_EVEN_WHEN_DISABLED -DDOCTEST_CONFIG_ASSERTS_RETURN_VALUES -I/path/to/doctest foo.cpp On my MacOS machine (Apple clang version 14.0.0 (clang-1400.0.29.102)), this gives the following error:
If I remove
So whether I include |
Any news on this? I also seem to be hitting this problem (#748). |
Description
clang-tidy gives warnings of unused variables in test cases when compiled without doctest.
Clang-tidy uses some clever methods to omit test cases from the binary when compiled with
DOCTEST_CONFIG_DISABLE
, but the test case code is still present (not #ifdefed out) so clang-tidy still sees it, and since theCHECK
s are compiled out, it sees unused vars.We run clang-tidy with warnings as errors, so this causes clang-tidy failures for us.
Steps to reproduce
When compiled with
DOCTEST_CONFIG_DISABLE
, the test case function declares an unused variablei
, which clang-tidy complains about. I'm not sure if anything can be done about this; doctest can insert a// NOLINTBEGIN
but it can't insert the final// NOLINTEND
for the same reason it can't just#ifdef
out the whole test -- there's no marker for the test end.Extra information
The text was updated successfully, but these errors were encountered: