Thread overview
what the closest thing we have to racket's check_expect()?
Dec 22, 2021
Dr Machine Code
Dec 22, 2021
Rumbu
Dec 23, 2021
WebFreak001
December 22, 2021

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?

December 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

December 23, 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

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