Repository navigation
Take coverage to 100%, fixing a real gap on the way - #13
Merged
Merged
Conversation
Dates and measures were read with parseInt and parseFloat inside a try which could never fire, because neither throws on rubbish - they return NaN. So a barcode carrying letters where it should carry digits came back as a successful parse holding an Invalid Date or a null weight, and every caller had to notice that for itself. The parse now looks at the number rather than merely reading it, which is what those catch blocks were meant to do all along, and what makes error codes 33 to 36 reachable at last. The far half of the sliding year window is reached by moving the clock. It needs a two digit year fifty behind the current one, which cannot be written in two digits before 2050, so no fixed date would ever have exercised it. That leaves two guards which cannot be reached by construction: the default arm of the element type switch, and the default arm of the message switch. Both are worth keeping, so they are held out of the figure with c8 ignore and a comment saying why, rather than deleted to flatter it. Thresholds are set at 100. Verified they bite: removing the new spec file drops the run to 99.36% and fails.
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Yes — 100% of statements, branches, functions and lines. Getting there turned up a real bug rather than just moving a number.
The bug
Dates and measures are read with
parseIntandparseFloat, each wrapped in atry. Neither function throws on rubbish; they returnNaN. So thecatchblocks could never fire, and a barcode carrying letters where it should carry digits came back as a successful parse:Invalid Dateis stillinstanceof Date, so a caller checking the type sees nothing wrong and only finds out downstream.The parse now looks at the number rather than merely reading it — which is what those
catchblocks were written to do — and refuses withinvalid year in date,invalid month in date,invalid day in dateorinvalid number. That also makes error codes 33 to 36 reachable for the first time, which is most of what was missing from the coverage figure.Valid input is untouched, including the day-of-
00reading that turns a date into the last day of its month.The sliding window
The half of the year window that reads a year as belonging to the century ahead needs a two digit year at least fifty behind the current one. That cannot be written in two digits before 2050, so no fixed date would ever have exercised it. It is reached by moving the clock with
jasmine.clock().mockDate()instead.The same specs now pin both edges deterministically rather than depending on what year it happens to be, while the "as the clock stands today" block still checks the window really does move.
The two that stay uncovered
Two guards cannot be reached by construction:
defaultarm of the element type switch — every construction in the file passesS,NorD;defaultarm of the message switch — every code the parser throws has an arm of its own.Both are worth keeping. They are held out of the figure with
/* c8 ignore */and a comment saying why, rather than deleted to flatter the number.Thresholds
Set at 100. Verified they bite rather than decorate: removing the new spec file drops the run to 99.36% statements and 98.04% branches, and the build fails.
313 specs, 0 failures.