Skip to content

Commit fe5f02b

Browse files
committed
drop internal default template format never used in production [skip ci]
1 parent 6c57803 commit fe5f02b

File tree

10 files changed

+69
-53
lines changed

10 files changed

+69
-53
lines changed

lib/cppcheck.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1867,6 +1867,7 @@ void CppCheck::purgedConfigurationMessage(const std::string &file, const std::st
18671867
void CppCheck::getErrorMessages(ErrorLogger &errorlogger)
18681868
{
18691869
Settings settings;
1870+
settings.templateFormat = "{callstack}: ({severity}) {inconclusive:inconclusive: }{message}"; // TODO: get rid of this
18701871
Suppressions supprs;
18711872

18721873
CppCheck cppcheck(settings, supprs, errorlogger, true, nullptr);

lib/errorlogger.cpp

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -610,30 +610,9 @@ static void replaceColors(std::string& source) {
610610
replace(source, substitutionMap);
611611
}
612612

613-
// TODO: remove default parameters
614613
std::string ErrorMessage::toString(bool verbose, const std::string &templateFormat, const std::string &templateLocation) const
615614
{
616-
// Save this ErrorMessage in plain text.
617-
618-
// TODO: should never happen - remove this
619-
// No template is given
620-
// (not 100%) equivalent templateFormat: {callstack} ({severity}{inconclusive:, inconclusive}) {message}
621-
if (templateFormat.empty()) {
622-
std::string text;
623-
if (!callStack.empty()) {
624-
text += ErrorLogger::callStackToString(callStack);
625-
text += ": ";
626-
}
627-
if (severity != Severity::none) {
628-
text += '(';
629-
text += severityToString(severity);
630-
if (certainty == Certainty::inconclusive)
631-
text += ", inconclusive";
632-
text += ") ";
633-
}
634-
text += (verbose ? mVerboseMessage : mShortMessage);
635-
return text;
636-
}
615+
assert(!templateFormat.empty());
637616

638617
// template is given. Reformat the output according to it
639618
std::string result = templateFormat;

lib/errorlogger.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,8 @@ class CPPCHECKLIB ErrorMessage {
158158
* @return formatted string
159159
*/
160160
std::string toString(bool verbose,
161-
const std::string &templateFormat = emptyString,
162-
const std::string &templateLocation = emptyString) const;
161+
const std::string &templateFormat,
162+
const std::string &templateLocation) const;
163163

164164
std::string serialize() const;
165165
void deserialize(const std::string &data);

test/fixture.cpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,26 @@ void TestFixture::reportErr(const ErrorMessage &msg)
429429
return;
430430
if (msg.severity == Severity::information && msg.id == "normalCheckLevelMaxBranches")
431431
return;
432-
const std::string errormessage(msg.toString(mVerbose, mTemplateFormat, mTemplateLocation));
432+
std::string errormessage;
433+
if (!mTemplateFormat.empty()) {
434+
errormessage = msg.toString(mVerbose, mTemplateFormat, mTemplateLocation);
435+
}
436+
else {
437+
if (!msg.callStack.empty()) {
438+
// TODO: add column
439+
errormessage += ErrorLogger::callStackToString(msg.callStack);
440+
errormessage += ": ";
441+
}
442+
if (msg.severity != Severity::none) {
443+
errormessage += '(';
444+
errormessage += severityToString(msg.severity);
445+
if (msg.certainty == Certainty::inconclusive)
446+
errormessage += ", inconclusive";
447+
errormessage += ") ";
448+
}
449+
errormessage += msg.shortMessage();
450+
// TODO: add ID
451+
}
433452
mErrout << errormessage << std::endl;
434453
}
435454

test/testcppcheck.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class TestCppcheck : public TestFixture {
3838
TestCppcheck() : TestFixture("TestCppcheck") {}
3939

4040
private:
41+
const std::string templateFormat{"{file}:{line}:{column}: {severity}:{inconclusive:inconclusive:} {message} [{id}]"};
4142

4243
class ErrorLogger2 : public ErrorLogger {
4344
public:
@@ -113,7 +114,8 @@ class TestCppcheck : public TestFixture {
113114
" return 0;\n"
114115
"}");
115116

116-
const Settings s;
117+
/*const*/ Settings s;
118+
s.templateFormat = templateFormat;
117119
Suppressions supprs;
118120
ErrorLogger2 errorLogger;
119121
CppCheck cppcheck(s, supprs, errorLogger, false, {});
@@ -135,7 +137,8 @@ class TestCppcheck : public TestFixture {
135137
" return 0;\n"
136138
"}");
137139

138-
const Settings s;
140+
/*const*/ Settings s;
141+
s.templateFormat = templateFormat;
139142
Suppressions supprs;
140143
ErrorLogger2 errorLogger;
141144
CppCheck cppcheck(s, supprs, errorLogger, false, {});
@@ -184,7 +187,9 @@ class TestCppcheck : public TestFixture {
184187
ScopedFile test_file_b("b.cpp",
185188
"#include \"inc.h\"");
186189

187-
const Settings s;
190+
/*const*/ Settings s;
191+
// this is the "simple" format
192+
s.templateFormat = templateFormat; // TODO: remove when we only longer rely on toString() in unique message handling
188193
Suppressions supprs;
189194
ErrorLogger2 errorLogger;
190195
CppCheck cppcheck(s, supprs, errorLogger, false, {});
@@ -215,9 +220,9 @@ class TestCppcheck : public TestFixture {
215220
"(void)b;\n"
216221
"}");
217222

218-
Settings s;
223+
/*const*/ Settings s;
219224
// this is the "simple" format
220-
s.templateFormat = "{file}:{line}:{column}: {severity}:{inconclusive:inconclusive:} {message} [{id}]";
225+
s.templateFormat = templateFormat; // TODO: remove when we only longer rely on toString() in unique message handling?
221226
Suppressions supprs;
222227
ErrorLogger2 errorLogger;
223228
CppCheck cppcheck(s, supprs, errorLogger, false, {});

test/testerrorlogger.cpp

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ class TestErrorLogger : public TestFixture {
3333
TestErrorLogger() : TestFixture("TestErrorLogger") {}
3434

3535
private:
36+
const std::string templateFormat{"{callstack}: ({severity}) {inconclusive:inconclusive: }{message}"};
37+
3638
const ErrorMessage::FileLocation fooCpp5{"foo.cpp", 5, 1};
3739
const ErrorMessage::FileLocation barCpp8{"bar.cpp", 8, 1};
3840
const ErrorMessage::FileLocation barCpp8_i{"bar.cpp", "ä", 8, 1};
@@ -81,13 +83,13 @@ class TestErrorLogger : public TestFixture {
8183
ErrorMessage message;
8284
message.id = id;
8385

84-
std::string serialized = message.toString(true, idPlaceholder + plainText + idPlaceholder);
86+
std::string serialized = message.toString(true, idPlaceholder + plainText + idPlaceholder, "");
8587
ASSERT_EQUALS(id + plainText + id, serialized);
8688

87-
serialized = message.toString(true, idPlaceholder + idPlaceholder);
89+
serialized = message.toString(true, idPlaceholder + idPlaceholder, "");
8890
ASSERT_EQUALS(id + id, serialized);
8991

90-
serialized = message.toString(true, plainText + idPlaceholder + plainText);
92+
serialized = message.toString(true, plainText + idPlaceholder + plainText, "");
9193
ASSERT_EQUALS(plainText + id + plainText, serialized);
9294
}
9395

@@ -133,8 +135,8 @@ class TestErrorLogger : public TestFixture {
133135
ASSERT_EQUALS(1, msg.callStack.size());
134136
ASSERT_EQUALS("Programming error.", msg.shortMessage());
135137
ASSERT_EQUALS("Programming error.", msg.verboseMessage());
136-
ASSERT_EQUALS("[foo.cpp:5]: (error) Programming error.", msg.toString(false));
137-
ASSERT_EQUALS("[foo.cpp:5]: (error) Programming error.", msg.toString(true));
138+
ASSERT_EQUALS("[foo.cpp:5]: (error) Programming error.", msg.toString(false, templateFormat, ""));
139+
ASSERT_EQUALS("[foo.cpp:5]: (error) Programming error.", msg.toString(true, templateFormat, ""));
138140
}
139141

140142
void ErrorMessageConstructLocations() const {
@@ -143,8 +145,8 @@ class TestErrorLogger : public TestFixture {
143145
ASSERT_EQUALS(2, msg.callStack.size());
144146
ASSERT_EQUALS("Programming error.", msg.shortMessage());
145147
ASSERT_EQUALS("Programming error.", msg.verboseMessage());
146-
ASSERT_EQUALS("[foo.cpp:5] -> [bar.cpp:8]: (error) Programming error.", msg.toString(false));
147-
ASSERT_EQUALS("[foo.cpp:5] -> [bar.cpp:8]: (error) Programming error.", msg.toString(true));
148+
ASSERT_EQUALS("[foo.cpp:5] -> [bar.cpp:8]: (error) Programming error.", msg.toString(false, templateFormat, ""));
149+
ASSERT_EQUALS("[foo.cpp:5] -> [bar.cpp:8]: (error) Programming error.", msg.toString(true, templateFormat, ""));
148150
}
149151

150152
void ErrorMessageVerbose() const {
@@ -153,8 +155,8 @@ class TestErrorLogger : public TestFixture {
153155
ASSERT_EQUALS(1, msg.callStack.size());
154156
ASSERT_EQUALS("Programming error.", msg.shortMessage());
155157
ASSERT_EQUALS("Verbose error", msg.verboseMessage());
156-
ASSERT_EQUALS("[foo.cpp:5]: (error) Programming error.", msg.toString(false));
157-
ASSERT_EQUALS("[foo.cpp:5]: (error) Verbose error", msg.toString(true));
158+
ASSERT_EQUALS("[foo.cpp:5]: (error) Programming error.", msg.toString(false, templateFormat, ""));
159+
ASSERT_EQUALS("[foo.cpp:5]: (error) Verbose error", msg.toString(true, templateFormat, ""));
158160
}
159161

160162
void ErrorMessageVerboseLocations() const {
@@ -163,8 +165,8 @@ class TestErrorLogger : public TestFixture {
163165
ASSERT_EQUALS(2, msg.callStack.size());
164166
ASSERT_EQUALS("Programming error.", msg.shortMessage());
165167
ASSERT_EQUALS("Verbose error", msg.verboseMessage());
166-
ASSERT_EQUALS("[foo.cpp:5] -> [bar.cpp:8]: (error) Programming error.", msg.toString(false));
167-
ASSERT_EQUALS("[foo.cpp:5] -> [bar.cpp:8]: (error) Verbose error", msg.toString(true));
168+
ASSERT_EQUALS("[foo.cpp:5] -> [bar.cpp:8]: (error) Programming error.", msg.toString(false, templateFormat, ""));
169+
ASSERT_EQUALS("[foo.cpp:5] -> [bar.cpp:8]: (error) Verbose error", msg.toString(true, templateFormat, ""));
168170
}
169171

170172
void ErrorMessageFromInternalError() const {
@@ -179,8 +181,8 @@ class TestErrorLogger : public TestFixture {
179181
ASSERT_EQUALS(0, loc.column);
180182
ASSERT_EQUALS("message", msg.shortMessage());
181183
ASSERT_EQUALS("message", msg.verboseMessage());
182-
ASSERT_EQUALS("[file.c:0]: (error) message", msg.toString(false));
183-
ASSERT_EQUALS("[file.c:0]: (error) message", msg.toString(true));
184+
ASSERT_EQUALS("[file.c:0]: (error) message", msg.toString(false, templateFormat, ""));
185+
ASSERT_EQUALS("[file.c:0]: (error) message", msg.toString(true, templateFormat, ""));
184186
}
185187
{
186188
InternalError internalError(nullptr, "message", "details", InternalError::INTERNAL);
@@ -192,8 +194,8 @@ class TestErrorLogger : public TestFixture {
192194
ASSERT_EQUALS(0, loc.column);
193195
ASSERT_EQUALS("msg: message", msg.shortMessage());
194196
ASSERT_EQUALS("msg: message: details", msg.verboseMessage());
195-
ASSERT_EQUALS("[file.cpp:0]: (error) msg: message", msg.toString(false));
196-
ASSERT_EQUALS("[file.cpp:0]: (error) msg: message: details", msg.toString(true));
197+
ASSERT_EQUALS("[file.cpp:0]: (error) msg: message", msg.toString(false, templateFormat, ""));
198+
ASSERT_EQUALS("[file.cpp:0]: (error) msg: message: details", msg.toString(true, templateFormat, ""));
197199
}
198200
}
199201

@@ -207,7 +209,7 @@ class TestErrorLogger : public TestFixture {
207209
msg.classification = getClassification(msg.guideline, reportType);
208210
ASSERT_EQUALS("Advisory", msg.classification);
209211
ASSERT_EQUALS("2.8", msg.guideline);
210-
ASSERT_EQUALS("Advisory 2.8", msg.toString(true, format));
212+
ASSERT_EQUALS("Advisory 2.8", msg.toString(true, format, ""));
211213
}
212214

213215
void ErrorMessageReportTypeCertC() const {
@@ -220,7 +222,7 @@ class TestErrorLogger : public TestFixture {
220222
msg.classification = getClassification(msg.guideline, reportType);
221223
ASSERT_EQUALS("L3", msg.classification);
222224
ASSERT_EQUALS("FIO42-C", msg.guideline);
223-
ASSERT_EQUALS("L3 FIO42-C", msg.toString(true, format));
225+
ASSERT_EQUALS("L3 FIO42-C", msg.toString(true, format, ""));
224226
}
225227

226228
void CustomFormat() const {
@@ -229,8 +231,8 @@ class TestErrorLogger : public TestFixture {
229231
ASSERT_EQUALS(1, msg.callStack.size());
230232
ASSERT_EQUALS("Programming error.", msg.shortMessage());
231233
ASSERT_EQUALS("Verbose error", msg.verboseMessage());
232-
ASSERT_EQUALS("foo.cpp:5,error,errorId,Programming error.", msg.toString(false, "{file}:{line},{severity},{id},{message}"));
233-
ASSERT_EQUALS("foo.cpp:5,error,errorId,Verbose error", msg.toString(true, "{file}:{line},{severity},{id},{message}"));
234+
ASSERT_EQUALS("foo.cpp:5,error,errorId,Programming error.", msg.toString(false, "{file}:{line},{severity},{id},{message}", ""));
235+
ASSERT_EQUALS("foo.cpp:5,error,errorId,Verbose error", msg.toString(true, "{file}:{line},{severity},{id},{message}", ""));
234236
}
235237

236238
void CustomFormat2() const {
@@ -239,8 +241,8 @@ class TestErrorLogger : public TestFixture {
239241
ASSERT_EQUALS(1, msg.callStack.size());
240242
ASSERT_EQUALS("Programming error.", msg.shortMessage());
241243
ASSERT_EQUALS("Verbose error", msg.verboseMessage());
242-
ASSERT_EQUALS("Programming error. - foo.cpp(5):(error,errorId)", msg.toString(false, "{message} - {file}({line}):({severity},{id})"));
243-
ASSERT_EQUALS("Verbose error - foo.cpp(5):(error,errorId)", msg.toString(true, "{message} - {file}({line}):({severity},{id})"));
244+
ASSERT_EQUALS("Programming error. - foo.cpp(5):(error,errorId)", msg.toString(false, "{message} - {file}({line}):({severity},{id})", ""));
245+
ASSERT_EQUALS("Verbose error - foo.cpp(5):(error,errorId)", msg.toString(true, "{message} - {file}({line}):({severity},{id})", ""));
244246
}
245247

246248
void CustomFormatLocations() const {
@@ -250,8 +252,8 @@ class TestErrorLogger : public TestFixture {
250252
ASSERT_EQUALS(2, msg.callStack.size());
251253
ASSERT_EQUALS("Programming error.", msg.shortMessage());
252254
ASSERT_EQUALS("Verbose error", msg.verboseMessage());
253-
ASSERT_EQUALS("Programming error. - bar.cpp(8):(error,errorId)", msg.toString(false, "{message} - {file}({line}):({severity},{id})"));
254-
ASSERT_EQUALS("Verbose error - bar.cpp(8):(error,errorId)", msg.toString(true, "{message} - {file}({line}):({severity},{id})"));
255+
ASSERT_EQUALS("Programming error. - bar.cpp(8):(error,errorId)", msg.toString(false, "{message} - {file}({line}):({severity},{id})", ""));
256+
ASSERT_EQUALS("Verbose error - bar.cpp(8):(error,errorId)", msg.toString(true, "{message} - {file}({line}):({severity},{id})", ""));
255257
}
256258

257259
void ToXmlV2() const {

test/testprocessexecutor.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ class TestProcessExecutorBase : public TestFixture {
9595
s.quiet = opt.quiet;
9696
if (opt.plistOutput)
9797
s.plistOutput = opt.plistOutput;
98+
s.templateFormat = "{callstack}: ({severity}) {inconclusive:inconclusive: }{message}";
9899
Suppressions supprs;
99100

100101
bool executeCommandCalled = false;

test/testsingleexecutor.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ class TestSingleExecutorBase : public TestFixture {
100100
if (opt.plistOutput)
101101
s.plistOutput = opt.plistOutput;
102102
s.clangTidy = opt.clangTidy;
103+
s.templateFormat = "{callstack}: ({severity}) {inconclusive:inconclusive: }{message}"; // TODO: remove when we only longer rely on toString() in unique message handling?
103104

104105
Suppressions supprs;
105106

test/testsuppressions.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ class TestSuppressions : public TestFixture {
4343
TestSuppressions() : TestFixture("TestSuppressions") {}
4444

4545
private:
46+
47+
const std::string templateFormat{"{callstack}: ({severity}) {inconclusive:inconclusive: }{message}"};
4648

4749
void run() override {
4850
TEST_CASE(suppressionsBadId1);
@@ -253,6 +255,7 @@ class TestSuppressions : public TestFixture {
253255
settings.severity.enable(Severity::information);
254256
if (suppression == "unusedFunction")
255257
settings.checks.setEnabled(Checks::unusedFunction, true);
258+
settings.templateFormat = templateFormat;
256259

257260
std::vector<std::unique_ptr<ScopedFile>> scopedfiles;
258261
scopedfiles.reserve(filelist.size());
@@ -294,6 +297,7 @@ class TestSuppressions : public TestFixture {
294297
$.quiet = true,
295298
$.inlineSuppressions = true);
296299
settings.severity.enable(Severity::information);
300+
settings.templateFormat = templateFormat;
297301

298302
Suppressions supprs;
299303
if (!suppression.empty()) {
@@ -340,6 +344,7 @@ class TestSuppressions : public TestFixture {
340344
$.quiet = true,
341345
$.inlineSuppressions = true);
342346
settings.severity.enable(Severity::information);
347+
settings.templateFormat = templateFormat;
343348

344349
Suppressions supprs;
345350
if (!suppression.empty()) {
@@ -1198,6 +1203,7 @@ class TestSuppressions : public TestFixture {
11981203
Settings settings;
11991204
settings.quiet = true;
12001205
settings.exitCode = 1;
1206+
settings.templateFormat = templateFormat;
12011207

12021208
Suppressions supprs;
12031209
ASSERT_EQUALS("", supprs.nomsg.addSuppressionLine("uninitvar"));
@@ -1238,6 +1244,7 @@ class TestSuppressions : public TestFixture {
12381244
settings.inlineSuppressions = true;
12391245
settings.relativePaths = true;
12401246
settings.basePaths.emplace_back("/somewhere");
1247+
settings.templateFormat = templateFormat;
12411248
const char code[] =
12421249
"struct Point\n"
12431250
"{\n"

test/testthreadexecutor.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ class TestThreadExecutorBase : public TestFixture {
9696
if (opt.plistOutput)
9797
s.plistOutput = opt.plistOutput;
9898
s.clangTidy = opt.clangTidy;
99+
s.templateFormat = "{callstack}: ({severity}) {inconclusive:inconclusive: }{message}"; // TODO: remove when we only longer rely on toString() in unique message handling?
99100

100101
Suppressions supprs;
101102

0 commit comments

Comments
 (0)