1
  
2
  
3
  
4
  
5
  
6
  
7
  
8
  
9
  
10
  
11
  
12
  
13
  
14
  
15
  
16
  
17
  
18
  
19
  
20
  
21
  
22
  
23
  
24
  
25
  
26
  
27
  
28
  
29
  
30
  
31
  
32
  
33
  
34
  
35
  
36
  
37
  
38
  
39
  
40
  
41
  
42
  
43
  
44
  
45
  
46
  
47
  
48
  
49
  
50
  
51
  
52
  
53
  
54
  
55
  
56
  
57
  
58
  
59
  
60
  
61
  
62
  
63
  
64
  
65
  
66
  
67
  
68
  
69
  
70
  
71
  
72
  
73
  
74
  
75
  
76
  
77
  
78
  
79
  
80
  
81
  
82
  
83
  
84
  
85
  
86
  
87
  
88
  
89
  
90
  
91
  
92
  
93
  
94
  
95
  
96
  
97
  
98
  
99
  
100
  
101
  
102
  
103
  
104
  
105
  
106
  
107
  
108
  
109
  
110
  
111
  
112
  
113
  
114
  
115
  
116
  
117
  
118
  
119
  
120
  
121
  
122
  
123
  
124
  
125
  
126
  
127
  
128
  
129
  
130
  
131
  
132
  
133
  
134
  
135
  
136
  
137
  
138
  
139
  
140
  
141
  
142
  
143
  
144
  
145
  
146
  
147
  
148
  
149
  
150
  
151
  
152
  
153
  
154
  
155
  
156
  
157
  
158
  
159
  
160
  
161
  
162
  
163
  
164
  
165
  
166
  
167
  
168
  
169
  
// -*- pike -*- 
// Include file for use in test suites (start --self-test). 
// 
// Assumes: 
// 
// inherit "etc/test/tests/pike_test_common.pike" 
 
// Run EXPR and check that it produces a nonzero result. If the test 
// is logged then EXPR is printed. If ARGS is given then 
// sprintf(EXPR, ARGS) is printed. Returns the result of EXPR. 
#define TEST_TRUE(EXPR, ARGS...)                                        \ 
  cpp_test_true (__FILE__, __LINE__,                                    \ 
                 lambda() {return (EXPR);},                             \ 
                 #EXPR, ({ARGS})) 
 
#define TEST_FALSE(EXPR, ARGS...)                                       \ 
  cpp_test_true (__FILE__, __LINE__,                                    \ 
                 lambda() {return !(EXPR);},                            \ 
                 #EXPR, ({ARGS})) 
 
#define TEST_EQUAL(A, B)                                                \ 
  lambda () {                                                           \ 
    int len__ = min (max (sizeof (#A), sizeof (#B)), 40);               \ 
    array args__ = ({len__, #A, 0, len__, #B, 0});                      \ 
    cpp_test_true (__FILE__, __LINE__,                                  \ 
                   lambda() {                                           \ 
                     return equal (args__[2] = (A), args__[5] = (B));   \ 
                   },                                                   \ 
                   "%-*s  (is %O) equals\n"                             \ 
                   "%-*s  (is %O)?",                                    \ 
                   args__);                                             \ 
    args__ = 0;                                                         \ 
  }() 
 
#define TEST_NOT_EQUAL(A, B)                                            \ 
  lambda () {                                                           \ 
    int len__ = min (max (sizeof (#A), sizeof (#B)), 40);               \ 
    array args__ = ({len__, #A, 0, len__, #B, 0});                      \ 
    cpp_test_true (__FILE__, __LINE__,                                  \ 
                   lambda() {                                           \ 
                     return !equal (args__[2] = (A), args__[5] = (B));  \ 
                   },                                                   \ 
                   "%-*s  (is %O) does not equal\n"                     \ 
                   "%-*s  (is %O)?",                                    \ 
                   args__);                                             \ 
    args__ = 0;                                                         \ 
  }() 
 
#define TEST_CMP(A, OP, B)                                              \ 
  lambda () {                                                           \ 
    int len__ = min (max (sizeof (#A), sizeof (#B)), 40);               \ 
    array args__ = ({len__, #A, 0, len__, #B, 0});                      \ 
    cpp_test_true (__FILE__, __LINE__,                                  \ 
                   lambda() {                                           \ 
                     return (args__[2] = (A)) OP (args__[5] = (B));     \ 
                   },                                                   \ 
                   "%-*s  (is %O) " #OP "\n"                            \ 
                   "%-*s  (is %O)?",                                    \ 
                   args__);                                             \ 
    args__ = 0;                                                         \ 
  }() 
 
#define TEST_ERROR(CODE, ARGS...)                                       \ 
  cpp_test_true (__FILE__, __LINE__,                                    \ 
                 lambda() {return catch {CODE;};},                      \ 
                 #CODE, ({ARGS})) 
 
#define TEST_NOT_ERROR(CODE, ARGS...)                                   \ 
  cpp_test_true (__FILE__, __LINE__,                                    \ 
                 lambda() {return !catch {CODE;};},                     \ 
                 #CODE, ({ARGS})) 
 
#define ASSERT_TRUE(EXPR, ARGS...)                                      \ 
  cpp_assert_true (__FILE__, __LINE__,                                  \ 
     lambda() {return (EXPR);},                                         \ 
     #EXPR, ({ARGS})) 
 
#define ASSERT_FALSE(EXPR, ARGS...)                                     \ 
  cpp_assert_true (__FILE__, __LINE__,                                  \ 
     lambda() {return !(EXPR);},                                        \ 
     #EXPR, ({ARGS})) 
 
// ASSERT macros: 
// Work like their TEST_-equivalent above but do not swallow errors. 
#define ASSERT_EQUAL(A, B)                                              \ 
  lambda () {                                                           \ 
    int len__ = min (max (sizeof (#A), sizeof (#B)), 40);               \ 
    array args__ = ({len__, #A, 0, len__, #B, 0});                      \ 
    cpp_assert_true (__FILE__, __LINE__,                                \ 
       lambda() {                                                       \ 
         return equal (args__[2] = (A), args__[5] = (B));               \ 
       },                                                               \ 
       "%-*s  (is %O) equals\n"                                         \ 
       "%-*s  (is %O)?",                                                \ 
       args__);                                                         \ 
    args__ = 0;                                                         \ 
  }() 
 
#define ASSERT_NOT_EQUAL(A, B)                                          \ 
  lambda () {                                                           \ 
    int len__ = min (max (sizeof (#A), sizeof (#B)), 40);               \ 
    array args__ = ({len__, #A, 0, len__, #B, 0});                      \ 
    cpp_assert_true (__FILE__, __LINE__,                                \ 
       lambda() {                                                       \ 
         return !equal (args__[2] = (A), args__[5] = (B));              \ 
       },                                                               \ 
       "%-*s  (is %O) does not equal\n"                                 \ 
       "%-*s  (is %O)?",                                                \ 
       args__);                                                         \ 
    args__ = 0;                                                         \ 
  }() 
 
#define ASSERT_CMP(A, OP, B)                                            \ 
  lambda () {                                                           \ 
    int len__ = min (max (sizeof (#A), sizeof (#B)), 40);               \ 
    array args__ = ({len__, #A, 0, len__, #B, 0});                      \ 
    cpp_assert_true (__FILE__, __LINE__,                                \ 
       lambda() {                                                       \ 
         return (args__[2] = (A)) OP (args__[5] = (B));                 \ 
       },                                                               \ 
       "%-*s  (is %O) " #OP "\n"                                        \ 
       "%-*s  (is %O)?",                                                \ 
       args__);                                                         \ 
    args__ = 0;                                                         \ 
  }() 
 
#define ASSERT_ERROR(CODE, ARGS...)                                     \ 
  cpp_assert_true (__FILE__, __LINE__,                                  \ 
     lambda() {return catch {CODE;};},                                  \ 
     #CODE, ({ARGS})) 
 
#define ASSERT_NOT_ERROR(CODE, ARGS...)                                 \ 
  cpp_assert_true (__FILE__, __LINE__,                                  \ 
     lambda() {return !catch {CODE;};},                                 \ 
     #CODE, ({ARGS})) 
 
#define TEST_CALL(FN, ARGS...)                                          \ 
  test (({__FILE__, __LINE__, (FN)}), ARGS) 
#define TEST_CALL_TRUE(FN, ARGS...)                                     \ 
  test_true (({__FILE__, __LINE__, (FN)}), ARGS) 
#define TEST_CALL_FALSE(FN, ARGS...)                                    \ 
  test_false (({__FILE__, __LINE__, (FN)}), ARGS) 
#define TEST_CALL_ERROR(FN, ARGS...)                                    \ 
  test_error (({__FILE__, __LINE__, (FN)}), ARGS) 
#define TEST_CALL_EQUAL(VAL, FN, ARGS...)                               \ 
  test_equal ((VAL), ({__FILE__, __LINE__, (FN)}), ARGS) 
#define TEST_CALL_NOT_EQUAL(VAL, FN, ARGS...)                           \ 
  test_not_equal ((VAL), ({__FILE__, __LINE__, (FN)}), ARGS) 
#define TEST_CALL_GENERIC(CHECK_FN, FN, ARGS...)                        \ 
  test_generic ((CHECK_FN), ({__FILE__, __LINE__, (FN)}), ARGS) 
 
// ASSERT macros: 
// Work like their TEST_-equivalent but do not swallow errors. 
#define ASSERT_CALL(FN, ARGS...)                                        \ 
  assert (({__FILE__, __LINE__, (FN)}), ARGS) 
#define ASSERT_CALL_TRUE(FN, ARGS...)                                   \ 
  assert_true (({__FILE__, __LINE__, (FN)}), ARGS) 
#define ASSERT_CALL_FALSE(FN, ARGS...)                                  \ 
  assert_false (({__FILE__, __LINE__, (FN)}), ARGS) 
#define ASSERT_CALL_ERROR(FN, ARGS...)                                  \ 
  assert_error (({__FILE__, __LINE__, (FN)}), ARGS) 
#define ASSERT_CALL_EQUAL(VAL, FN, ARGS...)                             \ 
  assert_equal ((VAL), ({__FILE__, __LINE__, (FN)}), ARGS) 
#define ASSERT_CALL_NOT_EQUAL(VAL, FN, ARGS...)                         \ 
  assert_not_equal ((VAL), ({__FILE__, __LINE__, (FN)}), ARGS) 
#define ASSERT_CALL_GENERIC(CHECK_FN, FN, ARGS...)                      \ 
  assert_generic ((CHECK_FN), ({__FILE__, __LINE__, (FN)}), ARGS)