by pornel · 7y ago · 0 comments
if(X) {}
else {}
if(Y) {}
else {}
"normal test coverage" is weaker than SQLite tests with the following lines added: testcase(X && Y);
testcase(X && !Y);
testcase(!X && Y);
testcase(!X && !Y);
I wasn't sure when reading the article, to be honest, but making sure you test things you don't explicitly branch on is kinda cool. # define testcase(X) if( X ){ sqlite3Coverage(__LINE__); }
If the testcase(condition) always evaluates to true, the code coverage analyzer would complain that the if ( X ) {sqlite3...} statement never evaluates to false and the branch coverage drops below 100%, the converse holds conversely if it was never evaluated to true in the first place.
Only if the code using the testcase macro gets repeatedly called in a way so that the testcase macro evaluates sometimes to true and sometimes to false, the coverage stays at 100%.sqlite3Coverage() does some dummy work so that the call will not be optimized away by the compiler.