digitalmars.dip.ideas - setuptime
- monkyyy (25/25) May 10 Unittests can have side effects, most yall will say this is a bug
- Paul Backus (2/12) May 11 We have this already; it's called `static this`.
- Walter Bright (2/3) May 22 Yes, that should do it.
Unittests can have side effects, most yall will say this is a bug to use but every once in a while Im tempted. It would mean requiring a user to pass a flag tho and you now are dependent on unit tests passing all the time. Unit tests could be duplicated under another keyword or colored. ```d File myconfig; int getconfigdetail(){ assert(myconfig.isopen); return 3; } void main(){ int detail=getconfigdetail(); } setuptime{//unittest{ myconfig=File(myconfig); } unittest{ assert(1==0); } ``` In the above code the myconfig file would be properly opened at "unittest time" without passing the -unittest flag and then getting a failing program from the bad unit test. Eliminating the trade offs, and unclear use of the feature.
May 10
On Saturday, 10 May 2025 at 17:22:09 UTC, monkyyy wrote:Unittests can have side effects, most yall will say this is a bug to use but every once in a while Im tempted. It would mean requiring a user to pass a flag tho and you now are dependent on unit tests passing all the time. Unit tests could be duplicated under another keyword or colored. [...] In the above code the myconfig file would be properly opened at "unittest time" without passing the -unittest flag and then getting a failing program from the bad unit test. Eliminating the trade offs, and unclear use of the feature.We have this already; it's called `static this`.
May 11
On 5/11/2025 2:38 AM, Paul Backus wrote:We have this already; it's called `static this`.Yes, that should do it.
May 22