Preprocessor: Unit test handling of missing includes in 'normal' preprocessing

This commit is contained in:
Daniel Marjamaki 2011-11-02 20:29:14 +01:00
parent dfcbc38466
commit 4fe3f8f080
1 changed files with 46 additions and 3 deletions

View File

@ -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<std::string> includePaths;
std::map<std::string,std::string> defs;
@ -2947,6 +2948,48 @@ private:
ASSERT_EQUALS("[test.c:2]: (error) abc\n", errout.str());
}
}
void def_missingInclude() {
const std::list<std::string> includePaths;
std::map<std::string,std::string> 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 <missing-include!!.h>\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)