Preprocessor: Unit test #error and missing includes. Ticket: #2131

This commit is contained in:
Daniel Marjamaki 2011-10-25 19:55:47 +02:00
parent 40dcab0b6b
commit 4b57a146fb
2 changed files with 23 additions and 1 deletions

View File

@ -1838,6 +1838,10 @@ std::string Preprocessor::handleIncludes(const std::string &code, const std::str
defs.erase(line.substr(7));
}
else if (line.compare(0,7,"#error ") == 0) {
error(filePath, linenr, line.substr(7));
}
ostr << line;
}

View File

@ -2828,7 +2828,7 @@ private:
const std::string filePath("test.c");
const std::list<std::string> includePaths;
std::map<std::string,std::string> defs;
Preprocessor preprocessor;
Preprocessor preprocessor(NULL, this);
// ifdef
{
@ -2928,6 +2928,24 @@ private:
ASSERT_EQUALS(actual1 + "#undef X\n" + actual1, actual);
}
// missing include
{
errout.str("");
const std::string code("#include \"missing.h\"");
const std::string actual(preprocessor.handleIncludes(code,filePath,includePaths,defs));
ASSERT_EQUALS("[test.c:1]: (information) Include file: \"missing.h\" not found.\n", errout.str());
}
// #error
{
errout.str("");
defs.clear();
const std::string code("#ifndef X\n#error abc\n#endif");
const std::string actual(preprocessor.handleIncludes(code,filePath,includePaths,defs));
ASSERT_EQUALS("\n#error abc\n\n", actual);
ASSERT_EQUALS("[test.c:2]: (error) abc\n", errout.str());
}
}
};