import os
import re
-import string
import StringIO
import sys
from types import *
import SCons.SConsign
SCons.SConsign.write() # simulate normal scons-finish
for n in sys.modules.keys():
- if string.split(n, '.')[0] == 'SCons' and n[:12] != 'SCons.compat':
+ if n.split('.')[0] == 'SCons' and n[:12] != 'SCons.compat':
m = sys.modules[n]
- if type(m) is ModuleType:
+ if isinstance(m, ModuleType):
# if this is really a scons module, clear its namespace
del sys.modules[n]
m.__dict__.clear()
if self.scons_env['CXX'] == 'g++':
global existing_lib
existing_lib = 'm'
-
+
+ if sys.platform in ['cygwin', 'win32']:
+ # On Windows, SCons.Platform.win32 redefines the builtin
+ # file() and open() functions to close the file handles.
+ # This interferes with the unittest.py infrastructure in
+ # some way. Just sidestep the issue by restoring the
+ # original builtin functions whenever we have to reset
+ # all of our global state.
+
+ import __builtin__
+ import SCons.Platform.win32
+
+ __builtin__.file = SCons.Platform.win32._builtin_file
+ __builtin__.open = SCons.Platform.win32._builtin_open
+
def _baseTryXXX(self, TryFunc):
# TryCompile and TryLink are much the same, so we can test them
# in one method, we pass the function as a string ('TryCompile',
log = self.test.read( self.test.workpath('config.log') )
expr = re.compile( ".*failed in a previous run and all", re.DOTALL )
firstOcc = expr.match( log )
- assert firstOcc != None, log
+ assert firstOcc is not None, log
secondOcc = expr.match( log, firstOcc.end(0) )
- assert secondOcc == None, log
+ assert secondOcc is None, log
# 2.2 test the error caching mechanism (dependencies have changed)
self._resetSConfState()
sconf = self.SConf.SConf(self.scons_env,
conf_dir=self.test.workpath('config.tests'),
log_file=self.test.workpath('config.log'))
- class MyBuilder:
+ import SCons.Builder
+ class MyBuilder(SCons.Builder.BuilderBase):
def __init__(self):
self.prefix = ''
self.suffix = ''
return None
def prepare(self):
pass
+ def push_to_cache(self):
+ pass
def retrieve_from_cache(self):
return 0
def build(self, **kw):
pass
def get_executor(self):
class Executor:
- pass
- e = Executor()
- e.targets = [self]
- return e
+ def __init__(self, targets):
+ self.targets = targets
+ def get_all_targets(self):
+ return self.targets
+ return Executor([self])
return [MyNode('n1'), MyNode('n2')]
try:
self.scons_env.Append(BUILDERS = {'SConfActionBuilder' : MyBuilder()})
log = self.test.read( self.test.workpath('config.log') )
expr = re.compile( ".*failed in a previous run and all", re.DOTALL )
firstOcc = expr.match( log )
- assert firstOcc != None, log
+ assert firstOcc is not None, log
secondOcc = expr.match( log, firstOcc.end(0) )
- assert secondOcc == None, log
+ assert secondOcc is None, log
def test_TryAction(self):
finally:
sconf.Finish()
+ def _test_check_compilers(self, comp, func, name):
+ """This is the implementation for CheckCC and CheckCXX tests."""
+ from copy import deepcopy
+
+ # Check that Check* works
+ r = func()
+ assert r, "could not find %s ?" % comp
+
+ # Check that Check* does fail if comp is not available in env
+ oldcomp = deepcopy(self.scons_env[comp])
+ del self.scons_env[comp]
+ r = func()
+ assert not r, "%s worked wo comp ?" % name
+
+ # Check that Check* does fail if comp is set but empty
+ self.scons_env[comp] = ''
+ r = func()
+ assert not r, "%s worked with comp = '' ?" % name
+
+ # Check that Check* does fail if comp is set to buggy executable
+ self.scons_env[comp] = 'thiscccompilerdoesnotexist'
+ r = func()
+ assert not r, "%s worked with comp = thiscompilerdoesnotexist ?" % name
+
+ # Check that Check* does fail if CFLAGS is buggy
+ self.scons_env[comp] = oldcomp
+ self.scons_env['%sFLAGS' % comp] = '/WX qwertyuiop.c'
+ r = func()
+ assert not r, "%s worked with %sFLAGS = qwertyuiop ?" % (name, comp)
+
+ def test_CheckCC(self):
+ """Test SConf.CheckCC()
+ """
+ self._resetSConfState()
+ sconf = self.SConf.SConf(self.scons_env,
+ conf_dir=self.test.workpath('config.tests'),
+ log_file=self.test.workpath('config.log'))
+ try:
+ try:
+ self._test_check_compilers('CC', sconf.CheckCC, 'CheckCC')
+ except AssertionError:
+ sys.stderr.write(self.test.read('config.log'))
+ raise
+ finally:
+ sconf.Finish()
+
+ def test_CheckSHCC(self):
+ """Test SConf.CheckSHCC()
+ """
+ self._resetSConfState()
+ sconf = self.SConf.SConf(self.scons_env,
+ conf_dir=self.test.workpath('config.tests'),
+ log_file=self.test.workpath('config.log'))
+ try:
+ try:
+ self._test_check_compilers('SHCC', sconf.CheckSHCC, 'CheckSHCC')
+ except AssertionError:
+ sys.stderr.write(self.test.read('config.log'))
+ raise
+ finally:
+ sconf.Finish()
+
+ def test_CheckCXX(self):
+ """Test SConf.CheckCXX()
+ """
+ self._resetSConfState()
+ sconf = self.SConf.SConf(self.scons_env,
+ conf_dir=self.test.workpath('config.tests'),
+ log_file=self.test.workpath('config.log'))
+ try:
+ try:
+ self._test_check_compilers('CXX', sconf.CheckCXX, 'CheckCXX')
+ except AssertionError:
+ sys.stderr.write(self.test.read('config.log'))
+ raise
+ finally:
+ sconf.Finish()
+
+ def test_CheckSHCXX(self):
+ """Test SConf.CheckSHCXX()
+ """
+ self._resetSConfState()
+ sconf = self.SConf.SConf(self.scons_env,
+ conf_dir=self.test.workpath('config.tests'),
+ log_file=self.test.workpath('config.log'))
+ try:
+ try:
+ self._test_check_compilers('SHCXX', sconf.CheckSHCXX, 'CheckSHCXX')
+ except AssertionError:
+ sys.stderr.write(self.test.read('config.log'))
+ raise
+ finally:
+ sconf.Finish()
+
def test_CheckHeader(self):
"""Test SConf.CheckHeader()
if not res.wasSuccessful():
sys.exit(1)
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4: