@@ -259,6 +259,10 @@ class TestPreprocessor : public TestFixture {
259259 TEST_CASE (testDirectiveIncludeComments);
260260
261261 TEST_CASE (testMissingInclude);
262+ TEST_CASE (testMissingInclude2);
263+ TEST_CASE (testMissingSystemInclude);
264+ TEST_CASE (testMissingSystemInclude2);
265+ TEST_CASE (testMissingIncludeMixed);
262266 TEST_CASE (testMissingIncludeCheckConfig);
263267 }
264268
@@ -2432,11 +2436,111 @@ class TestPreprocessor : public TestFixture {
24322436 ASSERT_EQUALS (dumpdata, ostr.str ());
24332437 }
24342438
2439+ // TODO: test with absolute path
2440+ // TODO: test with include path
2441+
24352442 void testMissingInclude () {
24362443 Preprocessor::missingIncludeFlag = false ;
24372444 Preprocessor::missingSystemIncludeFlag = false ;
24382445
24392446 Settings settings;
2447+ settings.clearIncludeCache = true ;
2448+ settings.severity .clear ();
2449+ settings.checks .enable (Checks::missingInclude);
2450+ Preprocessor preprocessor (settings, this );
2451+
2452+ ScopedFile header (" header.h" , " " );
2453+
2454+ std::string code (" #include \" header.h\" " );
2455+ errout.str (" " );
2456+ preprocessor.getcode (code, " " , " test.c" );
2457+ ASSERT_EQUALS (false , Preprocessor::missingIncludeFlag);
2458+ ASSERT_EQUALS (false , Preprocessor::missingSystemIncludeFlag);
2459+
2460+ // the expected messages are emitted outside of the Preprocessor
2461+ ASSERT_EQUALS (" " , errout.str ());
2462+
2463+ Preprocessor::missingIncludeFlag = false ;
2464+ Preprocessor::missingSystemIncludeFlag = false ;
2465+ }
2466+
2467+ void testMissingInclude2 () {
2468+ Preprocessor::missingIncludeFlag = false ;
2469+ Preprocessor::missingSystemIncludeFlag = false ;
2470+
2471+ Settings settings;
2472+ settings.clearIncludeCache = true ;
2473+ settings.severity .clear ();
2474+ settings.checks .enable (Checks::missingInclude);
2475+ Preprocessor preprocessor (settings, this );
2476+
2477+ std::string code (" #include \" header.h\" " );
2478+ errout.str (" " );
2479+ preprocessor.getcode (code, " " , " test.c" );
2480+ ASSERT_EQUALS (true , Preprocessor::missingIncludeFlag);
2481+ ASSERT_EQUALS (false , Preprocessor::missingSystemIncludeFlag);
2482+
2483+ // the expected messages are emitted outside of the Preprocessor
2484+ ASSERT_EQUALS (" " , errout.str ());
2485+
2486+ Preprocessor::missingIncludeFlag = false ;
2487+ Preprocessor::missingSystemIncludeFlag = false ;
2488+ }
2489+
2490+ void testMissingSystemInclude () {
2491+ Preprocessor::missingIncludeFlag = false ;
2492+ Preprocessor::missingSystemIncludeFlag = false ;
2493+
2494+ Settings settings;
2495+ settings.clearIncludeCache = true ;
2496+ settings.severity .clear ();
2497+ settings.checks .enable (Checks::missingInclude);
2498+ Preprocessor preprocessor (settings, this );
2499+
2500+ ScopedFile header (" header.h" , " " );
2501+
2502+ std::string code (" #include <header.h>" );
2503+ errout.str (" " );
2504+ preprocessor.getcode (code, " " , " test.c" );
2505+ ASSERT_EQUALS (false , Preprocessor::missingIncludeFlag);
2506+ ASSERT_EQUALS (false , Preprocessor::missingSystemIncludeFlag);
2507+
2508+ // the expected messages are emitted outside of the Preprocessor
2509+ ASSERT_EQUALS (" " , errout.str ());
2510+
2511+ Preprocessor::missingIncludeFlag = false ;
2512+ Preprocessor::missingSystemIncludeFlag = false ;
2513+ }
2514+
2515+ void testMissingSystemInclude2 () {
2516+ Preprocessor::missingIncludeFlag = false ;
2517+ Preprocessor::missingSystemIncludeFlag = false ;
2518+
2519+ Settings settings;
2520+ settings.clearIncludeCache = true ;
2521+ settings.severity .clear ();
2522+ settings.checks .enable (Checks::missingInclude);
2523+ Preprocessor preprocessor (settings, this );
2524+
2525+ std::string code (" #include <header.h>" );
2526+ errout.str (" " );
2527+ preprocessor.getcode (code, " " , " test.c" );
2528+ ASSERT_EQUALS (false , Preprocessor::missingIncludeFlag);
2529+ ASSERT_EQUALS (true , Preprocessor::missingSystemIncludeFlag);
2530+
2531+ // the expected messages are emitted outside of the Preprocessor
2532+ ASSERT_EQUALS (" " , errout.str ());
2533+
2534+ Preprocessor::missingIncludeFlag = false ;
2535+ Preprocessor::missingSystemIncludeFlag = false ;
2536+ }
2537+
2538+ void testMissingIncludeMixed () {
2539+ Preprocessor::missingIncludeFlag = false ;
2540+ Preprocessor::missingSystemIncludeFlag = false ;
2541+
2542+ Settings settings;
2543+ settings.clearIncludeCache = true ;
24402544 settings.severity .clear ();
24412545 settings.checks .enable (Checks::missingInclude);
24422546 Preprocessor preprocessor (settings, this );
@@ -2465,6 +2569,7 @@ class TestPreprocessor : public TestFixture {
24652569 Preprocessor::missingSystemIncludeFlag = false ;
24662570
24672571 Settings settings;
2572+ settings.clearIncludeCache = true ;
24682573 settings.checkConfiguration = true ;
24692574 settings.severity .clear ();
24702575 // needs to be reported regardless of enabled checks
0 commit comments