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 @Name("second_unit_test")
61 unittest {
62     writelnUt("Second unit test block\n");
63     assert(true); //unit test block that always passes
64 }
65 
66 @Tags(["untagged", "unhinged"])
67 @("third_unit_test")
68 unittest {
69     3.shouldEqual(3);
70 }
71 
72 @ShouldFail
73 unittest {
74     3.shouldEqual(5);
75 }
76 
77 
78 @(42, 2)
79 void testValues(int i) {
80     (i % 2 == 0).shouldBeTrue;
81 }
82 
83 
84 @ShouldFail
85 void testShouldFailWithAssertionInTestFunction() {
86      assert(false);
87 }
88 
89 @ShouldFail
90 @(12, 14)
91 void testIssue14(int i) {
92     (i % 2 == 0).shouldBeFalse;
93 }
94 
95 @Types!(int, byte)
96 void testTemplate(T)() {
97     T.init.shouldEqual(0);
98 }
99 
100 @("Built-in with values")
101 @Values("foo", "bar")
102 unittest {
103     getValue!string.length.shouldEqual(3);
104 }