Coding 2022-12-05

Tags:
By Max Woerner Chase

I added a small amount of code coverage today, and it immediately revealed a bug that had eluded all other checks. This has happened a bunch before. Whenever I write tests for some squirrelly bit of code, it seems to always turn out it was accidentally making bad type assumptions, or has a critical bit of logic inverted, or whatever.

I've read stuff online talking about how full code coverage isn't valuable, but I'd really rather exercise these weird code paths before I ship something. Maybe other people can write this kind of code with no bugs. If so, good for them, and when they're working on their code bases, they're free to apply standards to their work that match up with that track record. For my hobby projects, I'll be applying standards that apply to my track record with these hobby projects, and that means 100% coverage as table stakes.

Now, as it turns out, the test I wrote, that one that found the bug that I had to fix, is actually kind of on the weak side of things, and I'm going to need to extend things in several ways, some of which will increase coverage, and some of which won't, at least outside of the sense of "tests should have 100% coverage, so adding a new test should move the coverage percentage closer to 100%".

I may prioritize the latter, just because it'll make existing and new tests much stronger.

Actually, that's a good thing for me to consider while I work on the tests: should it always be the case that a valid ParametricCommand's build() method should produce a Parametric that, when passed all required (and possibly some additional, unnecessary) data to its facts() method, produces a Facts that, when passed to api.build(), produces a Compendium without erroring on any step? I think that's a reasonable correctness criterion, so, either later tonight, or sometime next week, I'll see about writing a helper to handle that.

The helper would have to do stuff like validate that all necessary data is passed, because right now, the code doesn't really establish that. (It would also need to precompute some of the facts to actually get that far, but, um, oh well.)

Anyway, I'm going to wrap this up and post it a little early, so I can relax later tonight.

Good night.