From f59164302d3c55391962e7203fd3d938cbe0a41a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Mon, 29 Jul 2013 11:43:08 +0200 Subject: [PATCH] TestAssignIf: improved code coverage --- test/testassignif.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/test/testassignif.cpp b/test/testassignif.cpp index 1c1f48270..498db206b 100644 --- a/test/testassignif.cpp +++ b/test/testassignif.cpp @@ -159,6 +159,13 @@ private: "}"); ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:4]: (style) Mismatching assignment and comparison, comparison 'y==8' is always false.\n", errout.str()); + check("void f(int x) {\n" + " int y = x & 7;\n" + " do_something(&y);\n" // passing variable => no error + " if (y==8);\n" + "}"); + ASSERT_EQUALS("", errout.str()); + check("void f(int x) {\n" " extern int y; y = x & 7;\n" " do_something();\n" @@ -180,6 +187,28 @@ private: " if (x==18) { }\n" "}"); ASSERT_EQUALS("", errout.str()); + + // bailout: no variable info + check("void foo(int x) {\n" + " y = 2 | x;\n" // y not declared => no error + " if(y == 1) {}\n" + "}"); + ASSERT_EQUALS("", errout.str()); + + // bailout: negative number + check("void foo(int x) {\n" + " int y = -2 | x;\n" // negative number => no error + " if (y==1) {}\n" + "}"); + ASSERT_EQUALS("", errout.str()); + + // bailout: pass variable to function + check("void foo(int x) {\n" + " int y = 2 | x;\n" + " bar(&y);\n" // pass variable to function => no error + " if (y==1) {}\n" + "}"); + ASSERT_EQUALS("", errout.str()); } void mismatchingBitAnd() {