tags:

views:

40

answers:

1

My team is creating a build system based on SCons. We have created a bunch of helper classes in our own site_scons/site_tools folder.

My task is to create and run tests on our code, using pyunit. The test code would probably live in a subfolder, with the directory layout looking something like:

SConstruct
our_source_code/
   Sconscript
site_scons/
    site_tools/
        a.py
        b.py
        c.py
        tests/
            test_a.py
            test_b.py
            test_c.py

Now my question is: What is the best way to invoke our tests, given they will probably require the correct SCons environment set up? (that is a.py uses SCons.Environment)

Do I add a Builder or a Command? Or something else?

+1  A: 

I think the best approach would be to use the test setup code from SCons itself. This requires a SVN checkout of SCons, as the test files are not shipped with the regular SCons tarballs. This is probably workable, as not everyone in your team would be writing tools and running tests on them.

For example, this is the test for javac. Basically you write out files that you want, run a SConstruct, then check the results are what you expected. You can mock tools with Python scripts, to ensure they are really called with the flags and files that you expect. For example:

import TestSCons
test = TestSCons.TestSCons()
test.write('SConstruct', '''env = Environment(tools = ["yourtool"])
env.RunYourTool()''')

test.write('sourcefile.x', 'Content goes here')
test.run(arguments = '.', stderr = None)

test.must_match('outputfile', 'desired contents')
test.pass_test()

There are also more instructions on writing SCons tools tests on the swtoolkit wiki, which is a seemingly-defunct SCons extension from Google. The info on the wiki is still useful, and there are some good examples on how to write tests for custom SCons tools.

rq
Nice link, thanks. We're very early in development, so the idea would be to integrate our "scons tests" into the regular Continuous Integration build, so unfortunately everyone has to be able to run the tests.
Justicle
Well, not everyone - the developer of the tool + build machine.
rq