File: assert.jam

package info (click to toggle)
boost-build 2.0-m12-2
  • links: PTS
  • area: main
  • in suites: lenny, squeeze
  • size: 8,692 kB
  • ctags: 6,963
  • sloc: ansic: 39,914; sh: 9,086; python: 6,120; xml: 5,524; cpp: 1,467; yacc: 456; asm: 353; makefile: 184
file content (142 lines) | stat: -rw-r--r-- 3,871 bytes parent folder | download | duplicates (3)
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
# Copyright 2001, 2002, 2003 Dave Abrahams 
# Copyright 2006 Rene Rivera 
# Copyright 2002, 2003 Vladimir Prus 
# Distributed under the Boost Software License, Version 1.0. 
# (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) 

import errors : error-skip-frames lol->list ;
import modules ;

# assert the equality of A and B 
rule equal ( a * : b * )
{
    if $(a) != $(b)
    {
        error-skip-frames 3 assertion failure: \"$(a)\" "!=" \"$(b)\" ;
    }
}

# assert that EXPECTED is the result of calling RULE-NAME with the
# given arguments
rule result ( expected * : rule-name args * : * )
{
    local result ;
    module [ CALLER_MODULE ]
    {
        modules.poke assert : result
            : [ $(2) : $(3) : $(4) : $(5) : $(6) : $(7) : $(8) : $(9) ] ;
    }

    if $(result) != $(expected)
    {
        error-skip-frames 3 assertion failure: "[" $(rule-name) 
          [ lol->list $(args) : $(3) : $(4) : $(5) : $(6) : $(7) : $(8) : $(9) ]
            "]"
          : expected: \"$(expected)\"
          : got: \"$(result)\" ;
    }
}

rule .set.equal ( set1 * : set2 * )
{
    if ( $(set1) in $(set2) ) && ( $(set2) in $(set1) )
    {
        return true ;
    }
}

# assert that EXPECTED is equal to the result of calling RULE-NAME with the
# given arguments
rule result-equal ( expected * : rule-name args * : * )
{
    local result ;
    module [ CALLER_MODULE ]
    {
        modules.poke assert : result
            : [ $(2) : $(3) : $(4) : $(5) : $(6) : $(7) : $(8) : $(9) ] ;
    }

    if ! [ .set.equal $(result) : $(expected) ]
    {
        error-skip-frames 3 assertion failure: "[" $(rule-name) 
          [ lol->list $(args) : $(3) : $(4) : $(5) : $(6) : $(7) : $(8) : $(9) ]
            "]"
          : expected: \"$(expected)\"
          : got: \"$(result)\" ;
    }
}

# assert that the given variable is nonempty.
rule nonempty-variable ( name )
{
    local value = [ modules.peek [ CALLER_MODULE ] : $(name) ] ;

    if ! $(value)-is-nonempty
    {
        error-skip-frames 3 assertion failure: expecting non-empty variable $(variable) ;
    }
}

# assert that the result of calling RULE-NAME on the given arguments
# has a true logical value (is neither an empty list nor all empty
# strings).
rule true ( rule-name args * : * )
{
    local result ;
    module [ CALLER_MODULE ]
    {
        modules.poke assert : result
          : [ $(1) : $(2) : $(3) : $(4)
            : $(5) : $(6) : $(7) : $(8) : $(9) ] ;
    }

    if ! $(result)
    {
        error-skip-frames 3 assertion failure: expecting true result from
          "[" $(rule-name) 
          [ lol->list $(args) : $(2) : $(3) : $(4) : $(5) : $(6) : $(7) : $(8) : $(9) ]
            "]" ;
    }
}

# assert that the result of calling RULE-NAME on the given arguments
# has a false logical value (is either an empty list or all empty
# strings).
rule false ( rule-name args * : * )
{
    local result ;
    module [ CALLER_MODULE ]
    {
        modules.poke assert : result
          : [ $(1) : $(2) : $(3) : $(4)
            : $(5) : $(6) : $(7) : $(8) : $(9) ] ;
    }

    if $(result)
    {
        error-skip-frames 3 assertion failure: expecting false result from
          "[" $(rule-name) 
          [ lol->list $(args) : $(2) : $(3) : $(4) : $(5) : $(6) : $(7) : $(8) : $(9) ]
            "]" : got [ lol->list $(result) ] instead  ;
    }
}

# assert that 'element' is present in 'list'.
rule "in" ( element : list * )
{
    if ! $(element) in $(list)
    {
        error-skip-frames 3 assertion failure: expecting $(element) in 
                          "[" $(list) "]" ;
    }
}

# assert that 'element' is not present in 'list'.
rule not-in ( element : list * )
{
    if $(element) in $(list)
    {
        error-skip-frames 3 assertion failure: did not expect $(element) in 
                          "[" $(list) "]" ;
    }
}