added tests for duplicated branches. Inspired by http://www.viva64.com/en/b/0149/ ( Comparision between PVS-Studio and cppcheck): Errors detected in Quake 3: Arena by PVS-Studio: Fragement 2

This commit is contained in:
Ettl Martin 2012-05-30 01:30:37 +02:00
parent 1620c5b797
commit d7c1907601
1 changed files with 34 additions and 0 deletions

View File

@ -140,6 +140,7 @@ private:
TEST_CASE(duplicateIf);
TEST_CASE(duplicateIf1); // ticket 3689
TEST_CASE(duplicateBranch);
TEST_CASE(duplicateBranch1); // tests extracted by http://www.viva64.com/en/b/0149/ ( Comparision between PVS-Studio and cppcheck ): Errors detected in Quake 3: Arena by PVS-Studio: Fragement 2
TEST_CASE(duplicateExpression1);
TEST_CASE(duplicateExpression2); // ticket #2730
TEST_CASE(duplicateExpression3); // ticket #3317
@ -1342,6 +1343,7 @@ private:
}
void switchRedundantAssignmentTest() {
check("void foo()\n"
"{\n"
" int y = 1;\n"
@ -3994,6 +3996,38 @@ private:
ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:2]: (style) Found duplicate branches for if and else.\n", errout.str());
}
void duplicateBranch1() {
// tests inspired by http://www.viva64.com/en/b/0149/ ( Comparision between PVS-Studio and cppcheck )
// Errors detected in Quake 3: Arena by PVS-Studio: Fragement 2
check("void f()\n"
"{\n"
" if (front < 0) \n"
" frac = (front)/(front-back);\n"
" else \n"
" frac = (front)/(front-back);\n"
"}\n");
ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:3]: (style) Found duplicate branches for if and else.\n", errout.str());
check("void f()\n"
"{\n"
" if (front < 0) \n"
" { frac = (front)/(front-back);}\n"
" else \n"
" frac = (front)/(front-back);\n"
"}\n");
ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:3]: (style) Found duplicate branches for if and else.\n", errout.str());
check("void f()\n"
"{\n"
" if (front < 0) \n"
" { frac = (front)/(front-back);}\n"
" else \n"
" frac = (front)/((front-back));\n"
"}\n");
ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:3]: (style) Found duplicate branches for if and else.\n", errout.str());
}
void duplicateExpression1() {
check("void foo() {\n"
" if (a == a) { }\n"