Skip to content

Commit

Permalink
testrunner: do not suppress duplicated error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
firewave committed Dec 8, 2023
1 parent 1bdb713 commit 9db2aff
Show file tree
Hide file tree
Showing 11 changed files with 333 additions and 98 deletions.
4 changes: 1 addition & 3 deletions test/fixture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -403,9 +403,7 @@ void TestFixture::reportErr(const ErrorMessage &msg)
if (msg.severity == Severity::none && msg.id == "logChecker")
return;
const std::string errormessage(msg.toString(mVerbose, mTemplateFormat, mTemplateLocation));
// TODO: remove the unique error handling?
if (errout.str().find(errormessage) == std::string::npos)
errout << errormessage << std::endl;
errout << errormessage << std::endl;
}

void TestFixture::setTemplateFormat(const std::string &templateFormat)
Expand Down
17 changes: 12 additions & 5 deletions test/testautovariables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,10 @@ class TestAutoVariables : public TestFixture {
" struct S s;\n"
" g(&s);\n"
"}");
ASSERT_EQUALS("[test.cpp:4]: (error) Address of local auto-variable assigned to a function parameter.\n", errout.str());
ASSERT_EQUALS(
"[test.cpp:4]: (error) Address of local auto-variable assigned to a function parameter.\n"
"[test.cpp:4]: (error) Address of local auto-variable assigned to a function parameter.\n", // duplicate
errout.str());
}

