root/trunk/src/tests/z-tests.c

Revision 918, 2.6 kB (checked in by takkaria, 3 months ago)

Use consistent newlines everywhere, and also set the svn:eol-style property to native on all text files.

  • Property svn:eol-style set to native
Line 
1 /* Tests for tests. */
2 #include "../z-tests.h"
3
4
5 TEST(this_fails){ FAIL; } TEST_END
6 TEST(this_is_blank) {;} TEST_END
7 TEST(this_succeeds) {;} TEST_END
8
9 TEST(this_checks_1){ CHECK(1); } TEST_END
10 TEST(this_checks_0){ CHECK(0); } TEST_END
11 TEST(this_checks_42){ CHECK(42); } TEST_END
12
13 TEST(plan)
14 {
15         TEST_PLAN(t, 12);
16         CHECK(t.num_tests_planned == 12);
17         CHECK(t.num_tests_executed == 0);
18         CHECK(t.num_tests_failed == 0);
19 }
20 TEST_END
21
22 TEST(run)
23 {
24         TEST_PLAN(t, 3);
25         TEST_RUN(&t, this_succeeds);
26         CHECK(t.num_tests_executed == 1);
27         CHECK(t.num_tests_failed == 0);
28         TEST_RUN(&t, this_is_blank);
29         CHECK(t.num_tests_executed == 2);
30         CHECK(t.num_tests_failed == 0);
31         TEST_RUN(&t, this_fails);
32         CHECK(t.num_tests_executed == 3);
33         CHECK(t.num_tests_failed == 1);
34         CHECK(t.num_tests_planned == 3); /* sanity */
35 }
36 TEST_END
37
38 TEST(check)
39 {
40         TEST_PLAN(t, 3);
41         TEST_RUN(&t, this_checks_0);
42         TEST_RUN(&t, this_checks_1);
43         TEST_RUN(&t, this_checks_42);
44         CHECK(t.num_tests_executed == 3);
45         CHECK(t.num_tests_failed == 1);
46 }
47 TEST_END
48
49 TEST(test_success)
50 {
51         /* success! */
52         TEST_PLAN(a, 1);
53         CHECK(!test_success(&a));
54         TEST_RUN(&a, this_succeeds);
55         CHECK(test_success(&a));
56
57         /* failure! */
58         TEST_PLAN(b, 1);
59         TEST_RUN(&b, this_fails);
60         CHECK(!test_success(&b));
61
62         /* no premature success */
63         TEST_PLAN(c, 2);
64         TEST_RUN(&c, this_succeeds);
65         CHECK(!test_success(&c));
66         TEST_RUN(&c, this_succeeds);
67         CHECK(test_success(&c));
68
69         /* too many */
70         TEST_PLAN(d, 1);
71         TEST_RUN(&d, this_succeeds);
72         TEST_RUN(&d, this_succeeds);
73         CHECK(!test_success(&d));
74
75         /* no plan => don't worry about count */
76         TEST_PLAN(e, 0);
77         CHECK(test_success(&e));
78         TEST_RUN(&e, this_succeeds);
79         CHECK(test_success(&e));
80         TEST_RUN(&e, this_fails);
81         CHECK(!test_success(&e));
82 }
83 TEST_END
84
85
86 /* my Inglish iz good too */
87 int this_completes_good(void)
88 {
89         TEST_PLAN(t, 1);
90         TEST_RUN(&t, this_succeeds);
91         TESTS_COMPLETE(t);
92 }
93
94 int this_completes_bad(void)
95 {
96         TEST_PLAN(t,3);
97         TEST_RUN(&t, this_fails);
98         TEST_RUN(&t, this_fails);
99         TEST_RUN(&t, this_succeeds);
100         TEST_RUN(&t, this_succeeds);
101         /* two of each, in the event someone      */
102         /* tries to get fancy and overload the    */
103         /* return code to be a count of some sort */
104         TESTS_COMPLETE(t);
105 }
106
107 TEST(complete)
108 {
109         CHECK(this_completes_good() == 0);
110         CHECK(this_completes_bad()  == 1);
111 }
112 TEST_END
113
114 int main(void)
115 {
116         puts("Running test tests. You should see some failures.\n"
117                 "This is OK. We're testing failure.");
118         TEST_PLAN(t, 5);
119
120         TEST_RUN(&t, plan);
121         TEST_RUN(&t, run);
122         TEST_RUN(&t, check);
123         TEST_RUN(&t, test_success);
124         TEST_RUN(&t, complete);
125
126         puts("\n\nThese are the numbers you're looking for:");
127         TESTS_COMPLETE(t);
128 }
129
Note: See TracBrowser for help on using the browser.