Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

testrunner: do not suppress duplicated error messages #5736

Merged
merged 1 commit into from
Jan 4, 2024
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
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::internal)
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 @@ -3795,7 +3799,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 @@ -3804,15 +3809,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 @@ -3431,7 +3431,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 @@ -3453,7 +3456,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 @@ -3496,12 +3502,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 @@ -3520,7 +3532,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 @@ -3537,7 +3553,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 @@ -4258,7 +4277,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
Loading