@@ -21,4 +21,60 @@ Working through each exercise is a process of:
21
21
* Note:* D has support for unit testing direct in the language so usually the unit tests reside in the same file as the implementation.
22
22
The unittests are run before the body of main and are enabled in the final executable by using the ** -unittest** compiler switch.
23
23
24
- @TODO add IDE related instructions.
24
+ ## Interpreting unit test output
25
+
26
+ If all the tests succeed, the test output might look like this
27
+
28
+ ``` none
29
+ $ dub test
30
+ Generating test runner configuration 'dnd-character-test-library' for 'library' (library).
31
+ Starting Performing "unittest" build using dmd for x86_64.
32
+ Building dnd-character ~master: building configuration [dnd-character-test-library]
33
+ Linking dnd-character-test-library
34
+ Running dnd-character-test-library
35
+ 1 modules passed unittests
36
+ ```
37
+
38
+ The test output can be difficult to read when there are test failures.
39
+
40
+ ``` none
41
+ $ dub test
42
+ Generating test runner configuration 'dnd-character-test-library' for 'library' (library).
43
+ Starting Performing "unittest" build using dmd for x86_64.
44
+ Building dnd-character ~master: building configuration [dnd-character-test-library]
45
+ Linking dnd-character-test-library
46
+ Running dnd-character-test-library
47
+ core.exception.AssertError@source/dnd_character.d(102): unittest failure
48
+ ----------------
49
+ ??:? _d_unittestp [0x5568ff91bf05]
50
+ source/dnd_character.d:102 void dnd_character.__unittest_L30_C1() [0x5568ff911fee]
51
+ ??:? void dnd_character.__modtest() [0x5568ff913760]
52
+ ??:? int core.runtime.runModuleUnitTests().__foreachbody6(object.ModuleInfo*) [0x5568ff928f82]
53
+ ??:? int object.ModuleInfo.opApply(scope int delegate(object.ModuleInfo*)).__lambda2(immutable(object.ModuleInfo*)) [0x5568ff9148f7]
54
+ ??:? int rt.minfo.moduleinfos_apply(scope int delegate(immutable(object.ModuleInfo*))).__foreachbody2(ref rt.sections_elf_shared.DSO) [0x5568ff92003f]
55
+ ??:? int rt.sections_elf_shared.DSO.opApply(scope int delegate(ref rt.sections_elf_shared.DSO)) [0x5568ff9200d1]
56
+ ??:? int rt.minfo.moduleinfos_apply(scope int delegate(immutable(object.ModuleInfo*))) [0x5568ff91ffcd]
57
+ ??:? int object.ModuleInfo.opApply(scope int delegate(object.ModuleInfo*)) [0x5568ff9148c9]
58
+ ??:? runModuleUnitTests [0x5568ff928db7]
59
+ ??:? void rt.dmain2._d_run_main2(char[][], ulong, extern (C) int function(char[][])*).runAll() [0x5568ff91d248]
60
+ ??:? void rt.dmain2._d_run_main2(char[][], ulong, extern (C) int function(char[][])*).tryExec(scope void delegate()) [0x5568ff91d1d5]
61
+ ??:? _d_run_main2 [0x5568ff91d13e]
62
+ ??:? _d_run_main [0x5568ff91cf27]
63
+ /usr/include/dmd/druntime/import/core/internal/entrypoint.d:29 main [0x5568ff90f8f1]
64
+ ??:? [0x7f473154a249]
65
+ ??:? __libc_start_main [0x7f473154a304]
66
+ ??:? _start [0x5568ff90f7e0]
67
+ 1/1 modules FAILED unittests
68
+ Error Program exited with code 1
69
+ ```
70
+
71
+ There's a lot of detailed stacktrace there, but the important line is the one above ` ---------------- `
72
+
73
+ ``` none
74
+ core.exception.AssertError@source/dnd_character.d(102): unittest failure
75
+ ```
76
+
77
+ That line tells you that the failing assertion is on ** line 102** of file ** dnd_character.d** .
78
+ You can use that to pinpoint the test that is not meeting expectations.
79
+
80
+ <!-- @TODO add IDE related instructions. -->
0 commit comments