Bug 24467 – Allow unittest functions to support expressions only

Status
NEW
Severity
enhancement
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2024-03-29T12:29:19Z
Last change time
2024-12-13T19:34:19Z
Assigned to
No Owner
Creator
Richard (Rikki) Andrew Cattermole
Moved to GitHub: dmd#20431 →

Comments

Comment #0 by alphaglosined — 2024-03-29T12:29:19Z
According to Nicholas Wilson unittests are functions. https://forum.dlang.org/post/[email protected] They should support expression syntax that all functions support. ``unittest() => assert(1==1);``
Comment #1 by issues.dlang — 2024-03-29T12:47:46Z
They do not have the same syntax as functions. You can't declare something like --- foo { } --- It's missing both a return type and parens. On the other hand, that's exactly what you do with unittest blocks --- unittest { } --- If a unittest declaration were a function declaration, then it would look something like --- void unittest() { } --- which is illegal, because unittest declarations can't have return types or parens. So, as far as declarations go, they're not function declarations. They're unittest declarations. They get implemented as functions underneath the hood, but their syntax is not the same, and as such, it makes no sense to support something like --- unittest() => assert(1 == 1); --- simply because you can do that with a function. I don't see how it can even be argued that the lambda syntax should be allowed for unittest declarations based on the fact that functions have it, because unittest declarations and function declarations do not share the same syntax. The only thing that's really the same is how their bodies work. In addition, it's incredibly bad practice to write unittest blocks that contain only a single assertion. That's garbage test coverage and is the sort of thing that only makes sense in toy examples. As such, it makes no sense to add a shorter syntax that would encourage folks to write such terrible tests.
Comment #2 by robert.schadek — 2024-12-13T19:34:19Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/20431 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB