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

📄 testing.jam

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

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 targets-to-test = $(run-target:S=$(SUF$(type-to-test))) ; 
    local parent = $(run-target:S=.test) ;
    local main-target = $(gTARGET_SUBVARIANT($(parent))) ;
    
    set-target-variables $(targets-to-test) ;
    generate-dependencies $(main-target) : $(targets-to-test) ;
    
    if $(sources)
    {
        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[1]) ] ;
    DEPENDS $(run-target) : $(executable) $(targets-to-test) $(gRUN_TEST_INPUT_FILES) ;
    INPUT_FILES on $(run-target) = $(gRUN_TEST_INPUT_FILES) ;
    ARGS on $(run-target) = $(gRUN_TEST_ARGS) ;
    
    #
    # 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) ;
}

# The rule is just used for argument checking
rule capture-run-output ( target : executable + )
{
    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) ;
    execute-test $(target) : $(executable) ;

    if --run-all-tests in $(ARGV)
    {
        ALWAYS $(target) ;
    }
}

if $(NT)
{
    CATENATE = type ;
}
else
{
    CATENATE = cat ;
}

actions execute-test bind INPUT_FILES output-file
{
    $(PATH_SETUP)$(>) $(ARGS) "$(INPUT_FILES)" > $(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 * )
{
    local gRUN_TEST_ARGS = $(args) ;
    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 + -