There must be module with test assertions in Phobos

Dmytro Katyukha firemage.dima at gmail.com
Thu Mar 30 19:53:42 UTC 2023


On Thursday, 30 March 2023 at 17:22:39 UTC, Petar Kirov 
[ZombineDev] wrote:
> On Thursday, 30 March 2023 at 17:01:26 UTC, Dmytro Katyukha 
> wrote:
>> Hi all,
>> [..]
>
> Hi! Are you aware of the `-checkaction=context` compiler flag? 
> Give it a shot:
>
> ```d
> unittest {
>     int x = 0, y = 5;
>     assert(x == y);
> }
> ```
> ```sh
> dmd -main -unittest -checkaction=context -run ./example.d
> ```
>
> ```
> onlineapp.d(3): [unittest] 0 != 5
> 1/1 modules FAILED unittests
> ```
>
> Test on [run.dlang.io][0].
>
> This is not an argument against a dedicated assertion module, 
> but I think it's good to be aware what can be achieved at the 
> compiler/runtime level vs library level.
>
> [0]: 
> https://run.dlang.io/?compiler=dmd&source=unittest%20%7B%0A%20%20%20%20int%20x%20%3D%200,%20y%20%3D%205;%0A%20%20%20%20assert(x%20%3D%3D%20y);%0A%7D%0A&args=-unittest%20-checkaction%3Dcontext%20-main

Thanks for information, i was not aware about this compiler 
switch.

Also, i would like to note that, there is no info about this 
compiler switch in [unittests 
documentation](https://dlang.org/spec/unittest.html)


More information about the Digitalmars-d mailing list