1 | # (C) Copyright David Abrahams 2001. Permission to copy, use, modify, sell and |
---|
2 | # distribute this software is granted provided this copyright notice appears in |
---|
3 | # all copies. This software is provided "as is" without express or implied |
---|
4 | # warranty, and with no claim as to its suitability for any purpose. |
---|
5 | |
---|
6 | import errors : error-skip-frames lol->list ; |
---|
7 | import modules ; |
---|
8 | |
---|
9 | # assert the equality of A and B |
---|
10 | rule equal ( a * : b * ) |
---|
11 | { |
---|
12 | if $(a) != $(b) |
---|
13 | { |
---|
14 | error-skip-frames 3 assertion failure: \"$(a)\" "!=" \"$(b)\" ; |
---|
15 | } |
---|
16 | } |
---|
17 | |
---|
18 | # assert that EXPECTED is the result of calling RULE-NAME with the |
---|
19 | # given arguments |
---|
20 | rule result ( expected * : rule-name args * : * ) |
---|
21 | { |
---|
22 | local result ; |
---|
23 | module [ CALLER_MODULE ] |
---|
24 | { |
---|
25 | modules.poke assert : result |
---|
26 | : [ $(2) : $(3) : $(4) : $(5) : $(6) : $(7) : $(8) : $(9) ] ; |
---|
27 | } |
---|
28 | |
---|
29 | if $(result) != $(expected) |
---|
30 | { |
---|
31 | error-skip-frames 3 assertion failure: "[" $(rule-name) |
---|
32 | [ lol->list $(args) : $(3) : $(4) : $(5) : $(6) : $(7) : $(8) : $(9) ] |
---|
33 | "]" |
---|
34 | : expected: \"$(expected)\" |
---|
35 | : got: \"$(result)\" ; |
---|
36 | } |
---|
37 | } |
---|
38 | |
---|
39 | # assert that the given variable is nonempty. |
---|
40 | rule nonempty-variable ( name ) |
---|
41 | { |
---|
42 | local value = [ modules.peek [ CALLER_MODULE ] : $(name) ] ; |
---|
43 | |
---|
44 | if ! $(value)-is-nonempty |
---|
45 | { |
---|
46 | error-skip-frames 3 assertion failure: expecting non-empty variable $(variable) ; |
---|
47 | } |
---|
48 | } |
---|
49 | |
---|
50 | # assert that the result of calling RULE-NAME on the given arguments |
---|
51 | # has a true logical value (is neither an empty list nor all empty |
---|
52 | # strings). |
---|
53 | rule true ( rule-name args * : * ) |
---|
54 | { |
---|
55 | local result ; |
---|
56 | module [ CALLER_MODULE ] |
---|
57 | { |
---|
58 | modules.poke assert : result |
---|
59 | : [ $(1) : $(2) $(3) : $(4) |
---|
60 | : $(5) : $(6) : $(7) : $(8) : $(9) ] ; |
---|
61 | } |
---|
62 | |
---|
63 | if ! $(result) |
---|
64 | { |
---|
65 | error-skip-frames 3 assertion failure: expecting true result from |
---|
66 | "[" $(rule-name) |
---|
67 | [ lol->list $(args) : $(2) : $(3) : $(4) : $(5) : $(6) : $(7) : $(8) : $(9) ] |
---|
68 | "]" ; |
---|
69 | } |
---|
70 | } |
---|
71 | |
---|
72 | # assert that the result of calling RULE-NAME on the given arguments |
---|
73 | # has a false logical value (is either an empty list or all empty |
---|
74 | # strings). |
---|
75 | rule false ( rule-name args * : * ) |
---|
76 | { |
---|
77 | local result ; |
---|
78 | module [ CALLER_MODULE ] |
---|
79 | { |
---|
80 | modules.poke assert : result |
---|
81 | : [ $(1) : $(2) $(3) : $(4) |
---|
82 | : $(5) : $(6) : $(7) : $(8) : $(9) ] ; |
---|
83 | } |
---|
84 | |
---|
85 | if $(result) |
---|
86 | { |
---|
87 | error-skip-frames 3 assertion failure: expecting false result from |
---|
88 | "[" $(rule-name) |
---|
89 | [ lol->list $(args) : $(2) : $(3) : $(4) : $(5) : $(6) : $(7) : $(8) : $(9) ] |
---|
90 | "]" : got [ lol->list $(result) ] instead ; |
---|
91 | } |
---|
92 | } |
---|
93 | |
---|
94 | # assert that 'element' is present in 'list'. |
---|
95 | rule "in" ( element : list * ) |
---|
96 | { |
---|
97 | if ! $(element) in $(list) |
---|
98 | { |
---|
99 | error-skip-frames 3 assertion failure: expecting $(element) in |
---|
100 | "[" $(list) "]" ; |
---|
101 | } |
---|
102 | } |
---|
103 | |
---|
104 | # assert that 'element' is not present in 'list'. |
---|
105 | rule not-in ( element : list * ) |
---|
106 | { |
---|
107 | if $(element) in $(list) |
---|
108 | { |
---|
109 | error-skip-frames 3 assertion failure: did not expect $(element) in |
---|
110 | "[" $(list) "]" ; |
---|
111 | } |
---|
112 | } |
---|