Add more tests for CmdLineParser.

This commit is contained in:
Kimmo Varis 2010-09-06 23:16:52 +03:00
parent ce45053131
commit 1dfab9f02c
1 changed files with 123 additions and 0 deletions

View File

@ -72,6 +72,17 @@ private:
TEST_CASE(helpshort); TEST_CASE(helpshort);
TEST_CASE(helplong); TEST_CASE(helplong);
TEST_CASE(showversion); TEST_CASE(showversion);
TEST_CASE(onefile);
TEST_CASE(onepath);
TEST_CASE(optionwithoutfile);
TEST_CASE(verboseshort);
TEST_CASE(verboselong);
TEST_CASE(debug);
TEST_CASE(debugwarnings);
TEST_CASE(forceshort);
TEST_CASE(forcelong);
TEST_CASE(quietshort);
TEST_CASE(quietlong);
} }
void nooptions() void nooptions()
@ -113,6 +124,118 @@ private:
ASSERT(parser.ParseFromArgs(2, argv)); ASSERT(parser.ParseFromArgs(2, argv));
ASSERT_EQUALS(true, parser.GetShowVersion()); ASSERT_EQUALS(true, parser.GetShowVersion());
} }
void onefile()
{
REDIRECT;
const char *argv[] = {"cppcheck", "file.cpp"};
Settings settings;
CmdLineParser parser(&settings);
ASSERT(parser.ParseFromArgs(2, argv));
ASSERT_EQUALS(1, parser.GetPathNames().size());
ASSERT_EQUALS("file.cpp", parser.GetPathNames().at(0));
}
void onepath()
{
REDIRECT;
const char *argv[] = {"cppcheck", "src"};
Settings settings;
CmdLineParser parser(&settings);
ASSERT(parser.ParseFromArgs(2, argv));
ASSERT_EQUALS(1, parser.GetPathNames().size());
ASSERT_EQUALS("src", parser.GetPathNames().at(0));
}
void optionwithoutfile()
{
REDIRECT;
const char *argv[] = {"cppcheck", "-v"};
Settings settings;
CmdLineParser parser(&settings);
ASSERT_EQUALS(false, parser.ParseFromArgs(2, argv));
ASSERT_EQUALS(0, parser.GetPathNames().size());
}
void verboseshort()
{
REDIRECT;
const char *argv[] = {"cppcheck", "-v", "fíle.cpp"};
Settings settings;
CmdLineParser parser(&settings);
ASSERT(parser.ParseFromArgs(3, argv));
ASSERT_EQUALS(true, settings._verbose);
}
void verboselong()
{
REDIRECT;
const char *argv[] = {"cppcheck", "--verbose", "fíle.cpp"};
Settings settings;
CmdLineParser parser(&settings);
ASSERT(parser.ParseFromArgs(3, argv));
ASSERT_EQUALS(true, settings._verbose);
}
void debug()
{
REDIRECT;
const char *argv[] = {"cppcheck", "--debug", "fíle.cpp"};
Settings settings;
CmdLineParser parser(&settings);
ASSERT(parser.ParseFromArgs(3, argv));
ASSERT_EQUALS(true, settings.debug);
}
void debugwarnings()
{
REDIRECT;
const char *argv[] = {"cppcheck", "--debug-warnings", "fíle.cpp"};
Settings settings;
CmdLineParser parser(&settings);
ASSERT(parser.ParseFromArgs(3, argv));
ASSERT_EQUALS(true, settings.debugwarnings);
}
void forceshort()
{
REDIRECT;
const char *argv[] = {"cppcheck", "-f", "fíle.cpp"};
Settings settings;
CmdLineParser parser(&settings);
ASSERT(parser.ParseFromArgs(3, argv));
ASSERT_EQUALS(true, settings._force);
}
void forcelong()
{
REDIRECT;
const char *argv[] = {"cppcheck", "--force", "fíle.cpp"};
Settings settings;
CmdLineParser parser(&settings);
ASSERT(parser.ParseFromArgs(3, argv));
ASSERT_EQUALS(true, settings._force);
}
void quietshort()
{
REDIRECT;
const char *argv[] = {"cppcheck", "-q", "fíle.cpp"};
Settings settings;
CmdLineParser parser(&settings);
ASSERT(parser.ParseFromArgs(3, argv));
ASSERT_EQUALS(true, settings._errorsOnly);
}
void quietlong()
{
REDIRECT;
const char *argv[] = {"cppcheck", "--quiet", "fíle.cpp"};
Settings settings;
CmdLineParser parser(&settings);
ASSERT(parser.ParseFromArgs(3, argv));
ASSERT_EQUALS(true, settings._errorsOnly);
}
}; };
REGISTER_TEST(TestCmdlineParser) REGISTER_TEST(TestCmdlineParser)