what the closest thing we have to racket's check_expect()?
WebFreak001
d.forum at webfreak.org
Thu Dec 23 07:02:16 UTC 2021
On Wednesday, 22 December 2021 at 20:14:01 UTC, Dr Machine Code
wrote:
> it differ from assert because it contains the expression, file
> and line information. See this
> https://stackoverflow.com/questions/14420857/check-expect-example-in-racket
> what's the closest thing we have in D? can we make it without
> compiler builtin?
if you just want to use an assert, the compiler flag
`-checkaction=context` basically gives you this kind of error
messages.
Example how to use in DUB (from serve-d):
https://github.com/Pure-D/serve-d/blob/84094fade433f3d52e43c5296d20af53b102ffdd/dub.json
```d
void main()
{
assert(1 + 1 == 2);
assert(1 + 1 == 1);
}
__EOF__
Sample output:
core.exception.AssertError at onlineapp.d(4): 2 != 1
----------------
??:? _d_assert_msg [0x563912072788]
./onlineapp.d:4 _Dmain [0x563912069f54]
```
[Run Online](https://run.dlang.io/is/X1bevb)
More information about the Digitalmars-d-learn
mailing list