Add regression test for #6906 and #7284 (#1614)

* Add regression test for #6906

Ticket #6906 was fixed in f65cf220ba.
Add a test to make sure there are no regressions.

* Add regression test for #7284

Ticket #7284 was fixed in 5d1fdf7958.
Add tests to avoid regressions.
This commit is contained in:
rikardfalkeborn 2019-01-23 09:09:03 +01:00 committed by amai2012
parent ec8bc785a2
commit 8356ec6774
2 changed files with 20 additions and 0 deletions

View File

@ -496,6 +496,13 @@ private:
" else if (bar() >1 && b) {}\n" " else if (bar() >1 && b) {}\n"
"}"); "}");
ASSERT_EQUALS("[test.cpp:5]: (style) Expression is always false because 'else if' condition matches previous condition at line 4.\n", errout.str()); ASSERT_EQUALS("[test.cpp:5]: (style) Expression is always false because 'else if' condition matches previous condition at line 4.\n", errout.str());
// 7284
check("void foo() {\n"
" if (a) {}\n"
" else if (!!a) {}\n"
"}\n");
ASSERT_EQUALS("[test.cpp:3]: (style) Expression is always false because 'else if' condition matches previous condition at line 2.\n", errout.str());
} }
void checkPureFunction(const char code[]) { void checkPureFunction(const char code[]) {

View File

@ -4082,6 +4082,19 @@ private:
" return a && b && c;\n" " return a && b && c;\n"
"}\n"); "}\n");
ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (style) Same expression on both sides of '&&' because 'a' and 'c' represent the same value.\n", errout.str()); ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (style) Same expression on both sides of '&&' because 'a' and 'c' represent the same value.\n", errout.str());
// 6906
check("void f(const bool b) {\n"
" const bool b1 = !b;\n"
" if(!b && b1){}\n"
"}\n");
ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (style) Same expression on both sides of '&&' because '!b' and 'b1' represent the same value.\n", errout.str());
// 7482
check("void f(void) {\n"
" if (a || !!a) {}\n"
"}\n");
ASSERT_EQUALS("[test.cpp:2]: (style) Same expression on both sides of '||' because 'a' and '!!a' represent the same value.\n", errout.str());
} }
void duplicateExpression8() { void duplicateExpression8() {