From 9db2affcb4d34650e628fac4b7061a6e46a3922f Mon Sep 17 00:00:00 2001 From: firewave Date: Thu, 7 Dec 2023 15:31:21 +0100 Subject: [PATCH] testrunner: do not suppress duplicated error messages --- test/fixture.cpp | 4 +- test/testautovariables.cpp | 17 ++- test/testbool.cpp | 5 +- test/testfunctions.cpp | 5 +- test/testnullpointer.cpp | 36 +++++-- test/testother.cpp | 120 ++++++++++++++++----- test/testsimplifytypedef.cpp | 3 +- test/teststl.cpp | 25 ++++- test/testsymboldatabase.cpp | 9 +- test/testunusedvar.cpp | 198 +++++++++++++++++++++++++++-------- test/testvalueflow.cpp | 9 +- 11 files changed, 333 insertions(+), 98 deletions(-) diff --git a/test/fixture.cpp b/test/fixture.cpp index 67d022bc3e44..a6d73afbb48a 100644 --- a/test/fixture.cpp +++ b/test/fixture.cpp @@ -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) diff --git a/test/testautovariables.cpp b/test/testautovariables.cpp index ede111f1cdd8..b5e014faefe3 100644 --- a/test/testautovariables.cpp +++ b/test/testautovariables.cpp @@ -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() { @@ -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::iterator f(std::vector v) {\n" @@ -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 f() {\n" @@ -3797,7 +3802,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 f() {\n" @@ -3805,7 +3811,8 @@ class TestAutoVariables : public TestFixture { " 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 f(int& x) {\n" diff --git a/test/testbool.cpp b/test/testbool.cpp index 17115bd9e50b..bd7e4cb4734c 100644 --- a/test/testbool.cpp +++ b/test/testbool.cpp @@ -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" diff --git a/test/testfunctions.cpp b/test/testfunctions.cpp index e223e74b05f5..c1e9300b4a0d 100644 --- a/test/testfunctions.cpp +++ b/test/testfunctions.cpp @@ -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() { diff --git a/test/testnullpointer.cpp b/test/testnullpointer.cpp index aa498142a9d4..d8de7375b26c 100644 --- a/test/testnullpointer.cpp +++ b/test/testnullpointer.cpp @@ -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" @@ -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" @@ -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" @@ -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" @@ -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() { @@ -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" diff --git a/test/testother.cpp b/test/testother.cpp index d221570159cb..b5a2520c6536 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -3079,8 +3079,11 @@ class TestOther : public TestFixture { "void an();\n" "void h();"); ASSERT_EQUALS("[test.cpp:131]: (style) Variable 'tm' can be declared as pointer to const\n" + "[test.cpp:131]: (style) Variable 'tm' can be declared as pointer to const\n" // duplicate "[test.cpp:136]: (style) Variable 'af' can be declared as pointer to const\n" - "[test.cpp:137]: (style) Variable 'ag' can be declared as pointer to const\n", + "[test.cpp:137]: (style) Variable 'ag' can be declared as pointer to const\n" + "[test.cpp:136]: (style) Variable 'af' can be declared as pointer to const\n" // duplicate + "[test.cpp:137]: (style) Variable 'ag' can be declared as pointer to const\n", // duplicate errout.str()); check("class C\n" @@ -3295,14 +3298,21 @@ class TestOther : public TestFixture { " if (d)\n" " d->f();\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (style) Variable 'd' can be declared as pointer to const\n", errout.str()); + ASSERT_EQUALS( + "[test.cpp:4]: (style) Variable 'd' can be declared as pointer to const\n" + "[test.cpp:4]: (style) Variable 'd' can be declared as pointer to const\n" // duplicate + "[test.cpp:4]: (style) Variable 'd' can be declared as pointer to const\n", // duplicate + errout.str()); check("void g(const int*);\n" "void f(const std::vector&v) {\n" " for (int* i : v)\n" " g(i);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3]: (style) Variable 'i' can be declared as pointer to const\n", errout.str()); + ASSERT_EQUALS( + "[test.cpp:3]: (style) Variable 'i' can be declared as pointer to const\n" + "[test.cpp:3]: (style) Variable 'i' can be declared as pointer to const\n", // duplicate + errout.str()); check("struct A {\n" // #11225 " A();\n" @@ -3610,7 +3620,10 @@ class TestOther : public TestFixture { " for (const auto& h : v)\n" " if (h) {}\n" "}\n"); - ASSERT_EQUALS("[test.cpp:5]: (style) Variable 'h' can be declared as pointer to const\n", errout.str()); + ASSERT_EQUALS( + "[test.cpp:5]: (style) Variable 'h' can be declared as pointer to const\n" + "[test.cpp:5]: (style) Variable 'h' can be declared as pointer to const\n", // duplicate + errout.str()); check("void f(const std::vector& v) {\n" " for (const auto& p : v)\n" @@ -3618,7 +3631,10 @@ class TestOther : public TestFixture { " for (const auto* p : v)\n" " if (p == nullptr) {}\n" "}\n"); - ASSERT_EQUALS("[test.cpp:2]: (style) Variable 'p' can be declared as pointer to const\n", errout.str()); + ASSERT_EQUALS( + "[test.cpp:2]: (style) Variable 'p' can be declared as pointer to const\n" + "[test.cpp:2]: (style) Variable 'p' can be declared as pointer to const\n", // duplicate + errout.str()); check("void f(std::vector& v) {\n" " for (const auto& p : v)\n" @@ -3631,7 +3647,8 @@ class TestOther : public TestFixture { " if (p == nullptr) {}\n" "}\n"); ASSERT_EQUALS("[test.cpp:1]: (style) Parameter 'v' can be declared as reference to const\n" - "[test.cpp:2]: (style) Variable 'p' can be declared as pointer to const\n", + "[test.cpp:2]: (style) Variable 'p' can be declared as pointer to const\n" + "[test.cpp:2]: (style) Variable 'p' can be declared as pointer to const\n", // duplicate errout.str()); check("void f(std::vector& v) {\n" @@ -3722,7 +3739,9 @@ class TestOther : public TestFixture { " v.clear();\n" "}\n"); ASSERT_EQUALS("[test.cpp:2]: (style) Variable 'p' can be declared as pointer to const\n" - "[test.cpp:5]: (style) Variable 'p' can be declared as pointer to const\n", + "[test.cpp:2]: (style) Variable 'p' can be declared as pointer to const\n" // duplicate + "[test.cpp:5]: (style) Variable 'p' can be declared as pointer to const\n" + "[test.cpp:5]: (style) Variable 'p' can be declared as pointer to const\n", // duplicate errout.str()); check("void f() {\n" @@ -3785,7 +3804,8 @@ class TestOther : public TestFixture { " g(1, p);\n" " h(p);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3]: (style) Parameter 'p' can be declared as pointer to const\n", + ASSERT_EQUALS("[test.cpp:3]: (style) Parameter 'p' can be declared as pointer to const\n" + "[test.cpp:3]: (style) Parameter 'p' can be declared as pointer to const\n", // duplicate errout.str()); check("void f(int, const int*);\n" @@ -3932,7 +3952,8 @@ class TestOther : public TestFixture { " void* p = &i;\n" " std::cout << p << '\\n';\n" "}\n"); - ASSERT_EQUALS("[test.cpp:2]: (style) Variable 'p' can be declared as pointer to const\n", + ASSERT_EQUALS("[test.cpp:2]: (style) Variable 'p' can be declared as pointer to const\n" + "[test.cpp:2]: (style) Variable 'p' can be declared as pointer to const\n", // duplicate errout.str()); check("struct S { const T* t; };\n" // #12206 @@ -6598,7 +6619,10 @@ class TestOther : public TestFixture { check("Vector func(int vec1) {\n" " return fabs(vec1 & vec1 & vec1);\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Same expression on both sides of '&'.\n", errout.str()); + ASSERT_EQUALS( + "[test.cpp:2]: (style) Same expression on both sides of '&'.\n" + "[test.cpp:2]: (style) Same expression on both sides of '&'.\n", // duplicate + errout.str()); } @@ -7609,7 +7633,8 @@ class TestOther : public TestFixture { " int end = x->first;\n" "}"); ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:3]: (style, inconclusive) Same expression used in consecutive assignments of 'start' and 'end'.\n" - "[test.cpp:2]: (style) Parameter 'x' can be declared as pointer to const\n", + "[test.cpp:2]: (style) Parameter 'x' can be declared as pointer to const\n" + "[test.cpp:2]: (style) Parameter 'x' can be declared as pointer to const\n", // duplicate errout.str()); check("struct SW { int first; };\n" @@ -7618,7 +7643,8 @@ class TestOther : public TestFixture { " int end = x->first;\n" "}"); ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:3]: (style, inconclusive) Same expression used in consecutive assignments of 'start' and 'end'.\n" - "[test.cpp:2]: (style) Parameter 'x' can be declared as pointer to const\n", + "[test.cpp:2]: (style) Parameter 'x' can be declared as pointer to const\n" + "[test.cpp:2]: (style) Parameter 'x' can be declared as pointer to const\n", // duplicate errout.str()); check("struct Foo { int f() const; };\n" @@ -7821,7 +7847,11 @@ class TestOther : public TestFixture { " if (*p < 0) continue;\n" " if ((*p > 0)) {}\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3]: (style) Variable 'p' can be declared as pointer to const\n", errout.str()); + ASSERT_EQUALS( + "[test.cpp:3]: (style) Variable 'p' can be declared as pointer to const\n" + "[test.cpp:3]: (style) Variable 'p' can be declared as pointer to const\n" // duplicate + "[test.cpp:3]: (style) Variable 'p' can be declared as pointer to const\n", // duplicate + errout.str()); check("void f() {\n" " int val = 0;\n" @@ -7831,7 +7861,9 @@ class TestOther : public TestFixture { "}\n"); TODO_ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (style) The comparison '*p < 0' is always false.\n" "[test.cpp:2] -> [test.cpp:4]: (style) The comparison '*p > 0' is always false.\n", - "[test.cpp:3]: (style) Variable 'p' can be declared as pointer to const\n", + "[test.cpp:3]: (style) Variable 'p' can be declared as pointer to const\n" + "[test.cpp:3]: (style) Variable 'p' can be declared as pointer to const\n" // duplicate + "[test.cpp:3]: (style) Variable 'p' can be declared as pointer to const\n", // duplicate errout.str()); check("void f() {\n" @@ -8495,7 +8527,11 @@ class TestOther : public TestFixture { " ptr = otherPtr;\n" " free(otherPtr - xx - 1);\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Variable 'ptr' can be declared as pointer to const\n", errout.str()); + ASSERT_EQUALS( + "[test.cpp:2]: (style) Variable 'ptr' can be declared as pointer to const\n" + "[test.cpp:2]: (style) Variable 'ptr' can be declared as pointer to const\n" // duplicate + "[test.cpp:2]: (style) Variable 'ptr' can be declared as pointer to const\n", // duplicate + errout.str()); } void checkRedundantCopy() { @@ -9072,14 +9108,20 @@ class TestOther : public TestFixture { " state_t *x = NULL;\n" " x = dostuff();\n" "}"); - ASSERT_EQUALS("test.cpp:2:style:Variable 'x' can be declared as pointer to const\n", errout.str()); + ASSERT_EQUALS( + "test.cpp:2:style:Variable 'x' can be declared as pointer to const\n" + "test.cpp:2:style:Variable 'x' can be declared as pointer to const\n", // duplicate + errout.str()); check("void f() {\n" " state_t *x;\n" " x = NULL;\n" " x = dostuff();\n" "}"); - ASSERT_EQUALS("test.cpp:2:style:Variable 'x' can be declared as pointer to const\n", errout.str()); + ASSERT_EQUALS( + "test.cpp:2:style:Variable 'x' can be declared as pointer to const\n" + "test.cpp:2:style:Variable 'x' can be declared as pointer to const\n", // duplicate + errout.str()); check("int foo() {\n" // #4420 " int x;\n" @@ -9213,7 +9255,9 @@ class TestOther : public TestFixture { " }\n" "}"); ASSERT_EQUALS("test.cpp:2:style:The scope of the variable 'p' can be reduced.\n" - "test.cpp:2:style:Variable 'p' can be declared as pointer to const\n", + "test.cpp:2:style:Variable 'p' can be declared as pointer to const\n" + "test.cpp:2:style:Variable 'p' can be declared as pointer to const\n" // duplicate + "test.cpp:2:style:Variable 'p' can be declared as pointer to const\n", // duplicate errout.str()); check("void foo() {\n" @@ -9305,14 +9349,20 @@ class TestOther : public TestFixture { " a = (void*)0;\n" " a = p;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Variable 'a' can be declared as pointer to const\n", errout.str()); + ASSERT_EQUALS( + "[test.cpp:2]: (style) Variable 'a' can be declared as pointer to const\n" + "[test.cpp:2]: (style) Variable 'a' can be declared as pointer to const\n", // duplicate + errout.str()); check("void f() {\n" " void* a;\n" " a = (void*)0U;\n" " a = p;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Variable 'a' can be declared as pointer to const\n", errout.str()); + ASSERT_EQUALS( + "[test.cpp:2]: (style) Variable 'a' can be declared as pointer to const\n" + "[test.cpp:2]: (style) Variable 'a' can be declared as pointer to const\n", // duplicate + errout.str()); } void redundantVarAssignment_struct() { @@ -9569,7 +9619,10 @@ class TestOther : public TestFixture { " int *p = NULL;\n" " p = dostuff();\n" "}"); - ASSERT_EQUALS("test.cpp:2:style:Variable 'p' can be declared as pointer to const\n", errout.str()); + ASSERT_EQUALS( + "test.cpp:2:style:Variable 'p' can be declared as pointer to const\n" + "test.cpp:2:style:Variable 'p' can be declared as pointer to const\n", // duplicate + errout.str()); // "trivial" initialization => do not warn check("void f() {\n" @@ -10552,7 +10605,10 @@ class TestOther : public TestFixture { check("void f() {\n" " int x = x = y + 1;\n" "}", "test.c"); - ASSERT_EQUALS("[test.c:2]: (warning) Redundant assignment of 'x' to itself.\n", errout.str()); + ASSERT_EQUALS( + "[test.c:2]: (warning) Redundant assignment of 'x' to itself.\n" + "[test.c:2]: (warning) Redundant assignment of 'x' to itself.\n", // duplicate + errout.str()); } void testEvaluationOrderMacro() { @@ -11368,7 +11424,9 @@ class TestOther : public TestFixture { ASSERT_EQUALS( "[test.cpp:2] -> [test.cpp:4] -> [test.cpp:3] -> [test.cpp:5] -> [test.cpp:6]: (error) Comparing pointers that point to different objects\n" "[test.cpp:4]: (style) Variable 'xp' can be declared as pointer to const\n" - "[test.cpp:5]: (style) Variable 'yp' can be declared as pointer to const\n", + "[test.cpp:5]: (style) Variable 'yp' can be declared as pointer to const\n" + "[test.cpp:4]: (style) Variable 'xp' can be declared as pointer to const\n" // duplicate + "[test.cpp:5]: (style) Variable 'yp' can be declared as pointer to const\n", // duplicate errout.str()); check("bool f() {\n" @@ -11391,7 +11449,9 @@ class TestOther : public TestFixture { ASSERT_EQUALS( "[test.cpp:1] -> [test.cpp:5] -> [test.cpp:1] -> [test.cpp:6] -> [test.cpp:7]: (error) Comparing pointers that point to different objects\n" "[test.cpp:5]: (style) Variable 'xp' can be declared as pointer to const\n" - "[test.cpp:6]: (style) Variable 'yp' can be declared as pointer to const\n", + "[test.cpp:6]: (style) Variable 'yp' can be declared as pointer to const\n" + "[test.cpp:5]: (style) Variable 'xp' can be declared as pointer to const\n" // duplicate + "[test.cpp:6]: (style) Variable 'yp' can be declared as pointer to const\n", // duplicate errout.str()); check("struct A {int data;};\n" @@ -11405,7 +11465,9 @@ class TestOther : public TestFixture { ASSERT_EQUALS( "[test.cpp:2] -> [test.cpp:3] -> [test.cpp:5] -> [test.cpp:2] -> [test.cpp:4] -> [test.cpp:6] -> [test.cpp:7]: (error) Comparing pointers that point to different objects\n" "[test.cpp:5]: (style) Variable 'xp' can be declared as pointer to const\n" - "[test.cpp:6]: (style) Variable 'yp' can be declared as pointer to const\n", + "[test.cpp:6]: (style) Variable 'yp' can be declared as pointer to const\n" + "[test.cpp:5]: (style) Variable 'xp' can be declared as pointer to const\n" // duplicate + "[test.cpp:6]: (style) Variable 'yp' can be declared as pointer to const\n", // duplicate errout.str()); check("bool f(int * xp, int* yp) {\n" @@ -11431,7 +11493,9 @@ class TestOther : public TestFixture { " return xp > yp;\n" "}"); ASSERT_EQUALS("[test.cpp:3]: (style) Variable 'xp' can be declared as pointer to const\n" - "[test.cpp:4]: (style) Variable 'yp' can be declared as pointer to const\n", + "[test.cpp:4]: (style) Variable 'yp' can be declared as pointer to const\n" + "[test.cpp:3]: (style) Variable 'xp' can be declared as pointer to const\n" // duplicate + "[test.cpp:4]: (style) Variable 'yp' can be declared as pointer to const\n", // duplicate errout.str()); check("bool f(const int * xp, const int* yp) {\n" @@ -11463,7 +11527,9 @@ class TestOther : public TestFixture { " return xp > yp;\n" "}"); ASSERT_EQUALS("[test.cpp:5]: (style) Variable 'xp' can be declared as pointer to const\n" - "[test.cpp:6]: (style) Variable 'yp' can be declared as pointer to const\n", + "[test.cpp:6]: (style) Variable 'yp' can be declared as pointer to const\n" + "[test.cpp:5]: (style) Variable 'xp' can be declared as pointer to const\n" // duplicate + "[test.cpp:6]: (style) Variable 'yp' can be declared as pointer to const\n", // duplicate errout.str()); check("struct S { int i; };\n" // #11576 diff --git a/test/testsimplifytypedef.cpp b/test/testsimplifytypedef.cpp index 8d3f0bb883cd..089d3474b9d1 100644 --- a/test/testsimplifytypedef.cpp +++ b/test/testsimplifytypedef.cpp @@ -1619,7 +1619,8 @@ class TestSimplifyTypedef : public TestFixture { checkSimplifyTypedef(code); ASSERT_EQUALS_WITHOUT_LINENUMBERS( - "[test.cpp:3]: (debug) valueflow.cpp:6541:(valueFlow) bailout: valueFlowAfterCondition: bailing in conditional block\n", + "[test.cpp:3]: (debug) valueflow.cpp:6541:(valueFlow) bailout: valueFlowAfterCondition: bailing in conditional block\n" + "[test.cpp:3]: (debug) valueflow.cpp:6541:(valueFlow) bailout: valueFlowAfterCondition: bailing in conditional block\n", // duplicate errout.str()); } diff --git a/test/teststl.cpp b/test/teststl.cpp index 523a0c59b525..851d6a57108a 100644 --- a/test/teststl.cpp +++ b/test/teststl.cpp @@ -312,7 +312,10 @@ class TestStl : public TestFixture { " std::string s;\n" " x = s.begin() + 1;\n" "}"); - ASSERT_EQUALS("test.cpp:3:error:Out of bounds access in expression 's.begin()+1' because 's' is empty.\n", errout.str()); + ASSERT_EQUALS( + "test.cpp:3:error:Out of bounds access in expression 's.begin()+1' because 's' is empty.\n" + "test.cpp:3:error:Out of bounds access in expression 's.begin()+1' because 's' is empty.\n", // duplicate + errout.str()); checkNormal("void f(int x) {\n" " std::string s;\n" @@ -1720,7 +1723,8 @@ class TestStl : public TestFixture { " {\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:5]: (error) Iterators of different containers 'l1' and 'l2' are used together.\n", + ASSERT_EQUALS("[test.cpp:5]: (error) Iterators of different containers 'l1' and 'l2' are used together.\n" + "[test.cpp:5]: (error) Iterators of different containers 'l1' and 'l2' are used together.\n", // duplicate errout.str()); } @@ -3724,7 +3728,11 @@ class TestStl : public TestFixture { " if (f.x.size() == 0) {}\n" "}"; check(code, false, Standards::CPP03); - ASSERT_EQUALS("[test.cpp:10]: (performance) Possible inefficient checking for 'x' emptiness.\n", errout.str()); + ASSERT_EQUALS( + "[test.cpp:10]: (performance) Possible inefficient checking for 'x' emptiness.\n" + "[test.cpp:10]: (performance) Possible inefficient checking for 'x' emptiness.\n", // duplicate + errout.str()); + check(code); ASSERT_EQUALS("", errout.str()); } @@ -3742,7 +3750,10 @@ class TestStl : public TestFixture { " if (zzz->x.size() > 0) { }\n" "}"; check(code, false, Standards::CPP03); - ASSERT_EQUALS("[test.cpp:10]: (performance) Possible inefficient checking for 'x' emptiness.\n", errout.str()); + ASSERT_EQUALS( + "[test.cpp:10]: (performance) Possible inefficient checking for 'x' emptiness.\n" + "[test.cpp:10]: (performance) Possible inefficient checking for 'x' emptiness.\n", // duplicate + errout.str()); code = "namespace N {\n" " class Zzz {\n" @@ -3756,7 +3767,11 @@ class TestStl : public TestFixture { " if (zzz->x.size() > 0) { }\n" "}"; check(code, false, Standards::CPP03); - ASSERT_EQUALS("[test.cpp:10]: (performance) Possible inefficient checking for 'x' emptiness.\n", errout.str()); + ASSERT_EQUALS( + "[test.cpp:10]: (performance) Possible inefficient checking for 'x' emptiness.\n" + "[test.cpp:10]: (performance) Possible inefficient checking for 'x' emptiness.\n", // duplicate + errout.str()); + check(code); ASSERT_EQUALS("", errout.str()); } diff --git a/test/testsymboldatabase.cpp b/test/testsymboldatabase.cpp index a0965e3a82f3..b59ed1fbfb71 100644 --- a/test/testsymboldatabase.cpp +++ b/test/testsymboldatabase.cpp @@ -3071,7 +3071,10 @@ class TestSymbolDatabase : public TestFixture { check("testing::testing()\n" "{\n" "}"); - ASSERT_EQUALS("[test.cpp:1]: (debug) Executable scope 'testing' with unknown function.\n", errout.str()); + ASSERT_EQUALS( + "[test.cpp:1]: (debug) Executable scope 'testing' with unknown function.\n" + "[test.cpp:1]: (debug) Executable scope 'testing' with unknown function.\n", // duplicate + errout.str()); } void symboldatabase5() { @@ -3194,7 +3197,9 @@ class TestSymbolDatabase : public TestFixture { check("::y(){x}"); ASSERT_EQUALS("[test.cpp:1]: (debug) Executable scope 'y' with unknown function.\n" - "[test.cpp:1]: (debug) valueFlowConditionExpressions bailout: Skipping function due to incomplete variable x\n", errout.str()); + "[test.cpp:1]: (debug) valueFlowConditionExpressions bailout: Skipping function due to incomplete variable x\n" + "[test.cpp:1]: (debug) Executable scope 'y' with unknown function.\n", // duplicate + errout.str()); } void symboldatabase20() { diff --git a/test/testunusedvar.cpp b/test/testunusedvar.cpp index fc04d144a397..b36a45f567c2 100644 --- a/test/testunusedvar.cpp +++ b/test/testunusedvar.cpp @@ -2004,7 +2004,10 @@ class TestUnusedVar : public TestFixture { "{\n" " int i = 0;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (style) Variable 'i' is assigned a value that is never used.\n", errout.str()); + ASSERT_EQUALS( + "[test.cpp:3]: (style) Variable 'i' is assigned a value that is never used.\n" + "[test.cpp:3]: (style) Variable 'i' is assigned a value that is never used.\n", // duplicate + errout.str()); functionVariableUsage("void foo()\n" "{\n" @@ -2078,13 +2081,19 @@ class TestUnusedVar : public TestFixture { "{\n" " bool i = false;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (style) Variable 'i' is assigned a value that is never used.\n", errout.str()); + ASSERT_EQUALS( + "[test.cpp:3]: (style) Variable 'i' is assigned a value that is never used.\n" + "[test.cpp:3]: (style) Variable 'i' is assigned a value that is never used.\n", // duplicate + errout.str()); functionVariableUsage("void foo()\n" "{\n" " bool i = true;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (style) Variable 'i' is assigned a value that is never used.\n", errout.str()); + ASSERT_EQUALS( + "[test.cpp:3]: (style) Variable 'i' is assigned a value that is never used.\n" + "[test.cpp:3]: (style) Variable 'i' is assigned a value that is never used.\n", // duplicate + errout.str()); functionVariableUsage("void foo()\n" "{\n" @@ -2105,43 +2114,64 @@ class TestUnusedVar : public TestFixture { " undefined i = 0;\n" "}\n", "test.c"); - ASSERT_EQUALS("[test.c:3]: (style) Variable 'i' is assigned a value that is never used.\n", errout.str()); + ASSERT_EQUALS( + "[test.c:3]: (style) Variable 'i' is assigned a value that is never used.\n" + "[test.c:3]: (style) Variable 'i' is assigned a value that is never used.\n", // duplicate + errout.str()); functionVariableUsage("void foo()\n" "{\n" " int i = undefined;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (style) Variable 'i' is assigned a value that is never used.\n", errout.str()); + ASSERT_EQUALS( + "[test.cpp:3]: (style) Variable 'i' is assigned a value that is never used.\n" + "[test.cpp:3]: (style) Variable 'i' is assigned a value that is never used.\n", // duplicate + errout.str()); functionVariableUsage("void foo()\n" "{\n" " int * i = Data;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (style) Variable 'i' is assigned a value that is never used.\n", errout.str()); + ASSERT_EQUALS( + "[test.cpp:3]: (style) Variable 'i' is assigned a value that is never used.\n" + "[test.cpp:3]: (style) Variable 'i' is assigned a value that is never used.\n", // duplicate + errout.str()); functionVariableUsage("void foo()\n" "{\n" " void * i = Data;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (style) Variable 'i' is assigned a value that is never used.\n", errout.str()); + ASSERT_EQUALS( + "[test.cpp:3]: (style) Variable 'i' is assigned a value that is never used.\n" + "[test.cpp:3]: (style) Variable 'i' is assigned a value that is never used.\n", // duplicate + errout.str()); functionVariableUsage("void foo()\n" "{\n" " const void * i = Data;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (style) Variable 'i' is assigned a value that is never used.\n", errout.str()); + ASSERT_EQUALS( + "[test.cpp:3]: (style) Variable 'i' is assigned a value that is never used.\n" + "[test.cpp:3]: (style) Variable 'i' is assigned a value that is never used.\n", // duplicate + errout.str()); functionVariableUsage("void foo()\n" "{\n" " struct S * i = DATA;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (style) Variable 'i' is assigned a value that is never used.\n", errout.str()); + ASSERT_EQUALS( + "[test.cpp:3]: (style) Variable 'i' is assigned a value that is never used.\n" + "[test.cpp:3]: (style) Variable 'i' is assigned a value that is never used.\n", // duplicate + errout.str()); functionVariableUsage("void foo()\n" "{\n" " const struct S * i = DATA;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (style) Variable 'i' is assigned a value that is never used.\n", errout.str()); + ASSERT_EQUALS( + "[test.cpp:3]: (style) Variable 'i' is assigned a value that is never used.\n" + "[test.cpp:3]: (style) Variable 'i' is assigned a value that is never used.\n", // duplicate + errout.str()); functionVariableUsage("void foo()\n" "{\n" @@ -2159,14 +2189,20 @@ class TestUnusedVar : public TestFixture { "{\n" " undefined * i = X;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (style) Variable 'i' is assigned a value that is never used.\n", errout.str()); + ASSERT_EQUALS( + "[test.cpp:3]: (style) Variable 'i' is assigned a value that is never used.\n" + "[test.cpp:3]: (style) Variable 'i' is assigned a value that is never used.\n", // duplicate + errout.str()); functionVariableUsage("void foo()\n" "{\n" " int i = 0;\n" " int j = i;\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (style) Variable 'j' is assigned a value that is never used.\n", errout.str()); + ASSERT_EQUALS( + "[test.cpp:4]: (style) Variable 'j' is assigned a value that is never used.\n" + "[test.cpp:4]: (style) Variable 'j' is assigned a value that is never used.\n", // duplicate + errout.str()); functionVariableUsage("void foo()\n" "{\n" @@ -2190,13 +2226,19 @@ class TestUnusedVar : public TestFixture { "{\n" " char *i = \"123456789\";\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (style) Variable 'i' is assigned a value that is never used.\n", errout.str()); + ASSERT_EQUALS( + "[test.cpp:3]: (style) Variable 'i' is assigned a value that is never used.\n" + "[test.cpp:3]: (style) Variable 'i' is assigned a value that is never used.\n", // duplicate + errout.str()); functionVariableUsage("void foo()\n" "{\n" " int i = 0;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (style) Variable 'i' is assigned a value that is never used.\n", errout.str()); + ASSERT_EQUALS( + "[test.cpp:3]: (style) Variable 'i' is assigned a value that is never used.\n" + "[test.cpp:3]: (style) Variable 'i' is assigned a value that is never used.\n", // duplicate + errout.str()); functionVariableUsage("void foo()\n" "{\n" @@ -2430,7 +2472,10 @@ class TestUnusedVar : public TestFixture { functionVariableUsage("void foo(int j = 0) {\n" // #5985 - default function parameters should not affect checking results " int i = 0;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Variable 'i' is assigned a value that is never used.\n", errout.str()); + ASSERT_EQUALS( + "[test.cpp:2]: (style) Variable 'i' is assigned a value that is never used.\n" + "[test.cpp:2]: (style) Variable 'i' is assigned a value that is never used.\n", // duplicate + errout.str()); // extracttests.enable } @@ -2887,7 +2932,9 @@ class TestUnusedVar : public TestFixture { "}"); ASSERT_EQUALS("[test.cpp:7]: (style) Variable 'i' is assigned a value that is never used.\n" "[test.cpp:3]: (style) Unused variable: i\n" - "[test.cpp:5]: (style) Unused variable: i\n", errout.str()); + "[test.cpp:5]: (style) Unused variable: i\n" + "[test.cpp:7]: (style) Variable 'i' is assigned a value that is never used.\n", // duplicate + errout.str()); functionVariableUsage("void foo(int x)\n" "{\n" @@ -3533,7 +3580,10 @@ class TestUnusedVar : public TestFixture { "void A::DoSomething(void) {\n" " const std::string x = Bar();\n" // <- warning "}"); - ASSERT_EQUALS("[test.cpp:16]: (style) Variable 'x' is assigned a value that is never used.\n", errout.str()); + ASSERT_EQUALS( + "[test.cpp:16]: (style) Variable 'x' is assigned a value that is never used.\n" + "[test.cpp:16]: (style) Variable 'x' is assigned a value that is never used.\n", // duplicate + errout.str()); } void localvar50() { // #6261, #6542 @@ -3715,13 +3765,19 @@ class TestUnusedVar : public TestFixture { " int i = 0, j = 1;\n" " return i;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:2]: (style) Variable 'j' is assigned a value that is never used.\n", errout.str()); + ASSERT_EQUALS( + "[test.cpp:2]: (style) Variable 'j' is assigned a value that is never used.\n" + "[test.cpp:2]: (style) Variable 'j' is assigned a value that is never used.\n", // duplicate + errout.str()); functionVariableUsage("int f() {\n" " int i = 0, j = 1;\n" " return j;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:2]: (style) Variable 'i' is assigned a value that is never used.\n", errout.str()); + ASSERT_EQUALS( + "[test.cpp:2]: (style) Variable 'i' is assigned a value that is never used.\n" + "[test.cpp:2]: (style) Variable 'i' is assigned a value that is never used.\n", // duplicate + errout.str()); functionVariableUsage("void f() {\n" // #10846 " int i = 1; while (i) { i = g(); }\n" @@ -3961,7 +4017,9 @@ class TestUnusedVar : public TestFixture { " int *b = &a;\n" "}"); ASSERT_EQUALS("[test.cpp:4]: (style) Variable 'b' is assigned a value that is never used.\n" - "[test.cpp:3]: (style) Unused variable: a\n", errout.str()); + "[test.cpp:3]: (style) Unused variable: a\n" + "[test.cpp:4]: (style) Variable 'b' is assigned a value that is never used.\n", // duplicate + errout.str()); functionVariableUsage("void foo()\n" "{\n" @@ -3969,7 +4027,9 @@ class TestUnusedVar : public TestFixture { " int *b = a;\n" "}"); ASSERT_EQUALS("[test.cpp:4]: (style) Variable 'b' is assigned a value that is never used.\n" - "[test.cpp:3]: (style) Unused variable: a\n", errout.str()); + "[test.cpp:3]: (style) Unused variable: a\n" + "[test.cpp:4]: (style) Variable 'b' is assigned a value that is never used.\n", // duplicate + errout.str()); functionVariableUsage("void foo()\n" "{\n" @@ -4047,14 +4107,20 @@ class TestUnusedVar : public TestFixture { "{\n" " int *b = &a;\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (style) Variable 'b' is assigned a value that is never used.\n", errout.str()); + ASSERT_EQUALS( + "[test.cpp:4]: (style) Variable 'b' is assigned a value that is never used.\n" + "[test.cpp:4]: (style) Variable 'b' is assigned a value that is never used.\n", // duplicate + errout.str()); // a is not a local variable and b is aliased to it functionVariableUsage("void foo(int a)\n" "{\n" " int *b = &a;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (style) Variable 'b' is assigned a value that is never used.\n", errout.str()); + ASSERT_EQUALS( + "[test.cpp:3]: (style) Variable 'b' is assigned a value that is never used.\n" + "[test.cpp:3]: (style) Variable 'b' is assigned a value that is never used.\n", // duplicate + errout.str()); // a is not a local variable and b is aliased to it functionVariableUsage("class A\n" @@ -4065,7 +4131,10 @@ class TestUnusedVar : public TestFixture { " int *b = &a;\n" " }\n" "};"); - ASSERT_EQUALS("[test.cpp:6]: (style) Variable 'b' is assigned a value that is never used.\n", errout.str()); + ASSERT_EQUALS( + "[test.cpp:6]: (style) Variable 'b' is assigned a value that is never used.\n" + "[test.cpp:6]: (style) Variable 'b' is assigned a value that is never used.\n", // duplicate + errout.str()); functionVariableUsage("int a;\n" "void foo()\n" @@ -4273,7 +4342,8 @@ class TestUnusedVar : public TestFixture { " *d = 0;\n" "}"); ASSERT_EQUALS("[test.cpp:5]: (style) Variable 'c' is assigned a value that is never used.\n" - "[test.cpp:3]: (style) Unused variable: a\n", + "[test.cpp:3]: (style) Unused variable: a\n" + "[test.cpp:5]: (style) Variable 'c' is assigned a value that is never used.\n", // duplicate errout.str()); functionVariableUsage("void foo()\n" @@ -4318,8 +4388,11 @@ class TestUnusedVar : public TestFixture { " b[-10] = 0;\n" " int * c = b - 10;\n" "}"); - ASSERT_EQUALS(// TODO "[test.cpp:4]: (style) Variable 'a' is assigned a value that is never used.\n" - "[test.cpp:5]: (style) Variable 'c' is assigned a value that is never used.\n", errout.str()); + TODO_ASSERT_EQUALS( + "[test.cpp:4]: (style) Variable 'a' is assigned a value that is never used.\n", + "[test.cpp:5]: (style) Variable 'c' is assigned a value that is never used.\n" + "[test.cpp:5]: (style) Variable 'c' is assigned a value that is never used.\n", // duplicate + errout.str()); functionVariableUsage("void foo()\n" "{\n" @@ -4375,7 +4448,9 @@ class TestUnusedVar : public TestFixture { " struct S * s = (struct S *)a;\n" "}"); ASSERT_EQUALS("[test.cpp:5]: (style) Variable 's' is assigned a value that is never used.\n" - "[test.cpp:4]: (style) Unused variable: a\n", errout.str()); + "[test.cpp:4]: (style) Unused variable: a\n" + "[test.cpp:5]: (style) Variable 's' is assigned a value that is never used.\n", // duplicate + errout.str()); functionVariableUsage("struct S { char c[100]; };\n" "void foo()\n" @@ -4384,7 +4459,9 @@ class TestUnusedVar : public TestFixture { " const struct S * s = (const struct S *)a;\n" "}"); ASSERT_EQUALS("[test.cpp:5]: (style) Variable 's' is assigned a value that is never used.\n" - "[test.cpp:4]: (style) Unused variable: a\n", errout.str()); + "[test.cpp:4]: (style) Unused variable: a\n" + "[test.cpp:5]: (style) Variable 's' is assigned a value that is never used.\n", // duplicate + errout.str()); functionVariableUsage("struct S { char c[100]; };\n" "void foo()\n" @@ -4393,7 +4470,9 @@ class TestUnusedVar : public TestFixture { " struct S * s = static_cast(a);\n" "}"); ASSERT_EQUALS("[test.cpp:5]: (style) Variable 's' is assigned a value that is never used.\n" - "[test.cpp:4]: (style) Unused variable: a\n", errout.str()); + "[test.cpp:4]: (style) Unused variable: a\n" + "[test.cpp:5]: (style) Variable 's' is assigned a value that is never used.\n", // duplicate + errout.str()); functionVariableUsage("struct S { char c[100]; };\n" "void foo()\n" @@ -4402,7 +4481,9 @@ class TestUnusedVar : public TestFixture { " const struct S * s = static_cast(a);\n" "}"); ASSERT_EQUALS("[test.cpp:5]: (style) Variable 's' is assigned a value that is never used.\n" - "[test.cpp:4]: (style) Unused variable: a\n", errout.str()); + "[test.cpp:4]: (style) Unused variable: a\n" + "[test.cpp:5]: (style) Variable 's' is assigned a value that is never used.\n", // duplicate + errout.str()); functionVariableUsage("int a[10];\n" "void foo()\n" @@ -4460,7 +4541,10 @@ class TestUnusedVar : public TestFixture { "{\n" " int * a = &ab.a;\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (style) Variable 'a' is assigned a value that is never used.\n", errout.str()); + ASSERT_EQUALS( + "[test.cpp:4]: (style) Variable 'a' is assigned a value that is never used.\n" + "[test.cpp:4]: (style) Variable 'a' is assigned a value that is never used.\n", // duplicate + errout.str()); functionVariableUsage("struct AB { int a; int b; } ab;\n" "void foo()\n" @@ -4477,7 +4561,9 @@ class TestUnusedVar : public TestFixture { " int * a = &ab.a;\n" "}"); ASSERT_EQUALS("[test.cpp:5]: (style) Variable 'a' is assigned a value that is never used.\n" - "[test.cpp:4]: (style) Variable 'ab' is not assigned a value.\n", errout.str()); + "[test.cpp:4]: (style) Variable 'ab' is not assigned a value.\n" + "[test.cpp:5]: (style) Variable 'a' is assigned a value that is never used.\n", // duplicate + errout.str()); functionVariableUsage("struct AB { int a; int b; };\n" "void foo()\n" @@ -5091,7 +5177,10 @@ class TestUnusedVar : public TestFixture { " struct ABC { int a, b, c; };\n" " struct ABC abc = { 1, 2, 3 };\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (style) Variable 'abc' is assigned a value that is never used.\n", errout.str()); + ASSERT_EQUALS( + "[test.cpp:4]: (style) Variable 'abc' is assigned a value that is never used.\n" + "[test.cpp:4]: (style) Variable 'abc' is assigned a value that is never used.\n", // duplicate + errout.str()); } void localvarStruct3() { @@ -5149,7 +5238,10 @@ class TestUnusedVar : public TestFixture { " A a = { 0 };\n" " return 0;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (style) Variable 'a' is assigned a value that is never used.\n", errout.str()); + ASSERT_EQUALS( + "[test.cpp:3]: (style) Variable 'a' is assigned a value that is never used.\n" + "[test.cpp:3]: (style) Variable 'a' is assigned a value that is never used.\n", // duplicate + errout.str()); // extracttests.disable functionVariableUsage("class A { int i; };\n" @@ -5157,9 +5249,12 @@ class TestUnusedVar : public TestFixture { " A a = { 0 };\n" " return 0;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (style) Variable 'a' is assigned a value that is never used.\n", errout.str()); - // extracttests.enable + ASSERT_EQUALS( + "[test.cpp:3]: (style) Variable 'a' is assigned a value that is never used.\n" + "[test.cpp:3]: (style) Variable 'a' is assigned a value that is never used.\n", // duplicate + errout.str()); + // extracttests.enable functionVariableUsage("class A { int i; public: A(); { } };\n" "int foo() {\n" " A a;\n" @@ -5428,7 +5523,10 @@ class TestUnusedVar : public TestFixture { " else\n" " return 1;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (style) Variable 'y' is assigned a value that is never used.\n", errout.str()); + ASSERT_EQUALS( + "[test.cpp:3]: (style) Variable 'y' is assigned a value that is never used.\n" + "[test.cpp:3]: (style) Variable 'y' is assigned a value that is never used.\n", // duplicate + errout.str()); functionVariableUsage("int foo(int x)\n" "{\n" @@ -6086,12 +6184,18 @@ class TestUnusedVar : public TestFixture { functionVariableUsage("void foo() {\n" " std::string s = \"foo\";\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Variable 's' is assigned a value that is never used.\n", errout.str()); + ASSERT_EQUALS( + "[test.cpp:2]: (style) Variable 's' is assigned a value that is never used.\n" + "[test.cpp:2]: (style) Variable 's' is assigned a value that is never used.\n", // duplicate + errout.str()); functionVariableUsage("void foo() {\n" // #8901 " const std::string s = \"foo\";\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Variable 's' is assigned a value that is never used.\n", errout.str()); + ASSERT_EQUALS( + "[test.cpp:2]: (style) Variable 's' is assigned a value that is never used.\n" + "[test.cpp:2]: (style) Variable 's' is assigned a value that is never used.\n", // duplicate + errout.str()); functionVariableUsage("std::string foo() {\n" " std::string s;\n" // Class instances are initialized. Assignment is not necessary @@ -6129,7 +6233,10 @@ class TestUnusedVar : public TestFixture { functionVariableUsage("void foo() {\n" " const bool b = true;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Variable 'b' is assigned a value that is never used.\n", errout.str()); + ASSERT_EQUALS( + "[test.cpp:2]: (style) Variable 'b' is assigned a value that is never used.\n" + "[test.cpp:2]: (style) Variable 'b' is assigned a value that is never used.\n", // duplicate + errout.str()); } void localvarconst2() { @@ -6256,7 +6363,10 @@ class TestUnusedVar : public TestFixture { functionVariableUsage("void f() {\n" " std::string x = foo();\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Variable 'x' is assigned a value that is never used.\n", errout.str()); + ASSERT_EQUALS( + "[test.cpp:2]: (style) Variable 'x' is assigned a value that is never used.\n" + "[test.cpp:2]: (style) Variable 'x' is assigned a value that is never used.\n", // duplicate + errout.str()); functionVariableUsage("void f() {\n" " std::vector x;\n" @@ -6396,7 +6506,9 @@ class TestUnusedVar : public TestFixture { " auto a2 = std::unique_ptr(new A());\n" "}\n"); ASSERT_EQUALS("[test.cpp:7]: (style) Variable 'a' is assigned a value that is never used.\n" - "[test.cpp:8]: (style) Variable 'a2' is assigned a value that is never used.\n", errout.str()); + "[test.cpp:8]: (style) Variable 'a2' is assigned a value that is never used.\n" + "[test.cpp:8]: (style) Variable 'a2' is assigned a value that is never used.\n", // duplicate + errout.str()); functionVariableUsage("void g();\n" // #11094 "void f() {\n" diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index 13d3b5bdd655..67ee645ccb5c 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -1835,7 +1835,8 @@ class TestValueFlow : public TestFixture { "}"); ASSERT_EQUALS_WITHOUT_LINENUMBERS( "[test.cpp:3]: (debug) valueFlowConditionExpressions bailout: Skipping function due to incomplete variable a\n" - "[test.cpp:4]: (debug) valueflow.cpp:1260:(valueFlow) bailout: variable 'x', condition is defined in macro\n", + "[test.cpp:4]: (debug) valueflow.cpp:1260:(valueFlow) bailout: variable 'x', condition is defined in macro\n" + "[test.cpp:4]: (debug) valueflow.cpp:1260:(valueFlow) bailout: variable 'x', condition is defined in macro\n", // duplicate errout.str()); bailout("#define FREE(obj) ((obj) ? (free((char *) (obj)), (obj) = 0) : 0)\n" // #8349 @@ -1845,7 +1846,8 @@ class TestValueFlow : public TestFixture { "}"); ASSERT_EQUALS_WITHOUT_LINENUMBERS( "[test.cpp:3]: (debug) valueFlowConditionExpressions bailout: Skipping function due to incomplete variable a\n" - "[test.cpp:4]: (debug) valueflow.cpp:1260:(valueFlow) bailout: variable 'x', condition is defined in macro\n", + "[test.cpp:4]: (debug) valueflow.cpp:1260:(valueFlow) bailout: variable 'x', condition is defined in macro\n" + "[test.cpp:4]: (debug) valueflow.cpp:1260:(valueFlow) bailout: variable 'x', condition is defined in macro\n", // duplicate errout.str()); } @@ -1859,7 +1861,8 @@ class TestValueFlow : public TestFixture { "}"); ASSERT_EQUALS_WITHOUT_LINENUMBERS( "[test.cpp:3]: (debug) valueFlowConditionExpressions bailout: Skipping function due to incomplete variable a\n" - "[test.cpp:2]: (debug) valueflow.cpp::(valueFlow) bailout: valueFlowAfterCondition: bailing in conditional block\n", + "[test.cpp:2]: (debug) valueflow.cpp::(valueFlow) bailout: valueFlowAfterCondition: bailing in conditional block\n" + "[test.cpp:2]: (debug) valueflow.cpp::(valueFlow) bailout: valueFlowAfterCondition: bailing in conditional block\n", // duplicate errout.str()); // #5721 - FP