From a562430f3f3a93e26fb0696351d4dea8f2a7657c Mon Sep 17 00:00:00 2001 From: Reijo Tomperi Date: Tue, 6 Apr 2010 22:13:23 +0300 Subject: [PATCH] Add a few test cases for CppCheck::parseFromArgs --- test/testcppcheck.cpp | 39 +++++++++++++++++++++++++++++++++++++-- test/testpreprocessor.cpp | 4 +++- test/testsuite.cpp | 3 ++- 3 files changed, 42 insertions(+), 4 deletions(-) diff --git a/test/testcppcheck.cpp b/test/testcppcheck.cpp index 2c9a5c9d0..11e636f25 100644 --- a/test/testcppcheck.cpp +++ b/test/testcppcheck.cpp @@ -28,6 +28,7 @@ #include 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() diff --git a/test/testpreprocessor.cpp b/test/testpreprocessor.cpp index 08d2db93f..6223ebe87 100644 --- a/test/testpreprocessor.cpp +++ b/test/testpreprocessor.cpp @@ -31,6 +31,7 @@ #include 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"]); diff --git a/test/testsuite.cpp b/test/testsuite.cpp index c69f313ba..8df184b6c 100644 --- a/test/testsuite.cpp +++ b/test/testsuite.cpp @@ -26,6 +26,7 @@ #include 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)