SCons integration

From CxxTest wiki

Jump to: navigation, search

CxxTest ships with a SCons builder, designed in the SCons way. This is the preferred way of using CxxTest with SCons. If this builder does not support a particular feature you require, please, report it as a feature request on our bugtracker.

Contents

Installation

Get the code from CxxTest svn. If you have a recent enough release of CxxTest itself, it should already be in build_toos/SCons/cxxtest.py

Copy this code into a cxxtest.py somewhere in your toolpath (usually to #/site_scons/site_tools/cxxtest.py), or, even better, make a symlink there to the file in the cxxtest installation directory.

Usage

In short, it can be used in the same way the Program() builder can be used. You can even specify other flags on call etc. If something does not behave the way Program() does, it is a bug and should be reported on our bugtracker.

This script has a couple of other options. The always-up-to-date documentation for them is in the builder itself, in the generate() function, but and here is a transcript (hopefully recent) with some additions. online casino spielen

The CxxTest builder accepts certain keyword arguments. You can specify them in your SCons environment at any time (for the arguments that it makes sense - for instance, the CXXTEST argument MUST be given at environment creation time, if needed, because the builder needs it for its own initialization).

Most of these you can also specify when you call the CxxTest() builder function to actually build something. If so, the supplied value will override the default.

For an example of specifying such arguments, see the example below.

Here is a list of all arguments the script accepts, together with their descriptions.

CXXTEST

The path to the cxxtestgen.py script. This option MUST be specified when the generate function is called. Basically, this means that you must set it when you call the Environment() constructor in SCons.

Odds are you will not have to specify this - in standard setups (cxxtest in the root of you project), this is found for you automatically.

Default: searches SCons environment, OS environment, path, and project, in that order.

CXXTEST_RUNNER

The runner to use.

Default: ErrorPrinter

CXXTEST_OPTS

Other options to pass to cxxtestgen.py. Default: (empty string)

CXXTEST_SUFFIX

The suffix of the test files. If you only ever use CxxTest to compile one test at a time, this is not needed - CxxTest() will automatically assume that the 1st sourcefile you give it is the test source.

Default: '.t.h'

CXXTEST_TARGET

The target to append the tests to, or, to put it differently, what scons command you run to run the tests. Defaults to "check", which means you run "scons check" in order for the test suites to be run.

Default: "check"

CXXTEST_CXXFLAGS_REMOVE

The flags that, if passed to the compiler as CXXFLAGS, cxxtest tests can't compile with, or give lots of warnings. Will be stripped from the CXXFLAGS variable.

Default: -pedantic -Weffc++

CXXTEST_CCFLAGS_REMOVE

See CXXTEST_CXXFLAGS_REMOVE option. This is the exact same thing, but for CCFLAGS.

CXXTEST_PYTHON

The path to the python binary. You should never have to set this.

Default: searches path for python.

CXXTEST_SKIP_ERRORS

Set to True to continue running the next test if one test fails.

Note: This does *not* mean that scons will continue compiling if a test does not compile. It is only for *running* tests when scons check is run.

Default: False

CXXTEST_CPPPATH

If you do not want to clutter your global CPPPATH with the CxxTest header files and other stuff you only need for your tests, this is the variable to set. Behaves as CPPPATH does.

Other options

Whatever the Program call accepts, this accepts, or should. If something doesn't work as expected, report it.

Example

Many examples can be found as tests for the builder, here, in the svn repository. Don't be afraid to look - the sample SConstruct files are inside the directories on the linked page.


# vanilla include (the 'cxxtest' would be 'CxxTest' if the file was called CxxTest.py!)
env = Environment(tools = ['default', 'cxxtest'])

# if you have to specify some options: (others can be found in the comment block of the generate function in the code or above)
env = Environment(tools = ['default', ('cxxtest', {'CXXTEST':'#/cxxtestgen.py', 'CXXTEST_CPPPATH':'#/libs/cxxtest/'})])

# or you can use this syntax:
env = Environment(tools = ['default','cxxtest'], CXXTEST='#/path/to/cxxtestgen.py')

# if you don't want to have an extra scons_site directory
env = Environment(toolpath=['cxxtest/build_tools/SCons'], tools = ['default','cxxtest'])

env.CxxTest('test_quaternion', source = 'Quaternion.t.h')      # the quaternion test
env.CxxTest('test_utility', ['utility.t.h', '../utility.cpp']) # utility functions test
env.CxxTest('test_timer', ['Timer.t.h'])                       # timer class test

# generate the source for multile files and then call the runner (--root/--part functionality)
env.CxxTest('test_multi', ['TestSuite1.t.h', 'TestSuite2.t.h', 'test_utility_functions.cpp'], CXXFLAGS='-Wall -W -Wextra')

Authors and Contributors

The 1st version was written by Gašper Ažman, and then completely rewritten again to produce the code as it largely is today.

Diego Nieto Cid kindly provided the windows interpreter finding fixes. Many thanks!

Some fixes and additions (and code cleanup) were initiated and implemented by J. Darby Mitchell. It is because of him that I started working on getting this builder to try to work out of the box.

Globbing support problems reported by Edmundo Lopez, who also provided a patch. As a result, the sourcecode was streamlined in order to fix the problems the patch uncovered.

Maintainer

The current maintainer is Gašper Ažman. The builder is maintained as a part of the CxxTest package.

Quality control

All problems reported have their own unit-test that fails if run by a builder without the fix. This means regressions shoud not crop up. If you have a problem with a version of this script that you did not have before, check the changelog - the behaviour might have changed. If that is not the case, please report it.