TestCmdLineParser: Add tests for ignored paths

This commit is contained in:
Daniel Marjamäki 2023-01-01 15:32:37 +01:00
parent cac86ada2b
commit bf11cdf299
1 changed files with 49 additions and 55 deletions

View File

@ -159,15 +159,12 @@ private:
TEST_CASE(valueFlowMaxIterationsInvalid2);
TEST_CASE(valueFlowMaxIterationsInvalid3);
// TODO
// Disabling these tests since they use relative paths to the
// testrunner executable.
//TEST_CASE(ignorepaths1);
//TEST_CASE(ignorepaths2);
//TEST_CASE(ignorepaths3);
//TEST_CASE(ignorepaths4);
//TEST_CASE(ignorefilepaths1);
//TEST_CASE(ignorefilepaths2);
TEST_CASE(ignorepaths1);
TEST_CASE(ignorepaths2);
TEST_CASE(ignorepaths3);
TEST_CASE(ignorepaths4);
TEST_CASE(ignorefilepaths1);
TEST_CASE(ignorefilepaths2);
TEST_CASE(checkconfig);
TEST_CASE(unknownParam);
@ -1303,61 +1300,59 @@ private:
ASSERT(!defParser.parseFromArgs(2, argv));
ASSERT_EQUALS("cppcheck: error: argument to '--valueflow-max-iteration' needs to be at least 0.\n", GET_REDIRECT_OUTPUT);
}
void ignorepaths1() {
REDIRECT;
const char * const argv[] = {"cppcheck", "-isrc", "file.cpp"};
CmdLineParser parser(&settings);
ASSERT(parser.parseFromArgs(3, argv));
ASSERT_EQUALS(1, parser.getIgnoredPaths().size());
ASSERT_EQUALS("src", parser.getIgnoredPaths()[0]);
ASSERT_EQUALS("", GET_REDIRECT_OUTPUT);
}
/*
void ignorepaths1() {
REDIRECT;
const char * const argv[] = {"cppcheck", "-isrc", "file.cpp"};
CmdLineParser parser(&settings);
ASSERT(parser.parseFromArgs(3, argv));
ASSERT_EQUALS(1, parser.getIgnoredPaths().size());
ASSERT_EQUALS("src/", parser.getIgnoredPaths()[0]);
ASSERT_EQUALS("", GET_REDIRECT_OUTPUT);
}
void ignorepaths2() {
REDIRECT;
const char * const argv[] = {"cppcheck", "-i", "src", "file.cpp"};
CmdLineParser parser(&settings);
ASSERT(parser.parseFromArgs(4, argv));
ASSERT_EQUALS(1, parser.getIgnoredPaths().size());
ASSERT_EQUALS("src", parser.getIgnoredPaths()[0]);
ASSERT_EQUALS("", GET_REDIRECT_OUTPUT);
}
void ignorepaths2() {
REDIRECT;
const char * const argv[] = {"cppcheck", "-i", "src", "file.cpp"};
CmdLineParser parser(&settings);
ASSERT(parser.parseFromArgs(4, argv));
ASSERT_EQUALS(1, parser.getIgnoredPaths().size());
ASSERT_EQUALS("src/", parser.getIgnoredPaths()[0]);
ASSERT_EQUALS("", GET_REDIRECT_OUTPUT);
}
void ignorepaths3() {
REDIRECT;
const char * const argv[] = {"cppcheck", "-isrc", "-imodule", "file.cpp"};
CmdLineParser parser(&settings);
ASSERT(parser.parseFromArgs(4, argv));
ASSERT_EQUALS(2, parser.getIgnoredPaths().size());
ASSERT_EQUALS("src", parser.getIgnoredPaths()[0]);
ASSERT_EQUALS("module", parser.getIgnoredPaths()[1]);
ASSERT_EQUALS("", GET_REDIRECT_OUTPUT);
}
void ignorepaths3() {
REDIRECT;
const char * const argv[] = {"cppcheck", "-isrc", "-imodule", "file.cpp"};
CmdLineParser parser(&settings);
ASSERT(parser.parseFromArgs(4, argv));
ASSERT_EQUALS(2, parser.getIgnoredPaths().size());
ASSERT_EQUALS("src/", parser.getIgnoredPaths()[0]);
ASSERT_EQUALS("module/", parser.getIgnoredPaths()[1]);
ASSERT_EQUALS("", GET_REDIRECT_OUTPUT);
}
void ignorepaths4() {
void ignorepaths4() {
REDIRECT;
const char * const argv[] = {"cppcheck", "-i", "src", "-i", "module", "file.cpp"};
CmdLineParser parser(&settings);
ASSERT(parser.parseFromArgs(6, argv));
ASSERT_EQUALS(2, parser.getIgnoredPaths().size());
ASSERT_EQUALS("src/", parser.getIgnoredPaths()[0]);
ASSERT_EQUALS("module/", parser.getIgnoredPaths()[1]);
ASSERT_EQUALS("src", parser.getIgnoredPaths()[0]);
ASSERT_EQUALS("module", parser.getIgnoredPaths()[1]);
ASSERT_EQUALS("", GET_REDIRECT_OUTPUT);
}
}
void ignorefilepaths1() {
REDIRECT;
const char * const argv[] = {"cppcheck", "-ifoo.cpp", "file.cpp"};
CmdLineParser parser(&settings);
ASSERT(parser.parseFromArgs(3, argv));
ASSERT_EQUALS(1, parser.getIgnoredPaths().size());
ASSERT_EQUALS("foo.cpp", parser.getIgnoredPaths()[0]);
ASSERT_EQUALS("", GET_REDIRECT_OUTPUT);
}
void ignorefilepaths1() {
REDIRECT;
const char * const argv[] = {"cppcheck", "-ifoo.cpp", "file.cpp"};
CmdLineParser parser(&settings);
ASSERT(parser.parseFromArgs(3, argv));
ASSERT_EQUALS(1, parser.getIgnoredPaths().size());
ASSERT_EQUALS("foo.cpp", parser.getIgnoredPaths()[0]);
ASSERT_EQUALS("", GET_REDIRECT_OUTPUT);
}
void ignorefilepaths2() {
void ignorefilepaths2() {
REDIRECT;
const char * const argv[] = {"cppcheck", "-isrc/foo.cpp", "file.cpp"};
CmdLineParser parser(&settings);
@ -1365,8 +1360,7 @@ private:
ASSERT_EQUALS(1, parser.getIgnoredPaths().size());
ASSERT_EQUALS("src/foo.cpp", parser.getIgnoredPaths()[0]);
ASSERT_EQUALS("", GET_REDIRECT_OUTPUT);
}
*/
}
void checkconfig() {
REDIRECT;