Skip to content

Commit 9dd0f16

Browse files
committed
add hasInclude tests
1 parent 6771527 commit 9dd0f16

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

test/testpreprocessor.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,8 @@ class TestPreprocessor : public TestFixture {
292292
TEST_CASE(testMissingIncludeMixed);
293293
TEST_CASE(testMissingIncludeCheckConfig);
294294

295+
TEST_CASE(hasInclude);
296+
295297
TEST_CASE(limitsDefines);
296298

297299
TEST_CASE(hashCalculation);
@@ -2567,6 +2569,23 @@ class TestPreprocessor : public TestFixture {
25672569
"test.c:11:0: information: Include file: <" + missing4 + "> not found. Please note: Cppcheck does not need standard library headers to get proper results. [missingIncludeSystem]\n", errout_str());
25682570
}
25692571

2572+
void hasInclude() {
2573+
const char code[] = "#if __has_include(<directory/non-existent-header.h>)\n123\n#endif";
2574+
Settings settings;
2575+
2576+
settings.standards.setStd("c++11");
2577+
ASSERT_EQUALS("", PreprocessorHelper::getcode(settings, *this, code, "", "test.cpp"));
2578+
ASSERT_EQUALS("[test.cpp:1:0]: (error) failed to evaluate #if condition, division/modulo by zero [preprocessorErrorDirective]\n", errout_str());
2579+
2580+
settings.standards.setStd("c++17");
2581+
ASSERT_EQUALS("", PreprocessorHelper::getcode(settings, *this, code, "", "test.cpp"));
2582+
ASSERT_EQUALS("", errout_str());
2583+
2584+
settings.standards.setStd("gnu++11");
2585+
ASSERT_EQUALS("", PreprocessorHelper::getcode(settings, *this, code, "", "test.cpp"));
2586+
ASSERT_EQUALS("", errout_str());
2587+
}
2588+
25702589
void limitsDefines() {
25712590
// #11928 / #10045
25722591
const char code[] = "void f(long l) {\n"

0 commit comments

Comments
 (0)