void testinvaliddealloc() {
Expand Down Expand Up @@ -2508,7 +2511,8 @@ class TestAutoVariables : public TestFixture {
" }\n"
"};");
ASSERT_EQUALS(
"[test.cpp:6] -> [test.cpp:6] -> [test.cpp:6] -> [test.cpp:4] -> [test.cpp:7]: (error) Non-local variable 'm' will use object that points to local variable 'x'.\n",
"[test.cpp:6] -> [test.cpp:6] -> [test.cpp:6] -> [test.cpp:4] -> [test.cpp:7]: (error) Non-local variable 'm' will use object that points to local variable 'x'.\n"
"[test.cpp:6] -> [test.cpp:6] -> [test.cpp:6] -> [test.cpp:4] -> [test.cpp:7]: (error) Non-local variable 'm' will use object that points to local variable 'x'.\n", // duplicate
errout.str());

check("std::vector<int>::iterator f(std::vector<int> v) {\n"
Expand Down Expand Up @@ -3788,7 +3792,8 @@ class TestAutoVariables : public TestFixture {
" return v;\n"
"}");
ASSERT_EQUALS(
"[test.cpp:3] -> [test.cpp:3] -> [test.cpp:2] -> [test.cpp:4]: (error) Returning object that points to local variable 'i' that will be invalid when returning.\n",
"[test.cpp:3] -> [test.cpp:3] -> [test.cpp:2] -> [test.cpp:4]: (error) Returning object that points to local variable 'i' that will be invalid when returning.\n"
"[test.cpp:3] -> [test.cpp:3] -> [test.cpp:2] -> [test.cpp:4]: (error) Returning object that points to local variable 'i' that will be invalid when returning.\n", // duplicate
errout.str());

check("std::vector<int*> f() {\n"
Expand All @@ -3797,15 +3802,17 @@ class TestAutoVariables : public TestFixture {
" return v;\n"
"}");
ASSERT_EQUALS(
"[test.cpp:3] -> [test.cpp:3] -> [test.cpp:2] -> [test.cpp:4]: (error) Returning object that points to local variable 'i' that will be invalid when returning.\n",
"[test.cpp:3] -> [test.cpp:3] -> [test.cpp:2] -> [test.cpp:4]: (error) Returning object that points to local variable 'i' that will be invalid when returning.\n"
"[test.cpp:3] -> [test.cpp:3] -> [test.cpp:2] -> [test.cpp:4]: (error) Returning object that points to local variable 'i' that will be invalid when returning.\n", // duplicate
errout.str());

check("std::vector<int*> f() {\n"
" int i = 0;\n"
" return {&i, &i};\n"
"}");
ASSERT_EQUALS(
"[test.cpp:3] -> [test.cpp:3] -> [test.cpp:2] -> [test.cpp:3]: (error) Returning object that points to local variable 'i' that will be invalid when returning.\n",
"[test.cpp:3] -> [test.cpp:3] -> [test.cpp:2] -> [test.cpp:3]: (error) Returning object that points to local variable 'i' that will be invalid when returning.\n"
"[test.cpp:3] -> [test.cpp:3] -> [test.cpp:2] -> [test.cpp:3]: (error) Returning object that points to local variable 'i' that will be invalid when returning.\n", // duplicate
errout.str());

check("std::vector<int*> f(int& x) {\n"
Expand Down
5 changes: 4 additions & 1 deletion test/testbool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,10 @@ class TestBool : public TestFixture {
" if ((5 && x)==3 || (8 && x)==9)\n"
" a++;\n"
"}");
ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean expression with an integer other than 0 or 1.\n", errout.str());
ASSERT_EQUALS(
"[test.cpp:2]: (warning) Comparison of a boolean expression with an integer other than 0 or 1.\n"
"[test.cpp:2]: (warning) Comparison of a boolean expression with an integer other than 0 or 1.\n", // duplicate
errout.str());

check("void f(int x) {\n"
" if ((5 && x)!=3)\n"
Expand Down
5 changes: 4 additions & 1 deletion test/testfunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,10 @@ class TestFunctions : public TestFixture {
check("void TDataModel::forceRowRefresh(int row) {\n"
" emit dataChanged(index(row, 0), index(row, columnCount() - 1));\n"
"}");
ASSERT_EQUALS("[test.cpp:2]: (style) Obsolescent function 'index' called. It is recommended to use 'strchr' instead.\n", errout.str());
ASSERT_EQUALS(
"[test.cpp:2]: (style) Obsolescent function 'index' called. It is recommended to use 'strchr' instead.\n"
"[test.cpp:2]: (style) Obsolescent function 'index' called. It is recommended to use 'strchr' instead.\n", // duplicate
errout.str());
}

void prohibitedFunctions_rindex() {
Expand Down
36 changes: 29 additions & 7 deletions test/testnullpointer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3371,7 +3371,10 @@ class TestNullPointer : public TestFixture {
" char* s = 0;\n"
" printf(\"%s\", s);\n"
"}");
ASSERT_EQUALS("[test.cpp:3]: (error) Null pointer dereference: s\n", errout.str());
ASSERT_EQUALS(
"[test.cpp:3]: (error) Null pointer dereference: s\n"
"[test.cpp:3]: (error) Null pointer dereference\n",
errout.str());

check("void f() {\n"
" char *s = 0;\n"
Expand All @@ -3393,7 +3396,10 @@ class TestNullPointer : public TestFixture {
" char* s = 0;\n"
" printf(\"%u%s\", 123, s);\n"
"}");
ASSERT_EQUALS("[test.cpp:3]: (error) Null pointer dereference: s\n", errout.str());
ASSERT_EQUALS(
"[test.cpp:3]: (error) Null pointer dereference: s\n"
"[test.cpp:3]: (error) Null pointer dereference\n",
errout.str());


check("void f() {\n"
Expand Down Expand Up @@ -3436,12 +3442,18 @@ class TestNullPointer : public TestFixture {
check("void f(char* s) {\n"
" sscanf(s, \"%s\", 0);\n"
"}");
ASSERT_EQUALS("[test.cpp:2]: (error) Null pointer dereference\n", errout.str());
ASSERT_EQUALS(
"[test.cpp:2]: (error) Null pointer dereference\n"
"[test.cpp:2]: (error) Null pointer dereference\n", // duplicate
errout.str());

check("void f() {\n"
" scanf(\"%d\", 0);\n"
"}");
ASSERT_EQUALS("[test.cpp:2]: (error) Null pointer dereference\n", errout.str());
ASSERT_EQUALS(
"[test.cpp:2]: (error) Null pointer dereference\n"
"[test.cpp:2]: (error) Null pointer dereference\n", // duplicate
errout.str());

check("void f(char* foo) {\n"
" char location[200];\n"
Expand All @@ -3460,7 +3472,11 @@ class TestNullPointer : public TestFixture {
" int* iVal = 0;\n"
" sscanf(dummy, \"%d\", iVal);\n"
"}");
ASSERT_EQUALS("[test.cpp:3]: (error) Null pointer dereference: iVal\n", errout.str());
ASSERT_EQUALS(
"[test.cpp:3]: (error) Null pointer dereference: iVal\n"
"[test.cpp:3]: (error) Null pointer dereference\n"
"[test.cpp:3]: (error) Null pointer dereference\n", // duplicate
errout.str());

check("void f(char *dummy) {\n"
" int* iVal;\n"
Expand All @@ -3477,7 +3493,10 @@ class TestNullPointer : public TestFixture {
check("void f(char* dummy) {\n"
" sscanf(dummy, \"%*d%u\", 0);\n"
"}");
ASSERT_EQUALS("[test.cpp:2]: (error) Null pointer dereference\n", errout.str());
ASSERT_EQUALS(
"[test.cpp:2]: (error) Null pointer dereference\n"
"[test.cpp:2]: (error) Null pointer dereference\n", // duplicate
errout.str());
}

void nullpointer_in_return() {
Expand Down Expand Up @@ -4198,7 +4217,10 @@ class TestNullPointer : public TestFixture {
check("void f(char *p = 0) {\n"
" std::cout << p ? *p : 0;\n" // Due to operator precedence, this is equivalent to: (std::cout << p) ? *p : 0;
"}");
ASSERT_EQUALS("[test.cpp:2]: (warning) Possible null pointer dereference if the default parameter value is used: p\n", errout.str());
ASSERT_EQUALS(
"[test.cpp:2]: (warning) Possible null pointer dereference if the default parameter value is used: p\n"
"[test.cpp:2]: (warning) Possible null pointer dereference if the default parameter value is used: p\n", // duplicate
errout.str());

check("void f(int *p = 0) {\n"
" std::cout << (p ? *p : 0);\n"
Expand Down
Loading

0 comments on commit 9db2aff

Please sign in to comment.