Added a regression test for #4103 - Comparing Boolean variables (> or <)

This commit is contained in:
orbitcowboy 2022-05-11 11:30:02 +02:00
parent 942dbad11c
commit d0b7fe887a
1 changed files with 40 additions and 0 deletions

View File

@ -64,6 +64,7 @@ private:
TEST_CASE(checkComparisonOfFuncReturningBool5);
TEST_CASE(checkComparisonOfFuncReturningBool6);
TEST_CASE(checkComparisonOfFuncReturningBool7); // #7197
TEST_CASE(checkComparisonOfFuncReturningBool8); // #4103
// Integration tests..
TEST_CASE(checkComparisonOfFuncReturningBoolIntegrationTest1); // #7798 overloaded functions
@ -729,6 +730,45 @@ private:
errout.str());
}
void checkComparisonOfFuncReturningBool8() { // #4103
// op: >
check("int main(void){\n"
" bool a = true;\n"
" bool b = false;\n"
" if(b > a){ \n" // here warning should be displayed
" ;\n"
" }\n"
"}");
ASSERT_EQUALS("[test.cpp:4]: (style) Comparison of a variable having boolean value using relational (<, >, <= or >=) operator.\n", errout.str());
// op: <
check("int main(void){\n"
" bool a = true;\n"
" bool b = false;\n"
" if(b < a){ \n" // here warning should be displayed
" ;\n"
" }\n"
"}");
ASSERT_EQUALS("[test.cpp:4]: (style) Comparison of a variable having boolean value using relational (<, >, <= or >=) operator.\n", errout.str());
// op: >=
check("int main(void){\n"
" bool a = true;\n"
" bool b = false;\n"
" if(b >= a){ \n" // here warning should be displayed
" ;\n"
" }\n"
"}");
ASSERT_EQUALS("[test.cpp:4]: (style) Comparison of a variable having boolean value using relational (<, >, <= or >=) operator.\n", errout.str());
// op: <=
check("int main(void){\n"
" bool a = true;\n"
" bool b = false;\n"
" if(b <= a){ \n" // here warning should be displayed
" ;\n"
" }\n"
"}");
ASSERT_EQUALS("[test.cpp:4]: (style) Comparison of a variable having boolean value using relational (<, >, <= or >=) operator.\n", errout.str());
}
void checkComparisonOfFuncReturningBoolIntegrationTest1() { // #7798
check("bool eval(double *) { return false; }\n"
"double eval(char *) { return 1.0; }\n"