www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Better unittest failure output

reply "Bahman Movaqar" <b.movaqar gmail.com> writes:
I am working on a simple project created with DUB[1].
When unit tests the output reads really cryptic to me; for 
example:

     $ dub test
     Generating test runner configuration '__test__library__' for 
'library' (library).
     Target dunit 1.0.11 is up to date. Use --force to rebuild.
     Building d-etudes ~master configuration "__test__library__", 
build type unittest.
     Compiling using dmd...
     Linking...
     Running ./__test__library__
     core.exception.AssertError source/e002.d(111): unittest 
failure
     ----------------
     ./__test__library__(void 
detudes.e002.__unittest_fail(int)+0x28) [0x4bf508]
     ./__test__library__(void 
detudes.e002.__unittestL106_4()+0x17b) [0x4bf47b]
     ./__test__library__(void detudes.e002.__modtest()+0xe) 
[0x4bf48e]
     ./__test__library__(int 
core.runtime.runModuleUnitTests().__foreachbody2(object.ModuleInfo*)+0x34)
[0x4d0d0c]
     ./__test__library__(int object.ModuleInfo.opApply(scope int 
delegate(object.ModuleInfo*)).__lambda2(immutable(object.ModuleInfo*))+0x1c)
[0x4c1ab4]
     ./__test__library__(int rt.minfo.moduleinfos_apply(scope int 
delegate(immutable(object.ModuleInfo*))).__foreachbody2(ref 
rt.sections_elf_shared.DSO)+0x46) [0x4c7422]
     ./__test__library__(int 
rt.sections_elf_shared.DSO.opApply(scope int delegate(ref 
rt.sections_elf_shared.DSO))+0x41) [0x4c7499]
     ./__test__library__(int rt.minfo.moduleinfos_apply(scope int 
delegate(immutable(object.ModuleInfo*)))+0x20) [0x4c73bc]
     ./__test__library__(int object.ModuleInfo.opApply(scope int 
delegate(object.ModuleInfo*))+0x20) [0x4c1a90]
     ./__test__library__(runModuleUnitTests+0x98) [0x4d0bd8]
     ./__test__library__(void rt.dmain2._d_run_main(int, char**, 
extern (C) int function(char[][])*).runAll()+0x17) [0x4c4147]
     ./__test__library__(void rt.dmain2._d_run_main(int, char**, 
extern (C) int function(char[][])*).tryExec(scope void 
delegate())+0x2a) [0x4c40fa]
     ./__test__library__(_d_run_main+0x1d2) [0x4c407a]
     ./__test__library__(main+0x20) [0x48a968]
     /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf5) 
[0x7f1f751d9ec5]
     Error executing command test:
     Program exited with code 1

It is almost impossible for me to comprehend anything useful out 
of this, except that, well, the tests have failed :-)

Is there any compiler switch, argument to `assert` or trick to 
make `unittest` output more helpful messages when failing?

[1] https://github.com/bahmanm/d-etudes
Sep 07 2015
next sibling parent reply anonymous <anonymous example.com> writes:
On Monday 07 September 2015 13:57, Bahman Movaqar wrote:

 I am working on a simple project created with DUB[1].
 When unit tests the output reads really cryptic to me; for 
 example:
 
      $ dub test
[...]
      core.exception.AssertError source/e002.d(111): unittest 
 failure
[...]
 
 It is almost impossible for me to comprehend anything useful out 
 of this, except that, well, the tests have failed :-)
From that one line I left intact above, you should also be able to figure out that it's the test in source/e002.d, line 111 that failed.
 Is there any compiler switch, argument to `assert` or trick to 
 make `unittest` output more helpful messages when failing?
You can pass a custom message as a second argument to assert: assert(condition, "message goes here"); I think there are testing libraries/frameworks around that mean to provide more than the basic built-in things. But I haven't tried any, so I can't recommend anything. Try searching for "test" here: http://code.dlang.org/
Sep 07 2015
parent reply "Bahman Movaqar" <b.movaqar gmail.com> writes:
On Monday, 7 September 2015 at 12:06:09 UTC, anonymous wrote:
 On Monday 07 September 2015 13:57, Bahman Movaqar wrote:
      $ dub test
[...]
      core.exception.AssertError source/e002.d(111): unittest
 failure
[...] From that one line I left intact above, you should also be able to figure out that it's the test in source/e002.d, line 111 that failed.
True. That I had already figured out. I was actually hoping for something like Groovy's assert messages[1], if possible.
 Is there any compiler switch, argument to `assert` or trick to 
 make `unittest` output more helpful messages when failing?
You can pass a custom message as a second argument to assert: assert(condition, "message goes here");
Thanks. This is indeed helpful. OT but where can I view the documentation for `unittest` and `assert`? [1]
Sep 07 2015
parent reply anonymous <anonymous example.com> writes:
On Monday 07 September 2015 14:12, Bahman Movaqar wrote:

 Thanks.  This is indeed helpful.  OT but where can I view the 
 documentation for `unittest` and `assert`?
unittest: http://dlang.org/unittest.html assert: http://dlang.org/expression.html#AssertExpression (I don't know why it's considered an expression and not a statement.)
Sep 07 2015
next sibling parent "Bahman Movaqar" <b.movaqar gmail.com> writes:
On Monday, 7 September 2015 at 12:16:14 UTC, anonymous wrote:
 On Monday 07 September 2015 14:12, Bahman Movaqar wrote:

 Thanks.  This is indeed helpful.  OT but where can I view the 
 documentation for `unittest` and `assert`?
unittest: http://dlang.org/unittest.html assert: http://dlang.org/expression.html#AssertExpression (I don't know why it's considered an expression and not a statement.)
Thanks.
Sep 07 2015
prev sibling parent "Kagamin" <spam here.lot> writes:
On Monday, 7 September 2015 at 12:16:14 UTC, anonymous wrote:
 On Monday 07 September 2015 14:12, Bahman Movaqar wrote:

 Thanks.  This is indeed helpful.  OT but where can I view the 
 documentation for `unittest` and `assert`?
unittest: http://dlang.org/unittest.html assert: http://dlang.org/expression.html#AssertExpression (I don't know why it's considered an expression and not a statement.)
int main() { int a = 1; a || assert(false); return 0; }
Sep 07 2015
prev sibling parent reply "Gary Willoughby" <dev nomad.so> writes:
On Monday, 7 September 2015 at 11:57:25 UTC, Bahman Movaqar wrote:
 I am working on a simple project created with DUB[1].
 When unit tests the output reads really cryptic to me; for 
 example:
Try using DUnit, it gives you much more readable fail messages: https://github.com/nomad-software/dunit
Sep 07 2015
parent "Gary Willoughby" <dev nomad.so> writes:
On Monday, 7 September 2015 at 12:58:58 UTC, Gary Willoughby 
wrote:
 On Monday, 7 September 2015 at 11:57:25 UTC, Bahman Movaqar 
 wrote:
 I am working on a simple project created with DUB[1].
 When unit tests the output reads really cryptic to me; for 
 example:
Try using DUnit, it gives you much more readable fail messages: https://github.com/nomad-software/dunit
It's in the dub repository too: http://code.dlang.org/packages/dunit
Sep 07 2015