Add a few test cases for CppCheck::parseFromArgs
This commit is contained in:
parent
2e11805c1a
commit
a562430f3f
|
@ -28,6 +28,7 @@
|
|||
#include <string>
|
||||
|
||||
extern std::ostringstream errout;
|
||||
extern std::ostringstream output;
|
||||
|
||||
class TestCppcheck : public TestFixture
|
||||
{
|
||||
|
@ -40,6 +41,7 @@ private:
|
|||
void check(const std::string &data)
|
||||
{
|
||||
errout.str("");
|
||||
output.str("");
|
||||
CppCheck cppCheck(*this);
|
||||
cppCheck.addFile("file.cpp", data);
|
||||
cppCheck.check();
|
||||
|
@ -55,6 +57,39 @@ private:
|
|||
TEST_CASE(include);
|
||||
TEST_CASE(templateFormat);
|
||||
TEST_CASE(getErrorMessages);
|
||||
TEST_CASE(parseArgs);
|
||||
}
|
||||
|
||||
void argCheck(int argc, const char *argv[])
|
||||
{
|
||||
errout.str("");
|
||||
output.str("");
|
||||
CppCheck cppCheck(*this);
|
||||
cppCheck.parseFromArgs(argc, argv);
|
||||
}
|
||||
|
||||
void parseArgs()
|
||||
{
|
||||
{
|
||||
const char *argv[] = {"cppcheck", "--help"};
|
||||
argCheck(2, argv);
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
ASSERT_EQUALS(true, output.str().find("Example usage") != std::string::npos);
|
||||
}
|
||||
|
||||
{
|
||||
const char *argv[] = {"cppcheck"};
|
||||
argCheck(1, argv);
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
ASSERT_EQUALS(true, output.str().find("Example usage") != std::string::npos);
|
||||
}
|
||||
|
||||
{
|
||||
const char *argv[] = {"cppcheck", "--version"};
|
||||
argCheck(2, argv);
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
ASSERT_EQUALS(std::string("Cppcheck ") + CppCheck::version() + "\n", output.str());
|
||||
}
|
||||
}
|
||||
|
||||
void linenumbers()
|
||||
|
@ -68,8 +103,8 @@ private:
|
|||
check(filedata);
|
||||
|
||||
// Compare results..
|
||||
ASSERT_EQUALS("Checking file.cpp...\n"
|
||||
"[file.cpp:5]: (error) Dereferencing 'foo' after it is deallocated / released\n", errout.str());
|
||||
ASSERT_EQUALS("Checking file.cpp...\n", output.str());
|
||||
ASSERT_EQUALS("[file.cpp:5]: (error) Dereferencing 'foo' after it is deallocated / released\n", errout.str());
|
||||
}
|
||||
|
||||
void linenumbers2()
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
#include <stdexcept>
|
||||
|
||||
extern std::ostringstream errout;
|
||||
extern std::ostringstream output;
|
||||
|
||||
class TestPreprocessor : public TestFixture
|
||||
{
|
||||
|
@ -1050,6 +1051,7 @@ private:
|
|||
"#endif\n";
|
||||
|
||||
errout.str("");
|
||||
output.str("");
|
||||
|
||||
// Preprocess => actual result..
|
||||
std::istringstream istr(filedata);
|
||||
|
@ -1065,7 +1067,7 @@ private:
|
|||
ASSERT_EQUALS("\n\n\n", actual[""]);
|
||||
|
||||
// the "defined(DEF_10) || defined(DEF_11)" are not handled correctly..
|
||||
ASSERT_EQUALS("unhandled configuration: defined(DEF_10)||defined(DEF_11)\n", errout.str());
|
||||
ASSERT_EQUALS("unhandled configuration: defined(DEF_10)||defined(DEF_11)\n", output.str());
|
||||
TODO_ASSERT_EQUALS(2, actual.size());
|
||||
TODO_ASSERT_EQUALS("\na1;\n\n", actual["DEF_10"]);
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
#include <list>
|
||||
|
||||
std::ostringstream errout;
|
||||
std::ostringstream output;
|
||||
|
||||
/**
|
||||
* TestRegistry
|
||||
|
@ -201,7 +202,7 @@ size_t TestFixture::runTests(const char cmd[])
|
|||
|
||||
void TestFixture::reportOut(const std::string & outmsg)
|
||||
{
|
||||
errout << outmsg << std::endl;
|
||||
output << outmsg << std::endl;
|
||||
}
|
||||
|
||||
void TestFixture::reportErr(const ErrorLogger::ErrorMessage &msg)
|
||||
|
|
Loading…
Reference in New Issue