Add more testcases for zerodiv
This commit is contained in:
parent
7021cb2c6b
commit
ea62ab337b
|
@ -43,6 +43,7 @@ private:
|
|||
TEST_CASE(zeroDiv8);
|
||||
TEST_CASE(zeroDiv9);
|
||||
TEST_CASE(zeroDiv10);
|
||||
TEST_CASE(zeroDiv11);
|
||||
|
||||
TEST_CASE(zeroDivCond); // division by zero / useless condition
|
||||
|
||||
|
@ -419,6 +420,20 @@ private:
|
|||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void zeroDiv11() {
|
||||
check("void f() {\n"
|
||||
" int res = (1+2)/0;\n"
|
||||
" int res = (1*2)/0;\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:2]: (error) Division by zero.\n"
|
||||
"[test.cpp:3]: (error) Division by zero.\n", errout.str());
|
||||
check("void f() {\n"
|
||||
" int res = (a+2)/0;\n"
|
||||
" int res = (a*2)/0;\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void zeroDivCond() {
|
||||
check("void f(unsigned int x) {\n"
|
||||
" int y = 17 / x;\n"
|
||||
|
|
Loading…
Reference in New Issue