Skip to content

Commit 87540e6

Browse files
authored
testrunner: do not suppress duplicated error messages (danmar#5736)
1 parent b2e0b3b commit 87540e6

12 files changed

Lines changed: 339 additions & 99 deletions

test/fixture.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -403,9 +403,7 @@ void TestFixture::reportErr(const ErrorMessage &msg)
403403
if (msg.severity == Severity::internal)
404404
return;
405405
const std::string errormessage(msg.toString(mVerbose, mTemplateFormat, mTemplateLocation));
406-
// TODO: remove the unique error handling?
407-
if (errout.str().find(errormessage) == std::string::npos)
408-
errout << errormessage << std::endl;
406+
errout << errormessage << std::endl;
409407
}
410408

411409
void TestFixture::setTemplateFormat(const std::string &templateFormat)

test/testautovariables.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,10 @@ class TestAutoVariables : public TestFixture {
663663
" struct S s;\n"
664664
" g(&s);\n"
665665
"}");
666-
ASSERT_EQUALS("[test.cpp:4]: (error) Address of local auto-variable assigned to a function parameter.\n", errout.str());
666+
ASSERT_EQUALS(
667+
"[test.cpp:4]: (error) Address of local auto-variable assigned to a function parameter.\n"
668+
"[test.cpp:4]: (error) Address of local auto-variable assigned to a function parameter.\n", // duplicate
669+
errout.str());
667670
}
668671

