From 3c8ffb90ddbbaa382b304d1a15564c66c0bf4294 Mon Sep 17 00:00:00 2001 From: Kimmo Varis Date: Wed, 8 Sep 2010 18:02:22 +0300 Subject: [PATCH] Add tests for userdefines and userincludes for CmdLineParser. --- test/testcmdlineparser.cpp | 56 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/test/testcmdlineparser.cpp b/test/testcmdlineparser.cpp index c4d9e9c07..e18c15c45 100644 --- a/test/testcmdlineparser.cpp +++ b/test/testcmdlineparser.cpp @@ -83,6 +83,11 @@ private: TEST_CASE(forcelong); TEST_CASE(quietshort); TEST_CASE(quietlong); + TEST_CASE(defines); + TEST_CASE(defines2); + TEST_CASE(includesnopath); + TEST_CASE(includes); + TEST_CASE(includes2); } void nooptions() @@ -236,6 +241,57 @@ private: ASSERT(parser.ParseFromArgs(3, argv)); ASSERT_EQUALS(true, settings._errorsOnly); } + + void defines() + { + REDIRECT; + const char *argv[] = {"cppcheck", "-D_WIN32", "file.cpp"}; + Settings settings; + CmdLineParser parser(&settings); + ASSERT(parser.ParseFromArgs(3, argv)); + ASSERT_EQUALS("_WIN32", settings.userDefines); + } + + void defines2() + { + REDIRECT; + const char *argv[] = {"cppcheck", "-D_WIN32", "-DNODEBUG", "file.cpp"}; + Settings settings; + CmdLineParser parser(&settings); + ASSERT(parser.ParseFromArgs(4, argv)); + ASSERT_EQUALS("_WIN32;NODEBUG", settings.userDefines); + } + + void includesnopath() + { + REDIRECT; + const char *argv[] = {"cppcheck", "-I", "file.cpp"}; + Settings settings; + CmdLineParser parser(&settings); + ASSERT_EQUALS(false, parser.ParseFromArgs(3, argv)); + } + + void includes() + { + REDIRECT; + const char *argv[] = {"cppcheck", "-I include", "file.cpp"}; + Settings settings; + CmdLineParser parser(&settings); + ASSERT(parser.ParseFromArgs(3, argv)); + ASSERT_EQUALS(" include/", settings._includePaths.front()); + } + + void includes2() + { + REDIRECT; + const char *argv[] = {"cppcheck", "-I include/", "-I framework/", "file.cpp"}; + Settings settings; + CmdLineParser parser(&settings); + ASSERT(parser.ParseFromArgs(4, argv)); + ASSERT_EQUALS(" include/", settings._includePaths.front()); + settings._includePaths.pop_front(); + ASSERT_EQUALS(" framework/", settings._includePaths.front()); + } }; REGISTER_TEST(TestCmdlineParser)