From b063783bc389c4c7812a61688b397a790b8030b6 Mon Sep 17 00:00:00 2001 From: Reijo Tomperi Date: Sun, 11 Apr 2010 15:25:30 +0300 Subject: [PATCH] Add some unit tests for command line argument parsing --- test/testcppcheck.cpp | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/test/testcppcheck.cpp b/test/testcppcheck.cpp index 9d3565b71..67b3ccede 100644 --- a/test/testcppcheck.cpp +++ b/test/testcppcheck.cpp @@ -26,6 +26,7 @@ #include #include +#include extern std::ostringstream errout; extern std::ostringstream output; @@ -57,7 +58,7 @@ private: TEST_CASE(include); TEST_CASE(templateFormat); TEST_CASE(getErrorMessages); - TEST_CASE(parseArgs); + TEST_CASE(parseOutputtingArgs); } void argCheck(int argc, const char *argv[]) @@ -68,7 +69,7 @@ private: cppCheck.parseFromArgs(argc, argv); } - void parseArgs() + void parseOutputtingArgs() { { const char *argv[] = {"cppcheck", "--help"}; @@ -90,6 +91,29 @@ private: ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS(std::string("Cppcheck ") + CppCheck::version() + "\n", output.str()); } + + { + const char *argv[] = {"cppcheck", "--doc"}; + argCheck(2, argv); + ASSERT_EQUALS("", errout.str()); + + // TODO: --doc prints output directly to stdout, so it can't + // be tested. Add test here when it is changed. + TODO_ASSERT_EQUALS("Something", output.str()); + } + + { + const char *argv[] = {"cppcheck", "--invalidArg"}; + try + { + argCheck(2, argv); + ASSERT_EQUALS("", "Should not come here"); + } + catch (std::runtime_error &e) + { + ASSERT_EQUALS("cppcheck: error: unrecognized command line option \"--invalidArg\"", e.what()); + } + } } void linenumbers()