[C++-sig] Re: Building/testing extensions: boost-python-runtest

David Abrahams dave at boost-consulting.com
Wed Sep 8 13:38:53 CEST 2004


Mark Rowe <mark.rowe at gmail.com> writes:

> Hi,
>
> I am using boost::python to wrap a C++ library primarily so that I can
> write unit tests for it in Python.  Inside the python/ directory of my
> project I have unit tests named similar to test_A.py, test_B.py, that
> are run by a driver script named test.py.  My problem is that when
> building and testing the code with bjam, the unit tests are not re-run
> if a change is made to test_*.py.  The are re-run correctly if test.py
> itself is changed.  Any information on how to add this type of
> dependency to the Jamfile would be appreciated.
>
> The relevant snippet from my Jamfile is:
>
> # Declare a test for the extension module
> boost-python-runtest testFoo
>     :  # Python test driver
>     test.py
>     # extension modules to use
>     <pyd>Foo
>     ;

Try using this version of the rule instead, which allows you to list
any number of python files in any order.  If it works, let me know and
I'll check it in.

----


rule boost-python-runtest (
  target : sources + : requirements * : local-build * : args * )
{
    local gRUN_TEST_ARGS = $(args) ;
    local pyfiles = [ MATCH ^(.*[.]py)$ : $(sources) ] ;
    sources = [ difference $(sources) : $(pyfiles) ] ;
    local gRUN_TEST_INPUT_FILES = [ FGristFiles $(pyfiles) ] ;

    # tell Jam that the python script is relative to this directory
    SEARCH on $(gRUN_TEST_INPUT_FILES) = $(SEARCH_SOURCE) ;

    # The user can add additional arguments in PYTHON_TEST_ARGS.
    local gRUN_TEST_ARGS2 = $(PYTHON_TEST_ARGS) ;
    gRUN_TEST_ARGS2 ?= -v ;
    
    #
    # Stick the names of the python script and source files used in
    # testing into $(source-files) on the main target.  This is kind
    # of a hack, because boost-test will be returning the name of the
    # main target, but unfortunatedly dump-tests runs during the
    # evaluation of boost-test and not during the build phase :(
    #
    local main-target = [ FGristFiles [ expand-target-names $(target) : RUN_PYD ] ] ;
    source-files on $(main-target) = $(gRUN_TEST_INPUT_FILES) ;
    
    local dependencies = [ FGristFiles [ expand-source-names $(sources) ] ] ;
    source-files on $(main-target) += $(gTARGET_SOURCES($(dependencies))) ;
      
    local result = [ 
      boost-test $(sources)
        : RUN_PYD
        : $(requirements)
          boost-python-disable-borland
          <default>python-intel-use-gcc-stdlib # unless otherwise
					       # specified, assume the GCC standard
					       # library is needed for intel
          : $(target)
            : $(local-build)
    ] ;
}


-- 
Dave Abrahams
Boost Consulting
http://www.boost-consulting.com




More information about the Cplusplus-sig mailing list