digitalmars.D.learn - what the closest thing we have to racket's check_expect()?
- Dr Machine Code (5/5) Dec 22 2021 it differ from assert because it contains the expression, file
- Rumbu (7/12) Dec 22 2021 Every error or exception in D has line and file information,
- WebFreak001 (21/26) Dec 22 2021 if you just want to use an assert, the compiler flag
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?
Dec 22 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?Every error or exception in D has line and file information, stack trace and more, therefore you can catch AssertError and print the details if the default message printed on console is not enough. For unit testing you have https://code.dlang.org/packages/dunit
Dec 22 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 onlineapp.d(4): 2 != 1 ---------------- ??:? _d_assert_msg [0x563912072788] ./onlineapp.d:4 _Dmain [0x563912069f54] ``` [Run Online](https://run.dlang.io/is/X1bevb)
Dec 22 2021