www.digitalmars.com         C & C++   DMDScript  

digitalmars.dip.ideas - setuptime

reply monkyyy <crazymonkyyy gmail.com> writes:
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
parent reply Paul Backus <snarwin gmail.com> writes:
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
parent Walter Bright <newshound2 digitalmars.com> writes:
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