From 82c46b2e4e3cd0c4709b800267752ba48ee3e675 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 | 122 ++++++++++++++++----- test/testsimplifytypedef.cpp | 3 +- test/testsingleexecutor.cpp | 5 +- test/teststl.cpp | 25 ++++- test/testsymboldatabase.cpp | 9 +- test/testunusedvar.cpp | 198 +++++++++++++++++++++++++++-------- test/testvalueflow.cpp | 9 +- 12 files changed, 339 insertions(+), 99 deletions(-) diff --git a/test/fixture.cpp b/test/fixture.cpp index 1a72724a0b7..fd8ac2ffafe 100644 --- a/test/fixture.cpp +++ b/test/fixture.cpp @@ -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) diff --git a/test/testautovariables.cpp b/test/testautovariables.cpp index b48f49fe727..8ba1298158e 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" @@ -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 f() {\n" @@ -3804,7 +3809,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" @@ -3812,7 +3818,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 17115bd9e50..c16477fb60e 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 e223e74b05f..636df6e8d06 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 217e724057c..f2ad99a9ede 100644 --- a/test/testnullpointer.cpp +++ b/test/testnullpointer.cpp @@ -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" @@ -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" @@ -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" @@ -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" @@ -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() { @@ -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" diff --git a/test/testother.cpp b/test/testother.cpp index 20228dfa911..8e33d2d099d 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -3111,8 +3111,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" @@ -3327,14 +3330,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" @@ -3660,7 +3670,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" @@ -3668,7 +3681,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" @@ -3681,7 +3697,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" @@ -3772,7 +3789,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" @@ -3835,7 +3854,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" @@ -3982,7 +4002,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 @@ -3998,6 +4019,8 @@ class TestOther : public TestFixture { " delete[] b;\n" "}\n"); ASSERT_EQUALS("[test.cpp:1]: (style) Parameter 'a1' can be declared as pointer to const\n" + "[test.cpp:1]: (style) Parameter 'a2' can be declared as pointer to const\n" + "[test.cpp:1]: (style) Parameter 'a1' can be declared as pointer to const\n" "[test.cpp:1]: (style) Parameter 'a2' can be declared as pointer to const\n", errout.str()); } @@ -6657,7 +6680,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()); } @@ -7668,7 +7694,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" @@ -7677,7 +7704,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" @@ -7880,7 +7908,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" @@ -7890,7 +7922,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" @@ -8554,7 +8588,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() { @@ -9131,14 +9169,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" @@ -9272,7 +9316,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" @@ -9364,14 +9410,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() { @@ -9628,7 +9680,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" @@ -10611,7 +10666,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() { @@ -11427,7 +11485,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" @@ -11450,7 +11510,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" @@ -11464,7 +11526,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" @@ -11490,7 +11554,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" @@ -11522,7 +11588,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 8d3f0bb883c..089d3474b9d 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/testsingleexecutor.cpp b/test/testsingleexecutor.cpp index d769e0b05db..6abdcf23933 100644 --- a/test/testsingleexecutor.cpp +++ b/test/testsingleexecutor.cpp @@ -348,7 +348,10 @@ class TestSingleExecutorBase : public TestFixture { check(2, 2, "#include \"" + inc_h.name() + "\""); // these are not actually made unique by the implementation. That needs to be done by the given ErrorLogger - ASSERT_EQUALS("[" + inc_h.name() + ":3]: (error) Null pointer dereference: (int*)0\n", errout.str()); + ASSERT_EQUALS( + "[" + inc_h.name() + ":3]: (error) Null pointer dereference: (int*)0\n" + "[" + inc_h.name() + ":3]: (error) Null pointer dereference: (int*)0\n", + errout.str()); } // TODO: test whole program analysis diff --git a/test/teststl.cpp b/test/teststl.cpp index 190978c9cd8..1b26e57ebb4 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()); } @@ -3723,7 +3727,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()); } @@ -3741,7 +3749,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" @@ -3755,7 +3766,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 a0965e3a82f..b59ed1fbfb7 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 e9c50edda94..a4237aefa2d 100644 --- a/test/testunusedvar.cpp +++ b/test/testunusedvar.cpp @@ -2018,7 +2018,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" @@ -2092,13 +2095,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" @@ -2119,43 +2128,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" @@ -2173,14 +2203,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" @@ -2204,13 +2240,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" @@ -2444,7 +2486,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 } @@ -2901,7 +2946,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" @@ -3547,7 +3594,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 @@ -3729,13 +3779,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" @@ -3975,7 +4031,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" @@ -3983,7 +4041,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" @@ -4061,14 +4121,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" @@ -4079,7 +4145,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" @@ -4287,7 +4356,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" @@ -4332,8 +4402,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" @@ -4389,7 +4462,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" @@ -4398,7 +4473,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" @@ -4407,7 +4484,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" @@ -4416,7 +4495,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" @@ -4474,7 +4555,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" @@ -4491,7 +4575,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" @@ -5105,7 +5191,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() { @@ -5163,7 +5252,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" @@ -5171,9 +5263,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" @@ -5459,7 +5554,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" @@ -6117,12 +6215,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 @@ -6160,7 +6264,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() { @@ -6287,7 +6394,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" @@ -6427,7 +6537,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 6c8cea6023e..c7eda198184 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -1852,7 +1852,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 @@ -1862,7 +1863,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()); } @@ -1876,7 +1878,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