1 module unit_threaded.ut.factory;
2 
3 
4 import unit_threaded.runner.factory;
5 
6 
7 unittest {
8     import unit_threaded.runner.reflection: TestData;
9     //existing, wanted
10     assert(isWantedTest(TestData("", "tests.server.testSubscribe"), ["tests"]));
11     assert(isWantedTest(TestData("", "tests.server.testSubscribe"), ["tests."]));
12     assert(isWantedTest(TestData("", "tests.server.testSubscribe"), ["tests.server.testSubscribe"]));
13     assert(!isWantedTest(TestData("", "tests.server.testSubscribe"), ["tests.server.testSubscribeWithMessage"]));
14     assert(!isWantedTest(TestData("", "tests.stream.testMqttInTwoPackets"), ["tests.server"]));
15     assert(isWantedTest(TestData("", "tests.server.testSubscribe"), ["tests.server"]));
16     assert(isWantedTest(TestData("", "pass_tests.testEqual"), ["pass_tests"]));
17     assert(isWantedTest(TestData("", "pass_tests.testEqual"), ["pass_tests.testEqual"]));
18     assert(isWantedTest(TestData("", "pass_tests.testEqual"), []));
19     assert(!isWantedTest(TestData("", "pass_tests.testEqual"), ["pass_tests.foo"]));
20     assert(!isWantedTest(TestData("", "example.tests.pass.normal.unittest"),
21                          ["example.tests.pass.io.TestFoo"]));
22     assert(isWantedTest(TestData("", "example.tests.pass.normal.unittest"), []));
23     assert(!isWantedTest(TestData("", "tests.pass.attributes.testHidden", null, true /*hidden*/), ["tests.pass"]));
24     assert(!isWantedTest(TestData("", "", null, false /*hidden*/, false /*shouldFail*/, false /*singleThreaded*/,
25                                   false /*builtin*/, "" /*suffix*/),
26                          ["@foo"]));
27     assert(isWantedTest(TestData("", "", null, false /*hidden*/, false /*shouldFail*/, false /*singleThreaded*/,
28                                  false /*builtin*/, "" /*suffix*/, ["foo"]),
29                         ["@foo"]));
30 
31     assert(!isWantedTest(TestData("", "", null, false /*hidden*/, false /*shouldFail*/, false /*singleThreaded*/,
32                                  false /*builtin*/, "" /*suffix*/, ["foo"]),
33                         ["~@foo"]));
34 
35     assert(isWantedTest(TestData("", "", null, false /*hidden*/, false /*shouldFail*/, false /*singleThreaded*/,
36                                   false /*builtin*/, "" /*suffix*/),
37                          ["~@foo"]));
38 
39     assert(isWantedTest(TestData("", "", null, false /*hidden*/, false /*shouldFail*/, false /*singleThreaded*/,
40                                  false /*builtin*/, "" /*suffix*/, ["bar"]),
41                          ["~@foo"]));
42 
43     // if hidden, don't run by default
44     assert(!isWantedTest(TestData("", "", null, true /*hidden*/, false /*shouldFail*/, false /*singleThreaded*/,
45                                   false /*builtin*/, "" /*suffix*/, ["bar"]),
46                         ["~@foo"]));
47 
48     TestData suffixData;
49     suffixData.name = "foo.bar.types";
50     suffixData.suffix = "int";
51     assert(isWantedTest(suffixData, ["foo.bar.types.int"]));
52 }
53 
54 
55 @("issue242")
56 @safe unittest {
57     import unit_threaded.asserts;
58     import unit_threaded.runner.reflection;
59     import unit_threaded.runner.testcase;
60     import unit_threaded.ut.modules.issue242;
61     import std.algorithm: map;
62     import std.array: array;
63     import std.algorithm: sorted = sort;
64 
65     const testData = moduleUnitTests!(unit_threaded.ut.modules.issue242);
66     const tests = createTestCases(testData);
67     // only one composite test case should be created
68     assertEqual(tests.length, 1);
69 
70     auto composite = cast(const CompositeTestCase) tests[0];
71     assert(composite !is null);
72 }