Preprocessor: Unit test #error and missing includes. Ticket: #2131
This commit is contained in:
parent
40dcab0b6b
commit
4b57a146fb
|
@ -1838,6 +1838,10 @@ std::string Preprocessor::handleIncludes(const std::string &code, const std::str
|
||||||
defs.erase(line.substr(7));
|
defs.erase(line.substr(7));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
else if (line.compare(0,7,"#error ") == 0) {
|
||||||
|
error(filePath, linenr, line.substr(7));
|
||||||
|
}
|
||||||
|
|
||||||
ostr << line;
|
ostr << line;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2828,7 +2828,7 @@ private:
|
||||||
const std::string filePath("test.c");
|
const std::string filePath("test.c");
|
||||||
const std::list<std::string> includePaths;
|
const std::list<std::string> includePaths;
|
||||||
std::map<std::string,std::string> defs;
|
std::map<std::string,std::string> defs;
|
||||||
Preprocessor preprocessor;
|
Preprocessor preprocessor(NULL, this);
|
||||||
|
|
||||||
// ifdef
|
// ifdef
|
||||||
{
|
{
|
||||||
|
@ -2928,6 +2928,24 @@ private:
|
||||||
|
|
||||||
ASSERT_EQUALS(actual1 + "#undef X\n" + actual1, actual);
|
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());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue