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 /** Attachs these types to the a parametrized unit test.
25     The attached template function will be instantiated with
26     each type listed, e.g.
27 
28     ----------------
29     @Types!(int, byte) void testInit(T)() { T.init.shouldEqual(0); }
30     ----------------
31 
32     These would mean two testInit test runs.
33 
34     Normally this would be a template but I don't know how to write
35  *  the UDA code to filter a template out
36  */
37 struct Types(T...) {}
38 
39 
40 /**
41  Used as a UDA for built-in unittests to enable value-parametrized tests.
42  Example:
43  -------
44  @Values(1, 2, 3) unittest { assert(getValue!int % 2 == 0); }
45  -------
46  The example above results in unit_threaded running the unit tests 3 times,
47  once for each value declared.
48 
49  See `getValue`.
50  */
51 ValuesImpl!T Values(T)(T[] values...) {
52     return ValuesImpl!T(values.dup);
53 }
54 
55 struct ValuesImpl(T) {
56     T[] values;
57 }
58 
59 /**
60  Retrieves the current test value of type T in a built-in unittest.
61  See `Values`.
62  */
63 T getValue(T)() {
64     return ValueHolder!T.value;
65 }
66 
67 package struct ValueHolder(T) {
68     static T value;
69 }