unit testing for SCons

I’m developing a build process on top of the build system SCons. Some steps are not trivial, so unit and functional testing are required.

By trials and errors, I’ve managed to find how to check dependencies. Here is a typical code:

def check_generate_patch(env):
  # Check that the builder is added
  assert env['BUILDERS'].has_key('cdoc_patch_generate')
  # Check that the user-friendly alias is added
  out = env.ans.lookup('patch')
  assert out
  # From the alias to the target file
  node = out.sources[0]
  # Check the source files, the target and the action
  assert len(node.sources)    == 2
  assert str(node.sources[0]) == os.path.join('tmp', 'file.txt')
  assert str(node.sources[1]) == os.path.join('tmp', 'file.txt.copy')
  assert str(node)            == os.path.join('out', 'file.patch')
  assert str(node.get_executor()) == 'generate_patch(target, source, env)'

Meanwhile, I’ve found no way to delete existing targets and dependencies. Looking in the source code, I lost somewhere in the Memoize debris.

In any case, SCons belongs to the very limited class of applications which I consider near perfect. Kudos to developers!

Leave a Reply