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 http://www.boost.org/LICENSE_1_0.txt) |
---|
6 | |
---|
7 | import errors : error-skip-frames lol->list ; |
---|
8 | import modules ; |
---|
9 | |
---|
10 | # assert the equality of A and B |
---|
11 | rule equal ( a * : b * ) |
---|
12 | { |
---|
13 | if $(a) != $(b) |
---|
14 | { |
---|
15 | error-skip-frames 3 assertion failure: \"$(a)\" "!=" \"$(b)\" ; |
---|
16 | } |
---|
17 | } |
---|
18 | |
---|
19 | # assert that EXPECTED is the result of calling RULE-NAME with the |
---|
20 | # given arguments |
---|
21 | rule result ( expected * : rule-name args * : * ) |
---|
22 | { |
---|
23 | local result ; |
---|
24 | module [ CALLER_MODULE ] |
---|
25 | { |
---|
26 | modules.poke assert : result |
---|
27 | : [ $(2) : $(3) : $(4) : $(5) : $(6) : $(7) : $(8) : $(9) ] ; |
---|
28 | } |
---|
29 | |
---|
30 | if $(result) != $(expected) |
---|
31 | { |
---|
32 | error-skip-frames 3 assertion failure: "[" $(rule-name) |
---|
33 | [ lol->list $(args) : $(3) : $(4) : $(5) : $(6) : $(7) : $(8) : $(9) ] |
---|
34 | "]" |
---|
35 | : expected: \"$(expected)\" |
---|
36 | : got: \"$(result)\" ; |
---|
37 | } |
---|
38 | } |
---|
39 | |
---|
40 | rule .set.equal ( set1 * : set2 * ) |
---|
41 | { |
---|
42 | if ( $(set1) in $(set2) ) && ( $(set2) in $(set1) ) |
---|
43 | { |
---|
44 | return true ; |
---|
45 | } |
---|
46 | } |
---|
47 | |
---|
48 | # assert that EXPECTED is equal to the result of calling RULE-NAME with the |
---|
49 | # given arguments |
---|
50 | rule result-equal ( expected * : rule-name args * : * ) |
---|
51 | { |
---|
52 | local result ; |
---|
53 | module [ CALLER_MODULE ] |
---|
54 | { |
---|
55 | modules.poke assert : result |
---|
56 | : [ $(2) : $(3) : $(4) : $(5) : $(6) : $(7) : $(8) : $(9) ] ; |
---|
57 | } |
---|
58 | |
---|
59 | if ! [ .set.equal $(result) : $(expected) ] |
---|
60 | { |
---|
61 | error-skip-frames 3 assertion failure: "[" $(rule-name) |
---|
62 | [ lol->list $(args) : $(3) : $(4) : $(5) : $(6) : $(7) : $(8) : $(9) ] |
---|
63 | "]" |
---|
64 | : expected: \"$(expected)\" |
---|
65 | : got: \"$(result)\" ; |
---|
66 | } |
---|
67 | } |
---|
68 | |
---|
69 | # assert that the given variable is nonempty. |
---|
70 | rule nonempty-variable ( name ) |
---|
71 | { |
---|
72 | local value = [ modules.peek [ CALLER_MODULE ] : $(name) ] ; |
---|
73 | |
---|
74 | if ! $(value)-is-nonempty |
---|
75 | { |
---|
76 | error-skip-frames 3 assertion failure: expecting non-empty variable $(variable) ; |
---|
77 | } |
---|
78 | } |
---|
79 | |
---|
80 | # assert that the result of calling RULE-NAME on the given arguments |
---|
81 | # has a true logical value (is neither an empty list nor all empty |
---|
82 | # strings). |
---|
83 | rule true ( rule-name args * : * ) |
---|
84 | { |
---|
85 | local result ; |
---|
86 | module [ CALLER_MODULE ] |
---|
87 | { |
---|
88 | modules.poke assert : result |
---|
89 | : [ $(1) : $(2) : $(3) : $(4) |
---|
90 | : $(5) : $(6) : $(7) : $(8) : $(9) ] ; |
---|
91 | } |
---|
92 | |
---|
93 | if ! $(result) |
---|
94 | { |
---|
95 | error-skip-frames 3 assertion failure: expecting true result from |
---|
96 | "[" $(rule-name) |
---|
97 | [ lol->list $(args) : $(2) : $(3) : $(4) : $(5) : $(6) : $(7) : $(8) : $(9) ] |
---|
98 | "]" ; |
---|
99 | } |
---|
100 | } |
---|
101 | |
---|
102 | # assert that the result of calling RULE-NAME on the given arguments |
---|
103 | # has a false logical value (is either an empty list or all empty |
---|
104 | # strings). |
---|
105 | rule false ( rule-name args * : * ) |
---|
106 | { |
---|
107 | local result ; |
---|
108 | module [ CALLER_MODULE ] |
---|
109 | { |
---|
110 | modules.poke assert : result |
---|
111 | : [ $(1) : $(2) : $(3) : $(4) |
---|
112 | : $(5) : $(6) : $(7) : $(8) : $(9) ] ; |
---|
113 | } |
---|
114 | |
---|
115 | if $(result) |
---|
116 | { |
---|
117 | error-skip-frames 3 assertion failure: expecting false result from |
---|
118 | "[" $(rule-name) |
---|
119 | [ lol->list $(args) : $(2) : $(3) : $(4) : $(5) : $(6) : $(7) : $(8) : $(9) ] |
---|
120 | "]" : got [ lol->list $(result) ] instead ; |
---|
121 | } |
---|
122 | } |
---|
123 | |
---|
124 | # assert that 'element' is present in 'list'. |
---|
125 | rule "in" ( element : list * ) |
---|
126 | { |
---|
127 | if ! $(element) in $(list) |
---|
128 | { |
---|
129 | error-skip-frames 3 assertion failure: expecting $(element) in |
---|
130 | "[" $(list) "]" ; |
---|
131 | } |
---|
132 | } |
---|
133 | |
---|
134 | # assert that 'element' is not present in 'list'. |
---|
135 | rule not-in ( element : list * ) |
---|
136 | { |
---|
137 | if $(element) in $(list) |
---|
138 | { |
---|
139 | error-skip-frames 3 assertion failure: did not expect $(element) in |
---|
140 | "[" $(list) "]" ; |
---|
141 | } |
---|
142 | } |
---|