mirror of
https://github.com/boostorg/build.git
synced 2026-02-15 13:02:11 +00:00
117 lines
2.5 KiB
Plaintext
117 lines
2.5 KiB
Plaintext
# (C) Copyright David Abrahams 2001. Permission to copy, use, modify, sell and
|
|
# distribute this software is granted provided this copyright notice appears in
|
|
# all copies. This software is provided "as is" without express or implied
|
|
# warranty, and with no claim as to its suitability for any purpose.
|
|
|
|
import class : is-instance ;
|
|
import errors ;
|
|
|
|
rule ungrist ( names * )
|
|
{
|
|
local result ;
|
|
for local name in $(names)
|
|
{
|
|
local stripped = [ MATCH ^<(.*)>$ : $(name) ] ;
|
|
if ! $(stripped)
|
|
{
|
|
errors.error "in ungrist" $(names) : $(name) is not of the form <.*> ;
|
|
}
|
|
result += $(stripped) ;
|
|
}
|
|
return $(result) ;
|
|
}
|
|
|
|
# Return the file of the caller of the rule that called caller-file.
|
|
rule caller-file ( )
|
|
{
|
|
local bt = [ BACKTRACE ] ;
|
|
return $(bt[9]) ;
|
|
}
|
|
|
|
# Returns the textual representation of argument. If it is a class
|
|
# instance, class its 'str' method. Otherwise, returns the argument.
|
|
rule str ( value )
|
|
{
|
|
if [ is-instance $(value) ]
|
|
{
|
|
return [ $(value).str ] ;
|
|
}
|
|
else
|
|
{
|
|
return $(value) ;
|
|
}
|
|
}
|
|
|
|
# Tests if 'a' is equal to 'b'. If 'a' is a class instance,
|
|
# calls its 'equal' method. Uses ordinary jam's comparison otherwise.
|
|
rule equal ( a b )
|
|
{
|
|
if [ is-instance $(a) ]
|
|
{
|
|
return [ $(a).equal $(b) ] ;
|
|
}
|
|
else
|
|
{
|
|
if $(a) = $(b)
|
|
{
|
|
return true ;
|
|
}
|
|
}
|
|
}
|
|
|
|
# Tests if 'a' is less than 'b'. If 'a' is a class instance,
|
|
# calls its 'less' method. Uses ordinary jam's comparison otherwise.
|
|
rule less ( a b )
|
|
{
|
|
if [ is-instance $(a) ]
|
|
{
|
|
return [ $(a).less $(b) ] ;
|
|
}
|
|
else
|
|
{
|
|
if $(a) < $(b)
|
|
{
|
|
return true ;
|
|
}
|
|
}
|
|
}
|
|
|
|
local rule __test__ ( )
|
|
{
|
|
import assert ;
|
|
import class : class new ;
|
|
assert.result foo bar : ungrist <foo> <bar> ;
|
|
|
|
assert.result 123 : str 123 ;
|
|
|
|
local rule test-class__ ( )
|
|
{
|
|
rule str ( )
|
|
{
|
|
return "str-test-class" ;
|
|
}
|
|
|
|
rule less ( a )
|
|
{
|
|
return "yes, of course!" ;
|
|
}
|
|
|
|
rule equal ( a )
|
|
{
|
|
return "not sure" ;
|
|
}
|
|
}
|
|
class test-class__ ;
|
|
|
|
assert.result "str-test-class" : str [ new test-class__ ] ;
|
|
assert.true less 1 2 ;
|
|
assert.false less 2 1 ;
|
|
assert.result "yes, of course!" : less [ new test-class__ ] 1 ;
|
|
assert.true equal 1 1 ;
|
|
assert.false equal 1 2 ;
|
|
assert.result "not sure" : equal [ new test-class__ ] 1 ;
|
|
}
|
|
|
|
|
|
|