Debian Codegraph @

gcc/testsuite/gdc.test/runnable/issue16995.d

raw
1 // REQUIRED_ARGS: -unittest
2 // COMPILE_SEPARATELY:
3 // EXTRA_SOURCES: imports/module_with_tests.d imports/another_module_with_tests.d
4
5 import imports.module_with_tests;
6 import imports.another_module_with_tests;
7 import core.exception: AssertError;
8
9 shared static this()
10 {
11 import core.runtime: Runtime, UnitTestResult;
12 Runtime.extendedModuleUnitTester = () => UnitTestResult.pass;
13 }
14
15 void main()
16 {
17 foreach(i, ut; __traits(getUnitTests, imports.module_with_tests))
18 {
19 try
20 {
21 ut();
22 assert(i == 0, "2nd unittest should fail");
23 }
24 catch(AssertError e)
25 {
26 assert(i == 1, "Only 2nd unittest should fail");
27 }
28 }
29
30 foreach(i, ut; __traits(getUnitTests, imports.another_module_with_tests))
31 {
32 try
33 {
34 ut();
35 assert(i == 0 || i == 1, "3rd unittest should fail");
36 }
37 catch(AssertError e)
38 {
39 assert(i == 2, "Only 3rd unittest should fail");
40 }
41 }
42 }