Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions cli/cmdlineparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1200,6 +1200,9 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
mSettings.templateFormat = "{file}:{line}:{column}: {severity}:{inconclusive:inconclusive:} {message} [{id}]\\n{code}";
mSettings.templateLocation = "{file}:{line}:{column}: note: {info}\\n{code}";
mSettings.daca = true;
} else if (mSettings.templateFormat == "simple") {
mSettings.templateFormat = "{file}:{line}:{column}: {severity}:{inconclusive:inconclusive:} {message} [{id}]";
mSettings.templateLocation = "";
}
// TODO: bail out when no placeholders are found?
}
Expand Down
1 change: 1 addition & 0 deletions releasenotes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ Other:
- The minimum required compiler versions have been bumped to GCC 5.1 / Clang 3.5 / Visual Studio 2015
- The minimum required CMake version has been bumped to 3.5
- Using Visual Studio with CMake now checks if the CMake version is at least 3.13. This was always required but was not checked explicitly.
- Added '--template=simple'. It is expands to '{file}:{line}:{column}: {severity}:{inconclusive:inconclusive:} {message} [{id}]' without any additional location details.
2 changes: 1 addition & 1 deletion test/cli/helloworld_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ def test_checkers_report():


def __test_missing_include_system(use_j):
args = ['--enable=missingInclude', '--suppress=zerodiv', '--template={file}:{line}:{column}: {severity}:{inconclusive:inconclusive:} {message} [{id}]', 'helloworld']
args = ['--enable=missingInclude', '--suppress=zerodiv', '--template=simple', 'helloworld']
if use_j:
args.insert(0, '-j2')

Expand Down
14 changes: 7 additions & 7 deletions test/cli/other_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def __test_missing_include(tmpdir, use_j):
#include "test.h"
""")

args = ['--enable=missingInclude', '--template={file}:{line}:{column}: {severity}:{inconclusive:inconclusive:} {message} [{id}]', test_file]
args = ['--enable=missingInclude', '--template=simple', test_file]
if use_j:
args.insert(0, '-j2')

Expand Down Expand Up @@ -247,7 +247,7 @@ def test_addon_y2038(tmpdir):
}
""")

args = ['--addon=y2038', '--enable=all', '--template={file}:{line}:{column}: {severity}:{inconclusive:inconclusive:} {message} [{id}]', test_file]
args = ['--addon=y2038', '--enable=all', '--template=simple', test_file]

exitcode, stdout, stderr = cppcheck(args)
assert exitcode == 0
Expand All @@ -268,7 +268,7 @@ def test_addon_threadsafety(tmpdir):
}
""")

args = ['--addon=threadsafety', '--enable=all', '--template={file}:{line}:{column}: {severity}:{inconclusive:inconclusive:} {message} [{id}]', test_file]
args = ['--addon=threadsafety', '--enable=all', '--template=simple', test_file]

exitcode, stdout, stderr = cppcheck(args)
assert exitcode == 0
Expand Down Expand Up @@ -298,7 +298,7 @@ def test_addon_naming(tmpdir):
int Var;
""")

args = ['--addon={}'.format(addon_file), '--enable=all', '--template={file}:{line}:{column}: {severity}:{inconclusive:inconclusive:} {message} [{id}]', test_file]
args = ['--addon={}'.format(addon_file), '--enable=all', '--template=simple', test_file]

exitcode, stdout, stderr = cppcheck(args)
assert exitcode == 0
Expand Down Expand Up @@ -590,7 +590,7 @@ def test_addon_findcasts(tmpdir):
}
""")

args = ['--addon=findcasts', '--enable=all', '--template={file}:{line}:{column}: {severity}:{inconclusive:inconclusive:} {message} [{id}]', test_file]
args = ['--addon=findcasts', '--enable=all', '--template=simple', test_file]

exitcode, stdout, stderr = cppcheck(args)
assert exitcode == 0
Expand All @@ -611,7 +611,7 @@ def test_addon_misc(tmpdir):
}
""")

args = ['--addon=misc', '--enable=all', '--template={file}:{line}:{column}: {severity}:{inconclusive:inconclusive:} {message} [{id}]', test_file]
args = ['--addon=misc', '--enable=all', '--template=simple', test_file]

exitcode, stdout, stderr = cppcheck(args)
assert exitcode == 0
Expand Down Expand Up @@ -757,7 +757,7 @@ class A {
};
""")

args = ['--enable=unusedFunction', '--inline-suppr', '--template={file}:{line}:{column}: {severity}:{inconclusive:inconclusive:} {message} [{id}]', test_cpp_file]
args = ['--enable=unusedFunction', '--inline-suppr', '--template=simple', test_cpp_file]

_, _, stderr = cppcheck(args)
assert stderr == "{}:4:0: style: The function 'f' is never used. [unusedFunction]\n".format(test_h_file)
Expand Down
2 changes: 1 addition & 1 deletion test/fixture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ void TestFixture::setTemplateFormat(const std::string &templateFormat)
mTemplateFormat = "{file}:{line}:{severity}:{message}";
mTemplateLocation = "{file}:{line}:note:{info}";
}
else if (templateFormat == "simple") {
else if (templateFormat == "simple") { // TODO: use the existing one in CmdLineParser
mTemplateFormat = "{file}:{line}:{column}: {severity}:{inconclusive:inconclusive:} {message} [{id}]";
mTemplateLocation = "";
}
Expand Down
11 changes: 11 additions & 0 deletions test/testcmdlineparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ class TestCmdlineParser : public TestFixture {
TEST_CASE(templatesCppcheck1);
TEST_CASE(templatesDaca2);
TEST_CASE(templatesSelfcheck);
TEST_CASE(templatesSimple);
TEST_CASE(templatesNoPlaceholder);
TEST_CASE(templateFormatInvalid);
TEST_CASE(templateFormatEmpty);
Expand Down Expand Up @@ -1553,6 +1554,16 @@ class TestCmdlineParser : public TestFixture {
ASSERT_EQUALS("{file}:{line}:{column}: note: {info}\n{code}", settings->templateLocation);
}

void templatesSimple() {
REDIRECT;
const char * const argv[] = {"cppcheck", "--template=simple", "file.cpp"};
settings->templateFormat.clear();
settings->templateLocation.clear();
ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(3, argv));
ASSERT_EQUALS("{file}:{line}:{column}: {severity}:{inconclusive:inconclusive:} {message} [{id}]", settings->templateFormat);
ASSERT_EQUALS("", settings->templateLocation);
}

// TODO: we should bail out on this
void templatesNoPlaceholder() {
REDIRECT;
Expand Down