Why this fails when using unittest?

Machine Code jckj33 at gmail.com
Fri Jun 7 16:33:13 UTC 2019


On Friday, 7 June 2019 at 16:30:34 UTC, Machine Code wrote:
> On Thursday, 6 June 2019 at 21:02:37 UTC, Steven Schveighoffer 
> wrote:
>> [...]
>
> Intesting, I also tried to declare it inside a function, that 
> did not work either. Is this hidden context pointer a current 
> limitation in CTFE? I've tried to declare the struct at module 
> level and run the functions on static this() to workaround that 
> but to finish, I'd like to eble to run the code in static 
> main() only when unnitest is enabled but so I haven't manged to 
> do that.
>
> *Imaginary code* would be:
>
> unittest
> {
> 	enum enabled = true;
> }
> else
> {
>     enum enabled = true;
> }
>
> but I was on my mind unittest was similar to static if() but as 
> it's like a function, there are no else let alone acess to enum 
> enabled as true, outside the block but the idea is run (or even 
> only declare) a piece of code (which includes that struct) only 
> if we are an unittest.

All this effort is because I do not want unittest code in a 
release or even debug. So I want to this be invisible anywhere 
but unittest or at least simulate that wit static if() how I'm 
tring to do


More information about the Digitalmars-d-learn mailing list