669672
void testinvaliddealloc() {
@@ -2508,7 +2511,8 @@ class TestAutoVariables : public TestFixture {
25082511
" }\n"
25092512
"};");
25102513
ASSERT_EQUALS(
2511-
"[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",
2514+
"[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"
2515+
"[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
25122516
errout.str());
25132517

25142518
check("std::vector<int>::iterator f(std::vector<int> v) {\n"
@@ -3795,7 +3799,8 @@ class TestAutoVariables : public TestFixture {
37953799
" return v;\n"
37963800
"}");
37973801
ASSERT_EQUALS(
3798-
"[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",
3802+
"[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"
3803+
"[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
37993804
errout.str());
38003805

38013806
check("std::vector<int*> f() {\n"
@@ -3804,15 +3809,17 @@ class TestAutoVariables : public TestFixture {
38043809
" return v;\n"
38053810
"}");
38063811
ASSERT_EQUALS(
3807-
"[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",
3812+
"[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"
3813+
"[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
38083814
errout.str());
38093815

38103816
check("std::vector<int*> f() {\n"
38113817
" int i = 0;\n"
38123818
" return {&i, &i};\n"
38133819
"}");
38143820
ASSERT_EQUALS(
3815-
"[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",
3821+
"[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"
3822+
"[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
38163823
errout.str());
38173824

38183825
check("std::vector<int*> f(int& x) {\n"

test/testbool.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,10 @@ class TestBool : public TestFixture {
269269
" if ((5 && x)==3 || (8 && x)==9)\n"
270270
" a++;\n"
271271
"}");
272-
ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean expression with an integer other than 0 or 1.\n", errout.str());
272+
ASSERT_EQUALS(
273+
"[test.cpp:2]: (warning) Comparison of a boolean expression with an integer other than 0 or 1.\n"
274+
"[test.cpp:2]: (warning) Comparison of a boolean expression with an integer other than 0 or 1.\n", // duplicate
275+
errout.str());
273276

274277
check("void f(int x) {\n"
275278
" if ((5 && x)!=3)\n"

test/testfunctions.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,10 @@ class TestFunctions : public TestFixture {
215215
check("void TDataModel::forceRowRefresh(int row) {\n"
216216
" emit dataChanged(index(row, 0), index(row, columnCount() - 1));\n"
217217
"}");
218-
ASSERT_EQUALS("[test.cpp:2]: (style) Obsolescent function 'index' called. It is recommended to use 'strchr' instead.\n", errout.str());
218+
ASSERT_EQUALS(
219+
"[test.cpp:2]: (style) Obsolescent function 'index' called. It is recommended to use 'strchr' instead.\n"
220+
"[test.cpp:2]: (style) Obsolescent function 'index' called. It is recommended to use 'strchr' instead.\n", // duplicate
221+
errout.str());
219222
}
220223

221224
void prohibitedFunctions_rindex() {

test/testnullpointer.cpp

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3431,7 +3431,10 @@ class TestNullPointer : public TestFixture {
34313431
" char* s = 0;\n"
34323432
" printf(\"%s\", s);\n"
34333433
"}");
3434-
ASSERT_EQUALS("[test.cpp:3]: (error) Null pointer dereference: s\n", errout.str());
3434+
ASSERT_EQUALS(
3435+
"[test.cpp:3]: (error) Null pointer dereference: s\n"
3436+
"[test.cpp:3]: (error) Null pointer dereference\n",
3437+
errout.str());
34353438

34363439
check("void f() {\n"
34373440
" char *s = 0;\n"
@@ -3453,7 +3456,10 @@ class TestNullPointer : public TestFixture {
34533456
" char* s = 0;\n"
34543457
" printf(\"%u%s\", 123, s);\n"
34553458
"}");
3456-
ASSERT_EQUALS("[test.cpp:3]: (error) Null pointer dereference: s\n", errout.str());
3459+
ASSERT_EQUALS(
3460+
"[test.cpp:3]: (error) Null pointer dereference: s\n"
3461+
"[test.cpp:3]: (error) Null pointer dereference\n",
3462+
errout.str());
34573463

34583464

34593465
check("void f() {\n"
@@ -3496,12 +3502,18 @@ class TestNullPointer : public TestFixture {
34963502
check("void f(char* s) {\n"
34973503
" sscanf(s, \"%s\", 0);\n"
34983504
"}");
3499-
ASSERT_EQUALS("[test.cpp:2]: (error) Null pointer dereference\n", errout.str());
3505+
ASSERT_EQUALS(
3506+
"[test.cpp:2]: (error) Null pointer dereference\n"
3507+
"[test.cpp:2]: (error) Null pointer dereference\n", // duplicate
3508+
errout.str());
35003509

35013510
check("void f() {\n"
35023511
" scanf(\"%d\", 0);\n"
35033512
"}");
3504-
ASSERT_EQUALS("[test.cpp:2]: (error) Null pointer dereference\n", errout.str());
3513+
ASSERT_EQUALS(
3514+
"[test.cpp:2]: (error) Null pointer dereference\n"
3515+
"[test.cpp:2]: (error) Null pointer dereference\n", // duplicate
3516+
errout.str());
35053517

35063518
check("void f(char* foo) {\n"
35073519
" char location[200];\n"
@@ -3520,7 +3532,11 @@ class TestNullPointer : public TestFixture {
35203532
" int* iVal = 0;\n"
35213533
" sscanf(dummy, \"%d\", iVal);\n"
35223534
"}");
3523-
ASSERT_EQUALS("[test.cpp:3]: (error) Null pointer dereference: iVal\n", errout.str());
3535+
ASSERT_EQUALS(
3536+
"[test.cpp:3]: (error) Null pointer dereference: iVal\n"
3537+
"[test.cpp:3]: (error) Null pointer dereference\n"
3538+
"[test.cpp:3]: (error) Null pointer dereference\n", // duplicate
3539+
errout.str());
35243540

35253541
check("void f(char *dummy) {\n"
35263542
" int* iVal;\n"
@@ -3537,7 +3553,10 @@ class TestNullPointer : public TestFixture {
35373553
check("void f(char* dummy) {\n"
35383554
" sscanf(dummy, \"%*d%u\", 0);\n"
35393555
"}");
3540-
ASSERT_EQUALS("[test.cpp:2]: (error) Null pointer dereference\n", errout.str());
3556+
ASSERT_EQUALS(
3557+
"[test.cpp:2]: (error) Null pointer dereference\n"
3558+
"[test.cpp:2]: (error) Null pointer dereference\n", // duplicate
3559+
errout.str());
35413560
}
35423561

35433562
void nullpointer_in_return() {
@@ -4258,7 +4277,10 @@ class TestNullPointer : public TestFixture {
42584277
check("void f(char *p = 0) {\n"
42594278
" std::cout << p ? *p : 0;\n" // Due to operator precedence, this is equivalent to: (std::cout << p) ? *p : 0;
42604279
"}");
4261-
ASSERT_EQUALS("[test.cpp:2]: (warning) Possible null pointer dereference if the default parameter value is used: p\n", errout.str());
4280+
ASSERT_EQUALS(
4281+
"[test.cpp:2]: (warning) Possible null pointer dereference if the default parameter value is used: p\n"
4282+
"[test.cpp:2]: (warning) Possible null pointer dereference if the default parameter value is used: p\n", // duplicate
4283+
errout.str());
42624284

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

0 commit comments

Comments
 (0)