Skip to content

Commit

Permalink
refs #13617 - disallow using --debug --xml with multiple input file…
Browse files Browse the repository at this point in the history
…s for now (#7280)
  • Loading branch information
firewave authored Feb 5, 2025
1 parent cdf9d6d commit ba73164
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
6 changes: 6 additions & 0 deletions cli/cmdlineparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1600,6 +1600,12 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
mFileSettings = project.fileSettings;
}

if (mSettings.debugnormal && mSettings.outputFormat == Settings::OutputFormat::xml && (mPathNames.size() > 1 || mFileSettings.size() > 1))
{
mLogger.printError("printing debug output in XML format does not support multiple input files.");
return Result::Fail;
}

// Use paths _pathnames if no base paths for relative path output are given
if (mSettings.basePaths.empty() && mSettings.relativePaths)
mSettings.basePaths = mPathNames;
Expand Down
16 changes: 16 additions & 0 deletions test/testcmdlineparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,8 @@ class TestCmdlineParser : public TestFixture {
TEST_CASE(maxTemplateRecursionMissingCount);
TEST_CASE(emitDuplicates);
TEST_CASE(debugClangOutput);
TEST_CASE(debugXmlMultiple);
TEST_CASE(debugNormalXmlMultiple);

TEST_CASE(ignorepaths1);
TEST_CASE(ignorepaths2);
Expand Down Expand Up @@ -2926,6 +2928,20 @@ class TestCmdlineParser : public TestFixture {
ASSERT_EQUALS(true, settings->debugClangOutput);
}

void debugXmlMultiple() {
REDIRECT;
const char * const argv[] = {"cppcheck", "--debug", "--xml", "1.cpp", "2.cpp"};
ASSERT_EQUALS_ENUM(CmdLineParser::Result::Fail, parser->parseFromArgs(5, argv));
ASSERT_EQUALS("cppcheck: error: printing debug output in XML format does not support multiple input files.\n", logger->str());
}

void debugNormalXmlMultiple() {
REDIRECT;
const char * const argv[] = {"cppcheck", "--debug-normal", "--xml", "1.cpp", "2.cpp"};
ASSERT_EQUALS_ENUM(CmdLineParser::Result::Fail, parser->parseFromArgs(5, argv));
ASSERT_EQUALS("cppcheck: error: printing debug output in XML format does not support multiple input files.\n", logger->str());
}

void ignorepaths1() {
REDIRECT;
const char * const argv[] = {"cppcheck", "-isrc", "file.cpp"};
Expand Down

0 comments on commit ba73164

Please sign in to comment.