From 4fe3f8f080a908c7ff9ffb98fa8c62fdcca0e782 Mon Sep 17 00:00:00 2001 From: Daniel Marjamaki Date: Wed, 2 Nov 2011 20:29:14 +0100 Subject: [PATCH] Preprocessor: Unit test handling of missing includes in 'normal' preprocessing --- test/testpreprocessor.cpp | 49 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 46 insertions(+), 3 deletions(-) diff --git a/test/testpreprocessor.cpp b/test/testpreprocessor.cpp index 3a0e2f10c..a23eb8a64 100644 --- a/test/testpreprocessor.cpp +++ b/test/testpreprocessor.cpp @@ -227,8 +227,9 @@ private: TEST_CASE(simplifyCondition); TEST_CASE(invalidElIf); // #2942 segfault - // Test Preprocessor::handleIncludes (defines are given) - TEST_CASE(handleIncludes_def); + // Defines are given: test Preprocessor::handleIncludes + TEST_CASE(def_handleIncludes); + TEST_CASE(def_missingInclude); } @@ -2824,7 +2825,7 @@ private: ASSERT_EQUALS("\n", actual); } - void handleIncludes_def() { + void def_handleIncludes() { const std::string filePath("test.c"); const std::list includePaths; std::map defs; @@ -2947,6 +2948,48 @@ private: ASSERT_EQUALS("[test.c:2]: (error) abc\n", errout.str()); } } + + void def_missingInclude() { + const std::list includePaths; + std::map defs; + defs["AA"] = ""; + Settings settings; + Preprocessor preprocessor(&settings,this); + + // missing local include + { + const std::string code("#include \"missing-include!!.h\"\n"); + + errout.str(""); + preprocessor.handleIncludes(code,"test.c",includePaths,defs); + ASSERT_EQUALS("[test.c:1]: (information) Include file: \"missing-include!!.h\" not found.\n", errout.str()); + + errout.str(""); + settings.nomsg.addSuppression("missingInclude"); + preprocessor.handleIncludes(code,"test.c",includePaths,defs); + ASSERT_EQUALS("", errout.str()); + } + + // missing system header + { + const std::string code("#include \n"); + + errout.str(""); + settings = Settings(); + preprocessor.handleIncludes(code,"test.c",includePaths,defs); + ASSERT_EQUALS("", errout.str()); + + errout.str(""); + settings.debugwarnings = true; + preprocessor.handleIncludes(code,"test.c",includePaths,defs); + ASSERT_EQUALS("[test.c:1]: (debug) Include file: \"missing-include!!.h\" not found.\n", errout.str()); + + errout.str(""); + settings.nomsg.addSuppression("missingInclude"); + preprocessor.handleIncludes(code,"test.c",includePaths,defs); + ASSERT_EQUALS("", errout.str()); + } + } }; REGISTER_TEST(TestPreprocessor)