📄 testing.jam
字号:
# (C) Copyright David Abrahams 2002.
# 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)
if ! $(.testing.jam-included)
{
.testing.jam-included = "}" ; # The brace makes emacs indentation happy
# Decide which toolsets should be treated like an ordinary (unix) GCC installation
gcc-compilers = [ MATCH ^(gcc.*)$ : $(TOOLS) ] ;
mingw-compilers = [ MATCH ^(mingw.*)$ ^(gcc-nocygwin.*) : $(TOOLS) ] ;
gcc-compilers = [ difference $(gcc-compilers) : $(mingw-compilers) ] ;
local rule get-var-value ( name + )
{
return $($(name)) ;
}
local rule get-library-name ( path_or_tokens + )
{
local path = $(path_or_tokens) ;
if ! $(path[1]) { path = [ split-path $(path) ] ; }
path = /$(path:J=/) ;
local match1 = [ MATCH /libs/(.*)/(test|example) : $(path) ] ;
local match2 = [ MATCH /libs/(.*)$ : $(path) ] ;
local match3 = [ MATCH (/status$) : $(path) ] ;
if $(match1) { return $(match1[0]) ; }
else if $(match2) { return $(match2[0]) ; }
else if $(match3) { return "" ; }
else if --dump-tests in $(ARGV)
{
EXIT Cannot extract library name from path $(path) ;
}
}
# Declares a test target. If name is not supplied, it is taken from the name of
# the first source file, sans extension and directory path.
#
# type should be a target type (e.g. OBJ, DLL, LIB, EXE)
#
# RETURNS the name(s) of the generated test target(s).
rule boost-test ( sources + : target-type : requirements * : test-name ? : default-build * )
{
if ! $(gIN_LIB_INCLUDE) # No need to execute this code twice
{
local result ;
{
# manufacture a test name if none supplied explicitly
test-name ?= $(sources[1]:D=:S=) ;
local library = "" ;
if $(SUBDIR_TOKENS) { library = [ get-library-name $(SUBDIR_TOKENS) ] ; }
# Make sure that targets don't become part of "all"
local gSUPPRESS_FAKE_TARGETS = true ;
result = [
declare-local-target $(test-name)
: $(sources)
: $(requirements) <sysinclude>$(BOOST_ROOT)
: $(default-build)
: $(target-type)
] ;
if $(result) && $(result) in $(.all-boost-tests)
{
EXIT boost-test \"$(result)\" declared twice ;
.all-boost-tests += $(result) ;
}
if --dump-tests in $(ARGV) && $(result)
{
dump-test $(library) : $(result) : $(requirements) ;
}
}
Clean clean : $(result) ;
# make NOTFILE targets of the same base name as the sources which can
# be used to build a single test.
type-DEPENDS $(sources:B:S=) : $(result) ;
# The NOTFILE target called "test" builds all tests
type-DEPENDS test : $(result) ;
# Make sure the test result doesn't hang around if the test fails
RMOLD $(result) ;
return $(result) ;
}
}
# Helper for boost-test above. Uses dynamic scoping to access
# boost-test's locals.
local rule dump-test ( library ? : targets + : requirements * )
{
local srcs = [ on $(targets) get-var-value source-files ] ;
# Pick any source file names off the associated main target as well.
srcs += [ unique [ on $(gTARGET_SUBVARIANT($(targets))) get-var-value source-files ] ] ;
local pwd = [ PWD ] ;
# locate each source file
local source-files ;
for local s in $(srcs)
{
# find out where to look for the file
local paths = [ on $(s) get-var-value LOCATE SEARCH ] ;
s = $(s:G=) ; # strip grist
# build all the potential full paths of the file
local full-paths = $(s:R=$(paths)) ;
# look there
local files = [ GLOB $(full-paths:D) : $(s:D=) ] ;
if $(files)
{
# make relative to the project root instead of "."
local file = $(files[1]:R=$(pwd)) ;
# try to undo absolute paths
source-files += [ relative-path $(file) ] ;
}
}
# Extract values of the <test-info> feature
local dump-test-info = [ get-values <test-info> : $(requirements) ] ;
# Format them into a single string of quoted strings
dump-test-info = \"$(dump-test-info:J=\"\ \")\" ;
local test-id ; # unique among all tests
if $(library)
{
test-id = $(library)/$(test-name) ;
}
else
{
test-id = $(test-name) ;
}
ECHO boost-test($(target-type)) \"$(test-id)\"
[$(dump-test-info)]
":" \"$(source-files)\"
;
if --dump-test-targets in $(ARGV)
{
ECHO boost-test(TARGET)
\"$(test-id)\" [$(dump-test-info)] ":"
\"$(targets)\"
;
}
}
#######
BOOST_TEST_SUFFIX ?= .test ;
# Set a variable which says how to dump a file to stdout
if $(NT)
{
CATENATE = type ;
}
else
{
CATENATE = cat ;
}
actions **passed** bind source-files
{
echo $(source-files) > $(<)
}
actions (failed-as-expected)
{
echo failed as expected > $(<)
}
# a utility rule which causes test-file to be built successfully only if
# dependency fails to build. Used for expected-failure tests.
rule failed-test-file ( test-file : dependency + )
{
local grist = [ MATCH ^<(.*)> : $(dependency:G) ] ;
local marker = $(dependency:G=$(grist)*fail) ;
(failed-as-expected) $(marker) ;
FAIL_EXPECTED $(dependency) ;
MakeLocate $(marker) : $(LOCATE_TARGET) ;
RMOLD $(marker) ;
DEPENDS $(marker) : $(dependency) ;
succeeded-test-file $(test-file) : $(marker) ;
}
# a utility rule which causes test-file to be built successfully only if
# dependency builds. Used for expected-success tests.
rule succeeded-test-file ( test-file : dependency + )
{
**passed** $(test-file) ;
DEPENDS $(test-file) : $(dependency) ;
}
rule declare-build-succeed-test ( test-type : dependency-type )
{
gGENERATOR_FUNCTION($(test-type)) = build-test succeeded-test-file ;
gDEPENDENCY_TYPE($(test-type)) = $(dependency-type) ;
SUF$(test-type) = $(BOOST_TEST_SUFFIX) ;
}
# A utility rule which declares test-type to be a target type which
# depends on the /failed/ construction of a target of type
# dependency-type.
rule declare-build-fail-test ( test-type : dependency-type )
{
gGENERATOR_FUNCTION($(test-type)) = build-test failed-test-file ;
gDEPENDENCY_TYPE($(test-type)) = $(dependency-type) ;
SUF$(test-type) = $(BOOST_TEST_SUFFIX) ;
}
# When the appropriate generator function is bound to the
# test-file-generator argument, this is a target generator function
# for target types declared with declare-build-succeed-test and
# declare-build-fail-test, above.
rule build-test ( test-file-generator test-file + : sources * : requirements * )
{
# Get the target type of the current target out of the build properties
local target-type = [ get-values <target-type> : $(gBUILD_PROPERTIES) ] ;
# Get the type of target to attempt to build; the outcome of this
# attempt determines the result of the test.
local dependency-type = $(gDEPENDENCY_TYPE($(target-type))) ;
# Get the actual name of the target to attempt to build
local dependency = $(test-file[1]:S=$(SUF$(dependency-type))) ;
# record the source file names so we can put them in the .test
# file.
source-files on $(test-file) = $(sources) ;
# Make sure that the test-file is erased upon failure, so as not
# to give a false indication of success.
RMOLD $(test-file) ;
# Call dependency-type's generator function to attempt the build
$(gGENERATOR_FUNCTION($(dependency-type))) $(dependency) : $(sources) : $(requirements) ;
# Generator functions don't handle this job for us; perhaps they should.
set-target-variables $(dependency) ;
if $(test-file:S) != $(BOOST_TEST_SUFFIX)
{
EXIT unexpected test file suffix. Filename: $(test-file) ;
}
# The test files go with the other subvariant targets
MakeLocate $(test-file) : $(LOCATE_TARGET) ;
Clean clean : $(test-file) ;
# Generate the test file
$(test-file-generator) $(test-file) : $(dependency) ;
}
### Rules for testing whether a file compiles ###
# Establish the rule which generates targets of type "OBJ". Should really go
# into basic build system, but wasn't needed 'till now.
gGENERATOR_FUNCTION(OBJ) = Object ;
declare-build-fail-test COMPILE_FAIL : OBJ ;
declare-build-succeed-test COMPILE : OBJ ;
# Test that the given source-file(s) compile
rule compile ( sources + : requirements * : test-name ? )
{
return [ boost-test $(sources) : COMPILE : $(requirements) : $(test-name) ] ;
}
# Test that the given source-file(s) fail to compile
rule compile-fail ( sources + : requirements * : test-name ? )
{
return [ boost-test $(sources) : COMPILE_FAIL : $(requirements) : $(test-name) ] ;
}
### Rules for testing whether a program runs ###
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -