Improve test coverage for redundant bitwise operations

This commit is contained in:
Dmitry-Me 2019-12-06 19:14:03 +03:00
parent 95e0b0d0f9
commit 047418dda1
1 changed files with 22 additions and 0 deletions

View File

@ -2760,6 +2760,20 @@ private:
"}"); "}");
ASSERT_EQUALS("[test.cpp:7]: (warning) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing?\n", errout.str()); ASSERT_EQUALS("[test.cpp:7]: (warning) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing?\n", errout.str());
check("void foo(int a)\n"
"{\n"
" int y = 1;\n"
" switch (a)\n"
" {\n"
" case 2:\n"
" y = y | 3;\n"
" case 3:\n"
" y = y | 3;\n"
" break;\n"
" }\n"
"}");
ASSERT_EQUALS("[test.cpp:7]: (warning) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing?\n", errout.str());
check("void foo(int a)\n" check("void foo(int a)\n"
"{\n" "{\n"
" int y = 1;\n" " int y = 1;\n"
@ -6983,6 +6997,14 @@ private:
"}"); "}");
ASSERT_EQUALS("[test.cpp:3]: (warning) Storing getchar() return value in char variable and then comparing with EOF.\n", errout.str()); ASSERT_EQUALS("[test.cpp:3]: (warning) Storing getchar() return value in char variable and then comparing with EOF.\n", errout.str());
check("void f() {\n"
" unsigned char c;\n"
" while( EOF != ( c = getchar() ) )\n"
" {\n"
" }\n"
"}");
ASSERT_EQUALS("[test.cpp:3]: (warning) Storing getchar() return value in char variable and then comparing with EOF.\n", errout.str());
check("void f() {\n" check("void f() {\n"
" int i; i = getchar();\n" " int i; i = getchar();\n"
" while( i != EOF)\n" " while( i != EOF)\n"