fixed #11919 - Removed deprecated command-line options `--template <template>` and `--template-format=<template>` (#5439)

This commit is contained in:
Oliver Stöneberg 2023-09-12 22:46:40 +02:00 committed by GitHub
parent a87e9e1042
commit 98ce46a3e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 57 deletions

View File

@ -898,20 +898,9 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
} }
// Output formatter // Output formatter
else if (std::strcmp(argv[i], "--template") == 0 || else if (std::strncmp(argv[i], "--template=", 11) == 0) {
std::strncmp(argv[i], "--template=", 11) == 0) { mSettings.templateFormat = argv[i] + 11;
// "--template format" // TODO: bail out when no template is provided?
if (argv[i][10] == '=')
mSettings.templateFormat = argv[i] + 11;
else if ((i+1) < argc && argv[i+1][0] != '-') {
printMessage("'--template <template>' is deprecated and will be removed in 2.13 - please use '--template=<template>' instead");
++i;
mSettings.templateFormat = argv[i];
} else {
printError("argument to '--template' is missing.");
return false;
}
// TODO: bail out when no placeholders are found?
if (mSettings.templateFormat == "gcc") { if (mSettings.templateFormat == "gcc") {
mSettings.templateFormat = "{bold}{file}:{line}:{column}: {magenta}warning:{default} {message} [{id}]{reset}\\n{code}"; mSettings.templateFormat = "{bold}{file}:{line}:{column}: {magenta}warning:{default} {message} [{id}]{reset}\\n{code}";
@ -931,21 +920,12 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
mSettings.templateLocation = "{file}:{line}:{column}: note: {info}\\n{code}"; mSettings.templateLocation = "{file}:{line}:{column}: note: {info}\\n{code}";
mSettings.daca = true; mSettings.daca = true;
} }
// TODO: bail out when no placeholders are found?
} }
else if (std::strcmp(argv[i], "--template-location") == 0 || else if (std::strncmp(argv[i], "--template-location=", 20) == 0) {
std::strncmp(argv[i], "--template-location=", 20) == 0) { mSettings.templateLocation = argv[i] + 20;
// "--template-location format" // TODO: bail out when no template is provided?
if (argv[i][19] == '=')
mSettings.templateLocation = argv[i] + 20;
else if ((i+1) < argc && argv[i+1][0] != '-') {
printMessage("'--template-location <template>' is deprecated and will be removed in 2.13 - please use '--template-location=<template>' instead");
++i;
mSettings.templateLocation = argv[i];
} else {
printError("argument to '--template-location' is missing.");
return false;
}
// TODO: bail out when no placeholders are found? // TODO: bail out when no placeholders are found?
} }

View File

@ -14,3 +14,4 @@ Changed interface:
Other: Other:
- Windows builds now default to the `native` platform instead of `win32A` or `win64`. Please specify it explicitly if you depedent on it. - Windows builds now default to the `native` platform instead of `win32A` or `win64`. Please specify it explicitly if you depedent on it.
- The undocumented and deprecated command-line options `--template <template>` and `--template-format <template>` has been removed. Please use `--template=` and `--template-format=` instead.

View File

@ -179,10 +179,8 @@ private:
TEST_CASE(templatesSelfcheck); TEST_CASE(templatesSelfcheck);
TEST_CASE(templatesNoPlaceholder); TEST_CASE(templatesNoPlaceholder);
TEST_CASE(templateFormatInvalid); TEST_CASE(templateFormatInvalid);
TEST_CASE(templateFormatInvalid2);
TEST_CASE(templateFormatEmpty); TEST_CASE(templateFormatEmpty);
TEST_CASE(templateLocationInvalid); TEST_CASE(templateLocationInvalid);
TEST_CASE(templateLocationInvalid2);
TEST_CASE(templateLocationEmpty); TEST_CASE(templateLocationEmpty);
TEST_CASE(xml); TEST_CASE(xml);
TEST_CASE(xmlver2); TEST_CASE(xmlver2);
@ -1416,24 +1414,12 @@ private:
} }
void templateFormatInvalid() { void templateFormatInvalid() {
REDIRECT;
const char* const argv[] = { "cppcheck", "--template", "--template-location={file}", "file.cpp" };
ASSERT(!parser->parseFromArgs(4, argv));
ASSERT_EQUALS("cppcheck: error: argument to '--template' is missing.\n", GET_REDIRECT_OUTPUT);
}
// TODO: will not error out as he next option does not start with a "-"
void templateFormatInvalid2() {
REDIRECT; REDIRECT;
settings->templateFormat.clear(); settings->templateFormat.clear();
settings->templateLocation.clear(); settings->templateLocation.clear();
const char* const argv[] = { "cppcheck", "--template", "file.cpp" }; const char* const argv[] = { "cppcheck", "--template", "file.cpp" };
ASSERT(!parser->parseFromArgs(3, argv)); ASSERT(!parser->parseFromArgs(3, argv));
ASSERT_EQUALS("file.cpp", settings->templateFormat); ASSERT_EQUALS("cppcheck: error: unrecognized command line option: \"--template\".\n", GET_REDIRECT_OUTPUT);
ASSERT_EQUALS("", settings->templateLocation);
TODO_ASSERT_EQUALS("cppcheck: error: argument to '--template' is missing.\n",
"cppcheck: '--template <template>' is deprecated and will be removed in 2.13 - please use '--template=<template>' instead\n"
"cppcheck: error: no C or C++ source files found.\n", GET_REDIRECT_OUTPUT);
} }
// will use the default // will use the default
@ -1453,21 +1439,7 @@ private:
REDIRECT; REDIRECT;
const char* const argv[] = { "cppcheck", "--template-location", "--template={file}", "file.cpp" }; const char* const argv[] = { "cppcheck", "--template-location", "--template={file}", "file.cpp" };
ASSERT(!parser->parseFromArgs(4, argv)); ASSERT(!parser->parseFromArgs(4, argv));
ASSERT_EQUALS("cppcheck: error: argument to '--template-location' is missing.\n", GET_REDIRECT_OUTPUT); ASSERT_EQUALS("cppcheck: error: unrecognized command line option: \"--template-location\".\n", GET_REDIRECT_OUTPUT);
}
// TODO: will not error out as the next option does not start with a "-"
void templateLocationInvalid2() {
REDIRECT;
settings->templateFormat.clear();
settings->templateLocation.clear();
const char* const argv[] = { "cppcheck", "--template-location", "file.cpp" };
ASSERT(!parser->parseFromArgs(3, argv));
ASSERT_EQUALS("{file}:{line}:{column}: {inconclusive:}{severity}:{inconclusive: inconclusive:} {message} [{id}]\n{code}", settings->templateFormat);
ASSERT_EQUALS("file.cpp", settings->templateLocation);
TODO_ASSERT_EQUALS("",
"cppcheck: '--template-location <template>' is deprecated and will be removed in 2.13 - please use '--template-location=<template>' instead\n"
"cppcheck: error: no C or C++ source files found.\n", GET_REDIRECT_OUTPUT);
} }
// will use the default // will use the default