⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testing.jam

📁 boost库提供标准的C++ API 配合dev c++使用,功能更加强大
💻 JAM
📖 第 1 页 / 共 2 页
字号:
#  (C) Copyright David Abrahams 2002. 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.
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)) ;
}

# 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=) ;
            
            # 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) in $(.all-boost-tests)
            {
                EXIT boost-test \"$(result)\" declared twice ;
                .all-boost-tests += $(result) ;
            }
            
            if ( --dump-tests in $(ARGV) ) 
            {
                dump-test $(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 ( 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=\"\ \")\" ;
    
    ECHO boost-test($(target-type)) \"$(test-name)\" 
      [$(dump-test-info)]
        ":" \"$(source-files)\"
          ;
    
}


#######

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 ;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -