]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | # Copyright 2001, 2002, 2003 Dave Abrahams |
2 | # Copyright 2006 Rene Rivera | |
3 | # Copyright 2002, 2003 Vladimir Prus | |
4 | # Distributed under the Boost Software License, Version 1.0. | |
5 | # (See accompanying file LICENSE_1_0.txt or copy at | |
6 | # http://www.boost.org/LICENSE_1_0.txt) | |
7 | ||
8 | import errors ; | |
9 | import modules ; | |
10 | ||
11 | ||
12 | ################################################################################ | |
13 | # | |
14 | # Private implementation details. | |
15 | # | |
16 | ################################################################################ | |
17 | ||
18 | # Rule added as a replacement for the regular Jam = operator but which does not | |
19 | # ignore trailing empty string elements. | |
20 | # | |
21 | local rule exact-equal-test ( lhs * : rhs * ) | |
22 | { | |
23 | local lhs_extended = $(lhs) xxx ; | |
24 | local rhs_extended = $(rhs) xxx ; | |
25 | if $(lhs_extended) = $(rhs_extended) | |
26 | { | |
27 | return true ; | |
28 | } | |
29 | } | |
30 | ||
31 | ||
32 | # Two lists are considered set-equal if they contain the same elements, ignoring | |
33 | # duplicates and ordering. | |
34 | # | |
35 | local rule set-equal-test ( set1 * : set2 * ) | |
36 | { | |
37 | if ( $(set1) in $(set2) ) && ( $(set2) in $(set1) ) | |
38 | { | |
39 | return true ; | |
40 | } | |
41 | } | |
42 | ||
43 | ||
44 | ################################################################################ | |
45 | # | |
46 | # Public interface. | |
47 | # | |
48 | ################################################################################ | |
49 | ||
50 | # Assert the equality of A and B, ignoring trailing empty string elements. | |
51 | # | |
52 | rule equal ( a * : b * ) | |
53 | { | |
54 | if $(a) != $(b) | |
55 | { | |
11fdf7f2 | 56 | errors.error-skip-frames 3 assertion "failure:" \"$(a)\" "==" \"$(b)\" |
7c673cae FG |
57 | (ignoring trailing empty strings) ; |
58 | } | |
59 | } | |
60 | ||
61 | ||
62 | # Assert that the result of calling RULE-NAME on the given arguments has a false | |
63 | # logical value (is either an empty list or all empty strings). | |
64 | # | |
65 | rule false ( rule-name args * : * ) | |
66 | { | |
67 | local result ; | |
68 | module [ CALLER_MODULE ] | |
69 | { | |
70 | modules.poke assert : result : [ $(1) : $(2) : $(3) : $(4) : $(5) : $(6) | |
71 | : $(7) : $(8) : $(9) : $(10) : $(11) : $(12) : $(13) : $(14) : $(15) | |
72 | : $(16) : $(17) : $(18) : $(19) ] ; | |
73 | } | |
74 | ||
75 | if $(result) | |
76 | { | |
11fdf7f2 | 77 | errors.error-skip-frames 3 assertion "failure:" Expected false result from |
7c673cae FG |
78 | "[" $(rule-name) [ errors.lol->list $(args) : $(2) : $(3) : $(4) : |
79 | $(5) : $(6) : $(7) : $(8) : $(9) : $(10) : $(11) : $(12) : $(13) : | |
11fdf7f2 | 80 | $(14) : $(15) : $(16) : $(17) : $(18) : $(19) ] "]" : "Got:" "[" |
7c673cae FG |
81 | \"$(result)\" "]" ; |
82 | } | |
83 | } | |
84 | ||
85 | ||
86 | # Assert that ELEMENT is present in LIST. | |
87 | # | |
88 | rule "in" ( element : list * ) | |
89 | { | |
90 | if ! $(element) in $(list) | |
91 | { | |
11fdf7f2 | 92 | errors.error-skip-frames 3 assertion "failure:" Expected \"$(element)\" in |
7c673cae FG |
93 | "[" \"$(list)\" "]" ; |
94 | } | |
95 | } | |
96 | ||
97 | ||
98 | # Assert the inequality of A and B, ignoring trailing empty string elements. | |
99 | # | |
100 | rule not-equal ( a * : b * ) | |
101 | { | |
102 | if $(a) = $(b) | |
103 | { | |
11fdf7f2 | 104 | errors.error-skip-frames 3 assertion "failure:" \"$(a)\" "!=" \"$(b)\" |
7c673cae FG |
105 | (ignoring trailing empty strings) ; |
106 | } | |
107 | } | |
108 | ||
109 | ||
110 | # Assert that ELEMENT is not present in LIST. | |
111 | # | |
112 | rule not-in ( element : list * ) | |
113 | { | |
114 | if $(element) in $(list) | |
115 | { | |
11fdf7f2 | 116 | errors.error-skip-frames 3 assertion "failure:" Did not expect |
7c673cae FG |
117 | \"$(element)\" in "[" \"$(list)\" "]" ; |
118 | } | |
119 | } | |
120 | ||
121 | ||
122 | # Assert the inequality of A and B as sets. | |
123 | # | |
124 | rule not-set-equal ( a * : b * ) | |
125 | { | |
126 | if [ set-equal-test $(a) : $(b) ] | |
127 | { | |
11fdf7f2 | 128 | errors.error-skip-frames 3 assertion "failure:" Expected "[" \"$(a)\" "]" |
7c673cae FG |
129 | and "[" \"$(b)\" "]" to not be equal as sets ; |
130 | } | |
131 | } | |
132 | ||
133 | ||
134 | # Assert that A and B are not exactly equal, not ignoring trailing empty string | |
135 | # elements. | |
136 | # | |
137 | rule not-exact-equal ( a * : b * ) | |
138 | { | |
139 | if [ exact-equal-test $(a) : $(b) ] | |
140 | { | |
11fdf7f2 | 141 | errors.error-skip-frames 3 assertion "failure:" \"$(a)\" "!=" \"$(b)\" ; |
7c673cae FG |
142 | } |
143 | } | |
144 | ||
145 | ||
146 | # Assert that EXPECTED is the result of calling RULE-NAME with the given | |
147 | # arguments. | |
148 | # | |
149 | rule result ( expected * : rule-name args * : * ) | |
150 | { | |
151 | local result ; | |
152 | module [ CALLER_MODULE ] | |
153 | { | |
154 | modules.poke assert : result : [ $(2) : $(3) : $(4) : $(5) : $(6) : $(7) | |
155 | : $(8) : $(9) : $(10) : $(11) : $(12) : $(13) : $(14) : $(15) : | |
156 | $(16) : $(17) : $(18) : $(19) ] ; | |
157 | } | |
158 | ||
159 | if ! [ exact-equal-test $(result) : $(expected) ] | |
160 | { | |
11fdf7f2 | 161 | errors.error-skip-frames 3 assertion "failure:" "[" $(rule-name) [ |
7c673cae FG |
162 | errors.lol->list $(args) : $(3) : $(4) : $(5) : $(6) : $(7) : $(8) : |
163 | $(9) : $(10) : $(11) : $(12) : $(13) : $(14) : $(15) : $(16) : $(17) | |
11fdf7f2 | 164 | : $(18) : $(19) ] "]" : "Expected:" "[" \"$(expected)\" "]" : "Got:" "[" |
7c673cae FG |
165 | \"$(result)\" "]" ; |
166 | } | |
167 | } | |
168 | ||
169 | ||
170 | # Assert that EXPECTED is set-equal (i.e. duplicates and ordering are ignored) | |
171 | # to the result of calling RULE-NAME with the given arguments. Note that rules | |
172 | # called this way may accept at most 18 parameters. | |
173 | # | |
174 | rule result-set-equal ( expected * : rule-name args * : * ) | |
175 | { | |
176 | local result ; | |
177 | module [ CALLER_MODULE ] | |
178 | { | |
179 | modules.poke assert : result : [ $(2) : $(3) : $(4) : $(5) : $(6) : $(7) | |
180 | : $(8) : $(9) : $(10) : $(11) : $(12) : $(13) : $(14) : $(15) : | |
181 | $(16) : $(17) : $(18) : $(19) ] ; | |
182 | } | |
183 | ||
184 | if ! [ set-equal-test $(result) : $(expected) ] | |
185 | { | |
11fdf7f2 | 186 | errors.error-skip-frames 3 assertion "failure:" "[" $(rule-name) [ |
7c673cae FG |
187 | errors.lol->list $(args) : $(3) : $(4) : $(5) : $(6) : $(7) : $(8) : |
188 | $(9) : $(10) : $(11) : $(12) : $(13) : $(14) : $(15) : $(16) : $(17) | |
11fdf7f2 | 189 | : $(18) : $(19) ] "]" : "Expected:" "[" \"$(expected)\" "]" : "Got:" "[" |
7c673cae FG |
190 | \"$(result)\" "]" ; |
191 | } | |
192 | } | |
193 | ||
194 | ||
195 | # Assert the equality of A and B as sets. | |
196 | # | |
197 | rule set-equal ( a * : b * ) | |
198 | { | |
199 | if ! [ set-equal-test $(a) : $(b) ] | |
200 | { | |
11fdf7f2 | 201 | errors.error-skip-frames 3 assertion "failure:" Expected "[" \"$(a)\" "]" |
7c673cae FG |
202 | and "[" \"$(b)\" "]" to be equal as sets ; |
203 | } | |
204 | } | |
205 | ||
206 | ||
207 | # Assert that the result of calling RULE-NAME on the given arguments has a true | |
208 | # logical value (is neither an empty list nor all empty strings). | |
209 | # | |
210 | rule true ( rule-name args * : * ) | |
211 | { | |
212 | local result ; | |
213 | module [ CALLER_MODULE ] | |
214 | { | |
215 | modules.poke assert : result : [ $(1) : $(2) : $(3) : $(4) : $(5) : $(6) | |
216 | : $(7) : $(8) : $(9) : $(10) : $(11) : $(12) : $(13) : $(14) : $(15) | |
217 | : $(16) : $(17) : $(18) : $(19) ] ; | |
218 | } | |
219 | ||
220 | if ! $(result) | |
221 | { | |
11fdf7f2 | 222 | errors.error-skip-frames 3 assertion "failure:" Expected true result from |
7c673cae FG |
223 | "[" $(rule-name) [ errors.lol->list $(args) : $(2) : $(3) : $(4) : |
224 | $(5) : $(6) : $(7) : $(8) : $(9) : $(10) : $(11) : $(12) : $(13) : | |
225 | $(14) : $(15) : $(16) : $(17) : $(18) : $(19) ] "]" ; | |
226 | } | |
227 | } | |
228 | ||
229 | ||
230 | # Assert the exact equality of A and B, not ignoring trailing empty string | |
231 | # elements. | |
232 | # | |
233 | rule exact-equal ( a * : b * ) | |
234 | { | |
235 | if ! [ exact-equal-test $(a) : $(b) ] | |
236 | { | |
11fdf7f2 | 237 | errors.error-skip-frames 3 assertion "failure:" \"$(a)\" "==" \"$(b)\" ; |
7c673cae FG |
238 | } |
239 | } | |
240 | ||
241 | ||
242 | # Assert that the given variable is not an empty list. | |
243 | # | |
244 | rule variable-not-empty ( name ) | |
245 | { | |
246 | local value = [ modules.peek [ CALLER_MODULE ] : $(name) ] ; | |
247 | if ! $(value)-is-not-empty | |
248 | { | |
11fdf7f2 | 249 | errors.error-skip-frames 3 assertion "failure:" Expected variable |
7c673cae FG |
250 | \"$(name)\" not to be an empty list ; |
251 | } | |
252 | } | |
253 | ||
254 | ||
255 | rule __test__ ( ) | |
256 | { | |
257 | # Helper rule used to avoid test duplication related to different list | |
258 | # equality test rules. | |
259 | # | |
260 | local rule run-equality-test ( equality-assert : ignore-trailing-empty-strings ? ) | |
261 | { | |
262 | local not-equality-assert = not-$(equality-assert) ; | |
263 | ||
264 | # When the given equality test is expected to ignore trailing empty | |
265 | # strings some of the test results should be inverted. | |
266 | local not-equality-assert-i = not-$(equality-assert) ; | |
267 | if $(ignore-trailing-empty-strings) | |
268 | { | |
269 | not-equality-assert-i = $(equality-assert) ; | |
270 | } | |
271 | ||
272 | $(equality-assert) : ; | |
273 | $(equality-assert) "" "" : "" "" ; | |
274 | $(not-equality-assert-i) : "" "" ; | |
275 | $(equality-assert) x : x ; | |
276 | $(not-equality-assert) : x ; | |
277 | $(not-equality-assert) "" : x ; | |
278 | $(not-equality-assert) "" "" : x ; | |
279 | $(not-equality-assert-i) x : x "" ; | |
280 | $(equality-assert) x "" : x "" ; | |
281 | $(not-equality-assert) x : "" x ; | |
282 | $(equality-assert) "" x : "" x ; | |
283 | ||
284 | $(equality-assert) 1 2 3 : 1 2 3 ; | |
285 | $(not-equality-assert) 1 2 3 : 3 2 1 ; | |
286 | $(not-equality-assert) 1 2 3 : 1 5 3 ; | |
287 | $(not-equality-assert) 1 2 3 : 1 "" 3 ; | |
288 | $(not-equality-assert) 1 2 3 : 1 1 2 3 ; | |
289 | $(not-equality-assert) 1 2 3 : 1 2 2 3 ; | |
290 | $(not-equality-assert) 1 2 3 : 5 6 7 ; | |
291 | ||
292 | # Extra variables used here just to make sure Boost Jam or Boost Build | |
293 | # do not handle lists with empty strings differently depending on | |
294 | # whether they are literals or stored in variables. | |
295 | ||
296 | local empty = ; | |
297 | local empty-strings = "" "" ; | |
298 | local x-empty-strings = x "" "" ; | |
299 | local empty-strings-x = "" "" x ; | |
300 | ||
301 | $(equality-assert) : $(empty) ; | |
302 | $(not-equality-assert-i) "" : $(empty) ; | |
303 | $(not-equality-assert-i) "" "" : $(empty) ; | |
304 | $(not-equality-assert-i) : $(empty-strings) ; | |
305 | $(not-equality-assert-i) "" : $(empty-strings) ; | |
306 | $(equality-assert) "" "" : $(empty-strings) ; | |
307 | $(equality-assert) $(empty) : $(empty) ; | |
308 | $(equality-assert) $(empty-strings) : $(empty-strings) ; | |
309 | $(not-equality-assert-i) $(empty) : $(empty-strings) ; | |
310 | $(equality-assert) $(x-empty-strings) : $(x-empty-strings) ; | |
311 | $(equality-assert) $(empty-strings-x) : $(empty-strings-x) ; | |
312 | $(not-equality-assert) $(empty-strings-x) : $(x-empty-strings) ; | |
313 | $(not-equality-assert-i) x : $(x-empty-strings) ; | |
314 | $(not-equality-assert) x : $(empty-strings-x) ; | |
315 | $(not-equality-assert-i) x : $(x-empty-strings) ; | |
316 | $(not-equality-assert-i) x "" : $(x-empty-strings) ; | |
317 | $(equality-assert) x "" "" : $(x-empty-strings) ; | |
318 | $(not-equality-assert) x : $(empty-strings-x) ; | |
319 | $(not-equality-assert) "" x : $(empty-strings-x) ; | |
320 | $(equality-assert) "" "" x : $(empty-strings-x) ; | |
321 | } | |
322 | ||
323 | ||
324 | # --------------- | |
325 | # Equality tests. | |
326 | # --------------- | |
327 | ||
328 | run-equality-test equal : ignore-trailing-empty-strings ; | |
329 | run-equality-test exact-equal ; | |
330 | ||
331 | ||
332 | # ------------------------- | |
333 | # assert.set-equal() tests. | |
334 | # ------------------------- | |
335 | ||
336 | set-equal : ; | |
337 | not-set-equal "" "" : ; | |
338 | set-equal "" "" : "" ; | |
339 | set-equal "" "" : "" "" ; | |
340 | set-equal a b c : a b c ; | |
341 | set-equal a b c : b c a ; | |
342 | set-equal a b c a : a b c ; | |
343 | set-equal a b c : a b c a ; | |
344 | not-set-equal a b c : a b c d ; | |
345 | not-set-equal a b c d : a b c ; | |
346 | } |