Skip to content

Commit c9a5bda

Browse files
committed
Add test
1 parent 818db41 commit c9a5bda

2 files changed

Lines changed: 34 additions & 0 deletions

File tree

lib/preprocessor.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ class CPPCHECKLIB RemarkComment {
9898
* configurations that exist in a source file.
9999
*/
100100
class CPPCHECKLIB WARN_UNUSED Preprocessor {
101+
friend class TestPreprocessor;
102+
101103
public:
102104
/** character that is inserted in expanded macros */
103105
static char macroChar;

test/testpreprocessor.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,8 @@ class TestPreprocessor : public TestFixture {
371371
TEST_CASE(testMissingIncludeMixed);
372372
TEST_CASE(testMissingIncludeCheckConfig);
373373

374+
TEST_CASE(testLazyInclude);
375+
374376
TEST_CASE(hasInclude);
375377

376378
TEST_CASE(limitsDefines);
@@ -3053,6 +3055,36 @@ class TestPreprocessor : public TestFixture {
30533055
"test.c:11:2: information: Include file: <" + missing4 + "> not found. Please note: Standard library headers do not need to be provided to get proper results. [missingIncludeSystem]\n", errout_str());
30543056
}
30553057

3058+
void testLazyInclude() {
3059+
const char *code = "#ifdef CONFIG1\n"
3060+
"#include \"header1.h\"\n"
3061+
"#include \"missing1.h\"\n"
3062+
"#else\n"
3063+
"#include \"header2.h\"\n"
3064+
"#include \"missing2.h\"\n"
3065+
"#endif\n";
3066+
3067+
std::vector<std::string> files;
3068+
simplecpp::TokenList tokens(code, files, "test.c");
3069+
3070+
ScopedFile header1("header1.h", "1");
3071+
ScopedFile header2("header2.h", "2");
3072+
3073+
Settings settings;
3074+
Preprocessor preprocessor(tokens, settings, *this, Standards::Language::CPP);
3075+
3076+
simplecpp::OutputList outputList;
3077+
simplecpp::TokenList tokens2 = preprocessor.preprocess("CONFIG1", files, outputList);
3078+
std::string out = tokens2.stringify();
3079+
3080+
simplecpp::FileDataCache &cache = preprocessor.mFileCache;
3081+
3082+
ASSERT_EQUALS("\n#line 1 \"header1.h\"\n1", out);
3083+
ASSERT_EQUALS(1, outputList.size());
3084+
ASSERT_EQUALS("Header not found: \"missing1.h\"", outputList.begin()->msg);
3085+
ASSERT_EQUALS(1, cache.size());
3086+
}
3087+
30563088
void hasInclude() {
30573089
const char code[] = "#if __has_include(<directory/non-existent-header.h>)\n123\n#endif";
30583090
Settings settings;

0 commit comments

Comments
 (0)