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