Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Code coverage not reported correctly for CTEs at the end of a stored procedure if the 'with' is immediately preceded with a semicolon #8
If a CTE is preceded by a semicolon e.g.
;with MyCTE as
and it is the last statement in a batch, the executed statement is matched against the immediately preceding statement instead. This is because the Overlaps function matches the preceding statement first due to the way that the coveredEnd variable is assigned the same value as the coveredOffset.
(This technically applies to other statements preceded with a semicolon, but it's unusual to see those).
I believe that the logic should change to treat those where coveredStatement.OffsetEnd is -1 (i.e. last statement) separate from others, and return true where the coveredOffset is equal or less than the tested statement's offset.
For other covered statements, the logic can now be simplified as we're no longer having to cope with both cases.
I've developed and tested a fix locally on my fork and will submit a pull request shortly.