1 module tests.pass.attributes;
2 
3 import unit_threaded;
4 
5 enum myEnumNum = "foo.bar"; //there was a bug that made this not compile
6 enum myOtherEnumNum;
7 
8 @Tags("tagged")
9 @UnitTest
10 void funcAttributes() {
11     //tests that using the @UnitTest UDA adds this function
12     //to the list of tests despite its name
13     1.shouldEqual(1);
14 }
15 
16 //won't be tested due to attribute
17 @DontTest
18 void testThatWontRun() {
19     1.shouldEqual(2); //doesn't matter, won't run anyway
20 }
21 
22 @DontTest
23 class TestThatWontRun: TestCase {
24     override void test() {
25         null.shouldNotBeNull; //doesn't matter, won't run anyway
26     }
27 }
28 
29 @HiddenTest("Bug id #54321")
30 class MyHiddenTest: TestCase {
31     override void test() {
32         null.shouldNotBeNull; //hidden by default, fails if explicitly run
33     }
34 }
35 
36 @HiddenTest
37 void testHidden() {
38     null.shouldNotBeNull; //hidden by default, fails if explicitly run
39 }
40 
41 
42 @ShouldFail("Bug id 12345")
43 void testShouldFail() {
44     3.shouldEqual(4);
45 }
46 
47 
48 @ShouldFail("Bug id 12345")
49 void testShouldFailWithOtherException() {
50     throw new Exception("This should not be seen");
51 }
52 
53 @Tags("tagged")
54 @Name("first_unit_test")
55 unittest {
56     writelnUt("First unit test block\n");
57     assert(true); //unit test block that always passes
58 }
59 
60 
61 @Name("second_unit_test")
62 unittest {
63     writelnUt("Second unit test block\n");
64     assert(true); //unit test block that always passes
65 }
66 
67 @Tags(["untagged", "unhinged"])
68 @("third_unit_test")
69 unittest {
70     3.shouldEqual(3);
71 }
72 
73 @ShouldFail
74 unittest {
75     3.shouldEqual(5);
76 }
77 
78 @Tags("other", "more")
79 @(42, 2)
80 void testValues(int i) {
81     (i % 2 == 0).shouldBeTrue;
82 }
83 
84 
85 @ShouldFail
86 void testShouldFailWithAssertionInTestFunction() {
87      assert(false);
88 }
89 
90 @ShouldFail
91 @(12, 14)
92 void testIssue14(int i) {
93     (i % 2 == 0).shouldBeFalse;
94 }
95 
96 @Types!(int, byte)
97 void testTemplate(T)() {
98     T.init.shouldEqual(0);
99 }
100 
101 @("Built-in with values")
102 @Values("red", "goo")
103 unittest {
104     getValue!string.length.shouldEqual(3);
105 }