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