]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/testsuite/gdc.test/runnable/traits_getUnitTests.d
d: Import dmd b8384668f, druntime e6caaab9, phobos 5ab9ad256 (v2.098.0-beta.1)
[thirdparty/gcc.git] / gcc / testsuite / gdc.test / runnable / traits_getUnitTests.d
1 // REQUIRED_ARGS: -unittest
2 // EXTRA_SOURCES: imports/traits_getUnitTests_import.d
3 module traits_getUnitTests;
4
5 import imports.traits_getUnitTests_import;
6
7 template Tuple (T...)
8 {
9 alias Tuple = T;
10 }
11
12 int i;
13
14 unittest
15 {
16 i++;
17 }
18
19 void test_getUnitTestsFromModule ()
20 {
21 static assert(__traits(getUnitTests, mixin(__MODULE__)).length == 1);
22 }
23
24 struct SGetUnitTestsFromAggregate
25 {
26 unittest {}
27 }
28
29 class CGetUnitTestsFromAggregate
30 {
31 unittest {}
32 }
33
34 void test_getUnitTestsFromAggregate ()
35 {
36 static assert(__traits(getUnitTests, SGetUnitTestsFromAggregate).length == 1);
37 static assert(__traits(getUnitTests, CGetUnitTestsFromAggregate).length == 1);
38 }
39
40 void test_callUnitTestFunction ()
41 {
42 __traits(getUnitTests, mixin(__MODULE__))[0]();
43 assert(i == 2); // 2, because the standard unit test runner
44 // will call the unit test function as well
45 }
46
47 struct GetUnitTestsWithUDA
48 {
49 @("asd") unittest {}
50 }
51
52 void test_getUnitTestsWithUDA ()
53 {
54 alias tests = Tuple!(__traits(getUnitTests, GetUnitTestsWithUDA));
55 static assert(tests.length == 1);
56 static assert(__traits(getAttributes, tests[0]).length == 1);
57 }
58
59 void test_getUnitTestsFromImport ()
60 {
61 static assert(__traits(getUnitTests, imports.traits_getUnitTests_import).length == 1);
62 static assert(__traits(getUnitTests, mixin("imports.traits_getUnitTests_import")).length == 1);
63 }
64
65 // https://issues.dlang.org/show_bug.cgi?id=11358
66 debug { }
67 enum len11358 = __traits(getUnitTests, mixin(__MODULE__)).length;
68
69 void main ()
70 {
71 test_getUnitTestsFromModule();
72 test_getUnitTestsFromAggregate();
73 test_callUnitTestFunction();
74 test_getUnitTestsWithUDA();
75 test_getUnitTestsFromImport();
76 }