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