Postmortem: Template unittests are bad & you shouldn't catch Error
Mathias LANG
geod24 at gmail.com
Fri Oct 23 14:19:20 UTC 2020
On Friday, 23 October 2020 at 09:03:43 UTC, Jacob Carlborg wrote:
>
> It's not that simple, you need to read the whole spec ;). The
> spec for unit tests has an exception:
>
> "Individual tests are specified in the unit test using
> AssertExpressions. Unlike AssertExpressions used elsewhere, the
> assert is not assumed to hold, and upon assert failure the
> program is still in a defined state." [1].
>
> Although, it's not clear if that only applies to `assert`
> directly in the `unittest` block or any assert reachable
> through the `unittest` block.
I'm aware of this, and I think the spec is pretty clear. "Unlike
`AssertExpression` used elsewhere" means that this only applies
to `assert` inside unittest, not those transitively reachable.
Note that a compiler could one day decide to rewrite those to
exceptions to be more consistent with the specs.
> Regardless of what's correct or not, I think there must be a
> way to have unit tests keep running after a failed test.
> Otherwise D will have very poor experience for unit test
> frameworks. It's already bad enough with the default unit test
> runner that aborts the rest of the unit tests inside a module
> after a failed test (it will continue with other modules).
>
> [1] https://dlang.org/spec/unittest.html
>
> --
> /Jacob Carlborg
A compiler rewrite would do that.
More information about the Digitalmars-d
mailing list