📄 testing.jam
字号:
gGENERATOR_FUNCTION(TEST_EXE) = run-test EXE ;
SUFTEST_EXE = .run ;
rule test-executable(EXE) ( target-to-test )
{
return $(target-to-test) ;
}
rule nt-paths-to-cygwin ( paths * )
{
local result ;
for local p in $(paths)
{
# if already rooted...
if [ MATCH ^([A-Za-z]:[/\\]) : $(p) ]
{
p = [ split-path $(p) ] ;
p = [ join-path /cygdrive [ MATCH ^(.).* : $(p[1]) ] $(p[2-]) ] ;
}
result += $(p:T) ;
}
return $(result) ;
}
rule run-test ( type-to-test run-target : sources * )
{
local parent = $(run-target:S=.test) ;
local targets-to-test ;
local main-target = $(gTARGET_SUBVARIANT($(parent))) ;
# If no sources, assume someone else already built the targets,
# and they are the library dependencies of the test target that
# match the type-to-test. This should perhaps be _all_
# dependencies, but hopefully we'll throw this code out soon!
if ! $(sources)
{
for local t in [ on $(parent) return $(library-dependencies) ]
{
if $(gTARGET_TYPE($(t))) = $(type-to-test)
{
targets-to-test += $(t) ;
}
}
}
else
{
targets-to-test = $(run-target:S=$(SUF$(type-to-test))) ;
set-target-variables $(targets-to-test) ;
generate-dependencies $(main-target) : $(targets-to-test) ;
declare-basic-target $(targets-to-test) : $(sources) : : : $(type-to-test) ;
$(gGENERATOR_FUNCTION($(type-to-test))) $(targets-to-test) : $(sources) ;
}
# The .test file goes with the other subvariant targets
# normalization is a hack to get the slashes going the right way on Windoze
local LOCATE_TARGET = [ FDirName [ split-path $(LOCATE_TARGET) ] ] ;
MakeLocate $(run-target) : $(LOCATE_TARGET) ;
local executable = [ test-executable($(type-to-test)) $(targets-to-test) ] ;
local x-input-files = [ expand-source-names $(gRUN_TEST_INPUT_FILES) ] ;
local x-input-deps = ;
for local x-input-file in $(x-input-files)
{
local input-file-type = [ ungrist $(x-input-file:G:L) ] ;
local input-file-type-id = $(gTARGET_TYPE_ID($(input-file-type))) ;
local input-file-typed = $(x-input-file:G=$(input-file-type-id)) ;
if $(input-file-typed)
{
dependent-include $(input-file-typed) ;
local input-file-path = [ target-path-of $(input-file-typed) ] ;
local input-file-target = [ target-id-of $(input-file-path) ] ;
local [ protect-subproject ] ;
enter-subproject [ directory-of $(input-file-path) ] ;
local p = $(gBUILD_PROPERTIES) ;
segregate-free-properties p ;
local input-file-subvariant = [
find-compatible-subvariant $(input-file-target)
: $(gCURRENT_TOOLSET) $(variant)
: $(p) ] ;
local input-file-dep = [
subvariant-target $(input-file-target)
: $(input-file-subvariant)
: $(gCURRENT_TOOLSET) $(variant) ] ;
x-input-deps += $(input-file-dep) ;
}
else
{
x-input-deps += $(x-input-file) ;
}
}
DEPENDS $(run-target) : $(executable) $(targets-to-test) $(x-input-deps) ;
INPUT_FILES on $(run-target) = $(x-input-deps) ;
ARGS on $(run-target) = $(gRUN_TEST_ARGS) ;
ARGS2 on $(run-target) = $(gRUN_TEST_ARGS2) ;
#
# Prepare path setup
#
local path-sources = $(parent) $(executable) ; # where do we get paths from?
local $(.run-path-shell-vars) ; # declare local path variables
# initialize path variables from the path-sources
for local v in $(.run-path-vars)
{
local shell-var = $(.shell-var($(v))) ;
$(shell-var) = [ unique $($(shell-var)) $(gRUN_$(v)($(path-sources))) ] ;
}
local nt-cygwin ;
if $(NT) && $(gCURRENT_TOOLSET) in $(gcc-compilers)
{
nt-cygwin = true ;
}
# build up a fragment of shell command
local path-setup ;
for local shell-var in $(.run-path-shell-vars)
{
if $($(shell-var))
{
local dirs = $($(shell-var)) ;
local splitpath = $(SPLITPATH) ;
# PATH gets translated automatically; the rest must be
# cygwin-native when running with Cygwin GCC under NT
if $(nt-cygwin) && $(shell-var) != PATH
{
dirs = [ nt-paths-to-cygwin $(dirs) ] ;
splitpath = ":" ;
}
if $(.run-path-shell-var-value($(shell-var)))
{
dirs += $(.env-prefix)$(shell-var)$(.env-suffix) ;
}
path-setup += $(SHELL_SET)$(shell-var)=$(dirs:J=$(splitpath)) ;
path-setup += $(SHELL_EXPORT)$(shell-var) ;
}
}
local debugger = [ MATCH ^--debugger=(.*) : $(ARGV) ] ;
debugger = $(debugger)" " ;
local newline = "
" ;
PATH_SETUP on $(run-target) = $(path-setup:J=$(newline):E=)$(newline)$(debugger:E=) ;
local verbose-test = 1 ;
if --verbose-test in $(ARGV)
{
verbose-test = 0 ;
}
VERBOSE_TEST on $(run-target) = $(verbose-test) ;
if $(NT)
{
STATUS on $(run-target) = %status% ;
SET_STATUS on $(run-target) = "set status=%ERRORLEVEL%" ;
RUN_OUTPUT_NL on $(run-target) = "echo." ;
STATUS_0 on $(run-target) = "%status% EQU 0 (" ;
STATUS_NOT_0 on $(run-target) = "%status% NEQ 0 (" ;
VERBOSE on $(run-target) = "%verbose% EQU 0 (" ;
ENDIF on $(run-target) = ")" ;
}
else
{
STATUS on $(run-target) = "$status" ;
SET_STATUS on $(run-target) = "status=$?" ;
RUN_OUTPUT_NL on $(run-target) = "echo" ;
STATUS_0 on $(run-target) = "test $status -eq 0 ; then" ;
STATUS_NOT_0 on $(run-target) = "test $status -ne 0 ; then" ;
VERBOSE on $(run-target) = "test $verbose -eq 0 ; then" ;
ENDIF on $(run-target) = "fi" ;
}
capture-run-output $(run-target) : $(executable) : $(debugger) ;
if ! ( --preserve-test-targets in $(ARGV) ) && ! [ MATCH ^--debugger=(.*) : $(ARGV) ]
{
RmTemps $(run-target) : $(targets-to-test) ;
}
}
# The rule is just used for argument checking
rule capture-run-output ( target : executable + : debugger ? )
{
gTEST_OUTPUT_FILE($(target)) = $(target:S=.output) ;
INCLUDES $(target) : $(target:S=.output) ;
MakeLocate $(test-file:S=.output) : $(LOCATE_TARGET) ;
Clean clean : $(test-file:S=.output) ;
output-file on $(target) = $(target:S=.output) ;
if $(debugger)
{
debug-test $(target) : $(executable) ;
}
else
{
execute-test $(target) : $(executable) ;
}
if --run-all-tests in $(ARGV)
{
ALWAYS $(target) ;
}
}
if $(NT)
{
CATENATE = type ;
}
else
{
CATENATE = cat ;
}
actions debug-test bind INPUT_FILES
{
$(PATH_SETUP)$(>) $(ARGS) "$(INPUT_FILES)" $(ARGS2)
}
actions execute-test bind INPUT_FILES output-file
{
$(PATH_SETUP)$(>) $(ARGS) "$(INPUT_FILES)" $(ARGS2) > $(output-file) 2>&1
$(SET_STATUS)
$(RUN_OUTPUT_NL) >> $(output-file)
echo EXIT STATUS: $(STATUS) >> $(output-file)
if $(STATUS_0)
$(CP) $(output-file) $(<)
$(ENDIF)
$(SHELL_SET)verbose=$(VERBOSE_TEST)
if $(STATUS_NOT_0)
$(SHELL_SET)verbose=0
$(ENDIF)
if $(VERBOSE)
echo ====== BEGIN OUTPUT ======
$(CATENATE) $(output-file)
echo ====== END OUTPUT ======
$(ENDIF)
exit $(STATUS)
}
declare-build-fail-test RUN_FAIL : TEST_EXE ;
declare-build-succeed-test RUN : TEST_EXE ;
rule run ( sources + : args * : input-files * : requirements * : name ? : default-build * : args2 * )
{
local gRUN_TEST_ARGS = $(args) ;
local gRUN_TEST_ARGS2 = $(args2) ;
local gRUN_TEST_INPUT_FILES = $(input-files) ;
SEARCH on $(input-files) = $(SEARCH_SOURCE) ;
return [ boost-test $(sources) : RUN : $(requirements) : $(name) : $(default-build) ] ;
}
rule run-fail ( sources + : args * : input-files * : requirements * : name ? )
{
local gRUN_TEST_ARGS = $(2) ;
local gRUN_TEST_INPUT_FILES = $(3) ;
SEARCH on $(3) = $(SEARCH_SOURCE) ;
return [ boost-test $(<) : RUN_FAIL : $(4) : $(name) ] ;
}
### Rules for testing whether a program links
declare-build-fail-test LINK_FAIL : EXE ;
rule link-fail ( sources + : requirements * : name ? )
{
return [ boost-test $(<) : LINK_FAIL : $(2) : $(name) ] ;
}
declare-build-succeed-test LINK : EXE ;
rule link ( sources + : requirements * : name ? )
{
return [ boost-test $(<) : LINK : $(2) : $(name) ] ;
}
### Rules for grouping tests into suites:
rule test-suite # pseudotarget-name : test-targets...
{
NOTFILE $(<) ;
type-DEPENDS $(<) : $(>) ;
}
} # include guard
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -