1 module unit_threaded.attrs; 2 3 enum UnitTest; //opt-in to registration 4 enum DontTest; //opt-out of registration 5 enum Serial; //run tests in the module in one thread / serially 6 7 alias SingleThreaded = Serial; 8 9 ///Hide test. Not run by default but can be run. 10 struct HiddenTest { 11 string reason; 12 } 13 14 /// The suite fails if the test passes. 15 struct ShouldFail { 16 string reason; 17 } 18 19 /// Associate a name with a unittest block. 20 struct Name { 21 string value; 22 } 23 24 /// Associates one or more tags with the test 25 struct Tags { 26 this(string[] values) { this.values = values; } 27 this(string value) { this.values = [value]; } 28 string[] values; 29 } 30 31 /** Automatically assign @Tags for each parameterized test 32 e.g. 33 --------------- 34 @Values("foo", "bar) @AutoTags unittest { ... } 35 // there are now two unit tests, one for "foo" with tag "foo" 36 // and one for "bar" with tag "bar" 37 --------------- 38 */ 39 enum AutoTags; 40 41 /** Attachs these types to the a parametrized unit test. 42 The attached template function will be instantiated with 43 each type listed, e.g. 44 45 ---------------- 46 @Types!(int, byte) void testInit(T)() { T.init.shouldEqual(0); } 47 ---------------- 48 49 These would mean two testInit test runs. 50 51 Normally this would be a template but I don't know how to write 52 * the UDA code to filter a template out 53 */ 54 struct Types(T...) {} 55 56 57 /** 58 Used as a UDA for built-in unittests to enable value-parametrized tests. 59 Example: 60 ------- 61 @Values(1, 2, 3) unittest { assert(getValue!int % 2 == 0); } 62 ------- 63 The example above results in unit_threaded running the unit tests 3 times, 64 once for each value declared. 65 66 See `getValue`. 67 */ 68 ValuesImpl!T Values(T)(T[] values...) { 69 return ValuesImpl!T(values.dup); 70 } 71 72 struct ValuesImpl(T) { 73 T[] values; 74 } 75 76 /** 77 Retrieves the current test value of type T in a built-in unittest. 78 See `Values`. 79 */ 80 T getValue(T)() { 81 return ValueHolder!T.value; 82 } 83 84 package struct ValueHolder(T) { 85 static T value; 86 }