Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_34_1/tools/build/v2/util/assert.jam @ 32

Last change on this file since 32 was 29, checked in by landauf, 17 years ago

updated boost from 1_33_1 to 1_34_1

File size: 3.8 KB
Line 
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
7import errors : error-skip-frames lol->list ;
8import modules ;
9
10# assert the equality of A and B
11rule 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
21rule 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
40rule .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
50rule 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.
70rule 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).
83rule 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).
105rule 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'.
125rule "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'.
135rule 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}
Note: See TracBrowser for help on using the repository browser.