exceptions thrown when running app with failed unittests

Ervin Bosenbacher via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Mar 19 15:13:21 PDT 2017


Its my 2nd day into D, I am already in deep love (:D),  and I 
would like to understand whether this is normal behavior or 
something went terribly wrong, so all help is greatly appreciated.

Following the book of The D Programming language I have the code 
below:

bool binarySearch(T)(T[] input, T value) {
     while (!input.empty) {
         auto i = input.length / 2;
         auto mid = input[i];
         if (mid > value) input = input[0 .. i];
         else if (mid < value) input = input[i + 1 .. $];
         else return true;
     }
     return false;
}

@safe nothrow unittest {
     assert(binarySearch([ 1, 3, 6, 7, 9, 15 ], 6));
     assert(binarySearch([ 1, 3, 6, 7, 9, 15 ], 5));
}

void main() {

     bool s1 = binarySearch([1, 3, 6, 7, 9, 15], 6);
     bool s2 = binarySearch!(int)([1, 3, 6, 7, 9, 15], 5);
     writeln(s1, s2);
}

Then I compile using the command
$ dmd source/app.d -unittest

and execute as follows
$ ./app

Then the output
core.exception.AssertError at source/app.d(62): unittest failure
----------------
4   app                                 0x000000010b18d1d0 
_d_unittest + 152
5   app                                 0x000000010b183d1e void 
app.__unittest_fail(int) + 38
6   app                                 0x000000010b183df4 
nothrow @safe void app.__unittestL60_1() + 184
7   app                                 0x000000010b183ca0 void 
app.__modtest() + 8
8   app                                 0x000000010b18db54 int 
core.runtime.runModuleUnitTests().__foreachbody2(object.ModuleInfo*) + 44
9   app                                 0x000000010b186656 int 
object.ModuleInfo.opApply(scope int 
delegate(object.ModuleInfo*)).__lambda2(immutable(object.ModuleInfo*)) + 34
10  app                                 0x000000010b1a4471 int 
rt.minfo.moduleinfos_apply(scope int 
delegate(immutable(object.ModuleInfo*))).__foreachbody2(ref 
rt.sections_osx_x86_64.SectionGroup) + 85
11  app                                 0x000000010b1a43fc int 
rt.minfo.moduleinfos_apply(scope int 
delegate(immutable(object.ModuleInfo*))) + 32
12  app                                 0x000000010b18662d int 
object.ModuleInfo.opApply(scope int delegate(object.ModuleInfo*)) 
+ 33
13  app                                 0x000000010b18da3e 
runModuleUnitTests + 126
14  app                                 0x000000010b19e312 void 
rt.dmain2._d_run_main(int, char**, extern (C) int 
function(char[][])*).runAll() + 22
15  app                                 0x000000010b19e2ab void 
rt.dmain2._d_run_main(int, char**, extern (C) int 
function(char[][])*).tryExec(scope void delegate()) + 31
16  app                                 0x000000010b19e21e 
_d_run_main + 458
17  app                                 0x000000010b183d37 main + 
15
18  libdyld.dylib                       0x00007fff95f2d254 start 
+ 0
19  ???                                 0x0000000000000000 0x0 + 0


The compiles is
DMD64 D Compiler v2.073.1
Copyright (c) 1999-2016 by Digital Mars written by Walter Bright

and I am executing this on OSX 10.12


More information about the Digitalmars-d-learn mailing list