# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
__author__ = "Steven Knight <knight at baldmt dot com>"
-__revision__ = "TestCmd.py 0.7.D001 2004/07/08 10:02:13 knight"
-__version__ = "0.7"
+__revision__ = "TestCmd.py 0.8.D001 2004/07/15 06:24:14 knight"
+__version__ = "0.8"
import os
import os.path
"""
if not self._dirlist:
return
- os.chdir(self._cwd)
+ os.chdir(self._cwd)
self.workdir = None
if condition is None:
condition = self.condition
self.writable(dir, 1)
shutil.rmtree(dir, ignore_errors = 1)
self._dirlist = []
-
+
try:
global _Cleanup
_Cleanup.remove(self)
def where_is(self, file, path=None, pathext=None):
"""Find an executable file.
"""
- if is_List(file):
- file = apply(os.path.join, tuple(file))
- if not os.path.isabs(file):
- file = where_is(file, path, pathext)
+ if is_List(file):
+ file = apply(os.path.join, tuple(file))
+ if not os.path.isabs(file):
+ file = where_is(file, path, pathext)
return file
def workdir_set(self, path):
test.run(options = "options to be prepended to arguments",
stdout = "expected standard output from the program",
stderr = "expected error output from the program",
- status = expected_status)
+ status = expected_status,
+ match = match_function)
The TestCommon module also provides the following variables
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
__author__ = "Steven Knight <knight at baldmt dot com>"
-__revision__ = "TestCommon.py 0.7.D001 2004/07/08 10:02:13 knight"
-__version__ = "0.7"
+__revision__ = "TestCommon.py 0.8.D001 2004/07/15 06:24:14 knight"
+__version__ = "0.8"
import os
import os.path
self.fail_test(not self.match(file_contents, expect))
except:
print "Unexpected contents of `%s'" % file
- print "EXPECTED contents ======"
+ print "EXPECTED contents ======"
print expect
print "ACTUAL contents ========"
print file_contents
def run(self, options = None, arguments = None,
stdout = None, stderr = '', status = 0, **kw):
- """Runs the program under test, checking that the test succeeded.
+ """Runs the program under test, checking that the test succeeded.
The arguments are the same as the base TestCmd.run() method,
with the addition of:
options Extra options that get appended to the beginning
of the arguments.
- stdout The expected standard output from
- the command. A value of None means
- don't test standard output.
+ stdout The expected standard output from
+ the command. A value of None means
+ don't test standard output.
- stderr The expected error output from
- the command. A value of None means
- don't test error output.
+ stderr The expected error output from
+ the command. A value of None means
+ don't test error output.
status The expected exit status from the
command. A value of None means don't
By default, this expects a successful exit (status = 0), does
not test standard output (stdout = None), and expects that error
output is empty (stderr = "").
- """
+ """
if options:
if arguments is None:
arguments = options
else:
arguments = options + " " + arguments
kw['arguments'] = arguments
- try:
- apply(TestCmd.run, [self], kw)
- except:
- print "STDOUT ============"
- print self.stdout()
- print "STDERR ============"
- print self.stderr()
- raise
- if _failed(self, status):
+ try:
+ match = kw['match']
+ del kw['match']
+ except KeyError:
+ match = self.match
+ try:
+ apply(TestCmd.run, [self], kw)
+ except:
+ print "STDOUT ============"
+ print self.stdout()
+ print "STDERR ============"
+ print self.stderr()
+ raise
+ if _failed(self, status):
expect = ''
if status != 0:
expect = " (expected %s)" % str(status)
print "%s returned %s%s" % (self.program, str(_status(self)), expect)
print "STDOUT ============"
print self.stdout()
- print "STDERR ============"
- print self.stderr()
- raise TestFailed
- if not stdout is None and not self.match(self.stdout(), stdout):
+ print "STDERR ============"
+ print self.stderr()
+ raise TestFailed
+ if not stdout is None and not match(self.stdout(), stdout):
print "Expected STDOUT =========="
print stdout
print "Actual STDOUT ============"
print "STDERR ==================="
print stderr
raise TestFailed
- if not stderr is None and not self.match(self.stderr(), stderr):
+ if not stderr is None and not match(self.stderr(), stderr):
print "STDOUT ==================="
print self.stdout()
- print "Expected STDERR =========="
- print stderr
- print "Actual STDERR ============"
- print self.stderr()
- raise TestFailed
+ print "Expected STDERR =========="
+ print stderr
+ print "Actual STDERR ============"
+ print self.stderr()
+ raise TestFailed
arguments = options + " " + arguments
kw['arguments'] = arguments
kw['stdout'] = self.wrap_stdout(read_str = read_str, build_str = s)
+ kw['match'] = self.match_exact
apply(self.run, [], kw)
def not_up_to_date(self, options = None, arguments = None, **kw):
kw['stdout'] = self.wrap_stdout(build_str="("+s+"[^\n]*\n)*")
kw['stdout'] = string.replace(kw['stdout'],'\n','\\n')
kw['stdout'] = string.replace(kw['stdout'],'.','\\.')
- old_match_func = self.match_func
- self.match_func = match_re_dotall
+ kw['match'] = self.match_re_dotall
apply(self.run, [], kw)
- self.match_func = old_match_func
# In some environments, $AR will generate a warning message to stderr
# if the library doesn't previously exist and is being created. One
python = TestSCons.python
_exe = TestSCons._exe
-test = TestSCons.TestSCons(match=TestSCons.match_re_dotall)
+test = TestSCons.TestSCons()
test.write("wrapper.py",
"""import os
""")
-test.run(arguments = 'f' + _exe, stderr=TestSCons.noisy_ar)
+test.run(arguments = 'f' + _exe,
+ stderr=TestSCons.noisy_ar,
+ match=TestSCons.match_re_dotall)
test.fail_test(os.path.exists(test.workpath('wrapper.out')))
-test.run(arguments = 'b' + _exe, stderr=TestSCons.noisy_ar)
+test.run(arguments = 'b' + _exe,
+ stderr=TestSCons.noisy_ar,
+ match=TestSCons.match_re_dotall)
test.fail_test(test.read('wrapper.out') != "wrapper.py\n")
python = TestSCons.python
_exe = TestSCons._exe
-test = TestSCons.TestSCons(match=TestSCons.match_re_dotall)
+test = TestSCons.TestSCons()
test.write("wrapper.py",
"""import os
""")
-test.run(arguments = 'f' + _exe, stderr=TestSCons.noisy_ar)
+test.run(arguments = 'f' + _exe,
+ stderr=TestSCons.noisy_ar,
+ match=TestSCons.match_re_dotall)
test.fail_test(os.path.exists(test.workpath('wrapper.out')))
-test.run(arguments = 'b' + _exe, stderr=TestSCons.noisy_ar)
+test.run(arguments = 'b' + _exe,
+ stderr=TestSCons.noisy_ar,
+ match=TestSCons.match_re_dotall)
test.fail_test(test.read('wrapper.out') != "wrapper.py\n")
args = prog + ' ' + subdir_prog + ' ' + variant_prog
-test = TestSCons.TestSCons(match=TestSCons.match_re_dotall)
+test = TestSCons.TestSCons()
test.subdir('include', 'subdir', ['subdir', 'include'], 'inc2')
test.write('empty.c', """
""")
-test.run(arguments = '.', stderr=TestSCons.noisy_ar)
+test.run(arguments = '.',
+ stderr=TestSCons.noisy_ar,
+ match=TestSCons.match_re_dotall)
test.pass_test()
import TestSCons
-test = TestSCons.TestSCons(match=TestSCons.match_re_dotall)
+test = TestSCons.TestSCons()
test.write('SConstruct', """\
def writeFile(target, contents):
lambda env,target,source: writeFile(target, '#include "gen.h"\\n'))
""")
-test.run(stderr=TestSCons.noisy_ar)
+test.run(stderr=TestSCons.noisy_ar,
+ match=TestSCons.match_re_dotall)
test.up_to_date(arguments = '.')
import TestSCons
-test = TestSCons.TestSCons(match=TestSCons.match_re_dotall)
+test = TestSCons.TestSCons()
test.subdir('work1', ['work1', 'dist'])
int foo = 3;
""")
-test.run(chdir = 'work1', arguments = ".", stderr=TestSCons.noisy_ar)
+test.run(chdir='work1', arguments=".",
+ stderr=TestSCons.noisy_ar,
+ match=TestSCons.match_re_dotall)
test.up_to_date(chdir = 'work1', arguments = ".")
_dll = TestSCons._dll
dll_ = TestSCons.dll_
-test = TestSCons.TestSCons(match=TestSCons.match_re_dotall)
+test = TestSCons.TestSCons()
test.subdir('lib1', 'lib2')
}
""")
-test.run(arguments = '.', stderr=TestSCons.noisy_ar)
+test.run(arguments = '.',
+ stderr=TestSCons.noisy_ar,
+ match=TestSCons.match_re_dotall)
test.run(program = prog1,
stdout = "f1.c\nprog.c\n")
}
""")
-test.run(arguments = '.', stderr=TestSCons.noisy_ar)
+test.run(arguments = '.',
+ stderr=TestSCons.noisy_ar,
+ match=TestSCons.match_re_dotall)
test.run(program = prog1,
stdout = "f1.c 1\nprog.c\n")
test.fail_test(oldtime2 == os.path.getmtime(prog2))
}
""")
-test.run(arguments = '.', stderr=TestSCons.noisy_ar)
+test.run(arguments = '.',
+ stderr=TestSCons.noisy_ar,
+ match=TestSCons.match_re_dotall)
test.run(program = prog1,
stdout = "f1.c 2\nprog.c\n")
env.Library('foo', source = 'empty.c')
""")
-test.run(arguments = '.', stderr=TestSCons.noisy_ar)
+test.run(arguments = '.',
+ stderr=TestSCons.noisy_ar,
+ match=TestSCons.match_re_dotall)
test.pass_test()
else:
_lib = '.a'
-test = TestSCons.TestSCons(match=TestSCons.match_re_dotall)
+test = TestSCons.TestSCons()
test.write('SConstruct', """
env = Environment(LIBPREFIX = 'xxx-',
}
""")
-test.run(arguments = '.', stderr=TestSCons.noisy_ar)
+test.run(arguments = '.',
+ stderr=TestSCons.noisy_ar,
+ match=TestSCons.match_re_dotall)
test.fail_test(not os.path.exists(test.workpath('xxx-foo' + _lib)))
_exe = ''
bar_lib = 'libbar.a'
-test = TestSCons.TestSCons(match=TestSCons.match_re_dotall)
+test = TestSCons.TestSCons()
test.subdir('sub1', 'sub2')
# on IRIX, ld32 prints out a warning saying that libbaz.a isn't used
sw = 'ld32: WARNING 84 : ./libbaz.a is not used for resolving any symbol.\n'
-test.run(arguments = '.', stderr='(%s|%s'%(sw, TestSCons.noisy_ar[1:]))
+test.run(arguments = '.',
+ stderr='(%s|%s'%(sw, TestSCons.noisy_ar[1:]),
+ match=TestSCons.match_re_dotall)
#test.fail_test(not test.stderr() in ['', sw])
test.run(program=foo1_exe, stdout='sub1/bar.c\nsub1/baz.c\n')
}
""")
-test.run(arguments = '.', stderr='(%s|%s'%(sw, TestSCons.noisy_ar[1:]))
+test.run(arguments = '.',
+ stderr='(%s|%s'%(sw, TestSCons.noisy_ar[1:]),
+ match=TestSCons.match_re_dotall)
#test.fail_test(not test.stderr() in ['', sw, TestSCons.noisy_ar])
test.run(program=foo1_exe, stdout='sub1/bar.c\nsub1/baz.c 2\n')
}
""")
-test.run(arguments = '.', stderr=TestSCons.noisy_ar)
+test.run(arguments = '.',
+ stderr=TestSCons.noisy_ar,
+ match=TestSCons.match_re_dotall)
test.run(program=blender_exe,
stdout='src/component1/message.c\nsrc/component2/hello.c\n')
else:
lib_ = 'lib'
-test = TestSCons.TestSCons(match=TestSCons.match_re_dotall)
+test = TestSCons.TestSCons()
test.write('SConstruct', """
env = Environment(LIBSUFFIX = '.xxx',
}
""")
-test.run(arguments = '.', stderr=TestSCons.noisy_ar)
+test.run(arguments = '.',
+ stderr=TestSCons.noisy_ar,
+ match=TestSCons.match_re_dotall)
test.fail_test(not os.path.exists(test.workpath(lib_ + 'foo.xxx')))
import TestSCons
-test = TestSCons.TestSCons(match=TestSCons.match_re_dotall)
+test = TestSCons.TestSCons()
test.write('SConstruct', """
env = Environment(LIBS = [ 'foo1', 'libfoo2' ],
}
""")
-test.run(arguments = '.', stderr=TestSCons.noisy_ar)
+test.run(arguments = '.',
+ stderr=TestSCons.noisy_ar,
+ match=TestSCons.match_re_dotall)
test.run(program = test.workpath('prog'),
stdout = "f1.c\nf2a.c\nf2b.c\nf2c.c\nf3a.c\nf3b.c\nf3c.cpp\nprog.c\n")
}
""")
-test.run(stderr=TestSCons.noisy_ar)
+test.run(stderr=TestSCons.noisy_ar,
+ match=TestSCons.match_re_dotall)
+
test.run(program = test.workpath('uses-nrd'),
stdout = "nrd\n")
_dll = TestSCons._dll
_shobj = TestSCons._shobj
-test = TestSCons.TestSCons(match=TestSCons.match_re_dotall)
+test = TestSCons.TestSCons()
test.subdir( 'qt', ['qt', 'bin'], ['qt', 'include'], ['qt', 'lib'] )
""")
test.run(chdir=test.workpath('qt','lib'), arguments = '.',
- stderr=TestSCons.noisy_ar)
+ stderr=TestSCons.noisy_ar,
+ match=TestSCons.match_re_dotall)
QT = test.workpath('qt')
QT_LIB = 'myqt'
}
""")
-test.run(chdir='work3', arguments = lib_aaa, stderr=TestSCons.noisy_ar)
+test.run(chdir='work3', arguments = lib_aaa,
+ stderr=TestSCons.noisy_ar,
+ match=TestSCons.match_re_dotall)
test.up_to_date(chdir='work3', options = '-n', arguments = lib_aaa)
test.write(['work3', 'aaa.cpp'], r"""
#include "my_qobject.h"
test.run(chdir='work3',
arguments = "build_dir=1 " +
test.workpath('work3', 'build', lib_aaa),
- stderr=TestSCons.noisy_ar )
+ stderr=TestSCons.noisy_ar,
+ match=TestSCons.match_re_dotall)
test.run(chdir='work3',
arguments = "build_dir=1 chdir=1 " +
test.workpath('work3', 'build', lib_aaa) )
python = TestSCons.python
_exe = TestSCons._exe
-test = TestSCons.TestSCons(match=TestSCons.match_re_dotall)
+test = TestSCons.TestSCons()
test.subdir( 'qt', ['qt', 'bin'], ['qt', 'include'], ['qt', 'lib'] )
""")
test.run(chdir=test.workpath('qt','lib'), arguments = '.',
- stderr=TestSCons.noisy_ar)
+ stderr=TestSCons.noisy_ar,
+ match=TestSCons.match_re_dotall)
QT = test.workpath('qt')
QT_LIB = 'myqt'
_exe = TestSCons._exe
-test = TestSCons.TestSCons(match=TestSCons.match_re_dotall)
+test = TestSCons.TestSCons()
ranlib = test.detect('RANLIB', 'ranlib')
""")
-test.run(arguments = 'f' + _exe, stderr=TestSCons.noisy_ar)
+test.run(arguments = 'f' + _exe,
+ stderr=TestSCons.noisy_ar,
+ match=TestSCons.match_re_dotall)
test.fail_test(os.path.exists(test.workpath('wrapper.out')))
-test.run(arguments = 'b' + _exe, stderr=TestSCons.noisy_ar)
+test.run(arguments = 'b' + _exe,
+ stderr=TestSCons.noisy_ar,
+ match=TestSCons.match_re_dotall)
test.fail_test(test.read('wrapper.out') != "wrapper.py\n")
python = TestSCons.python
_exe = TestSCons._exe
-test = TestSCons.TestSCons(match=TestSCons.match_re_dotall)
+test = TestSCons.TestSCons()
ranlib = test.detect('RANLIB', 'ranlib')
""")
-test.run(arguments = 'f' + _exe, stderr=TestSCons.noisy_ar)
+test.run(arguments = 'f' + _exe,
+ stderr=TestSCons.noisy_ar,
+ match=TestSCons.match_re_dotall)
test.fail_test(os.path.exists(test.workpath('wrapper.out')))
-test.run(arguments = 'b' + _exe, stderr=TestSCons.noisy_ar)
+test.run(arguments = 'b' + _exe,
+ stderr=TestSCons.noisy_ar,
+ match=TestSCons.match_re_dotall)
test.fail_test(test.read('wrapper.out') != "wrapper.py\n")
-test = TestSCons.TestSCons(match=TestSCons.match_re_dotall)
+test = TestSCons.TestSCons()
#
test.subdir('repository', 'work1', 'work2', 'work3')
#
test.run(chdir = 'work1', options = opts, arguments = ".",
- stderr=TestSCons.noisy_ar)
+ stderr=TestSCons.noisy_ar,
+ match=TestSCons.match_re_dotall)
test.run(program = work1_foo, stdout =
"""repository/aaa.c
""")
test.run(chdir = 'work1', options = opts, arguments = ".",
- stderr=TestSCons.noisy_ar)
+ stderr=TestSCons.noisy_ar,
+ match=TestSCons.match_re_dotall)
test.run(program = work1_foo, stdout =
"""repository/aaa.c
test.writable('repository', 1)
test.run(chdir = 'repository', options = opts, arguments = ".",
- stderr=TestSCons.noisy_ar)
+ stderr=TestSCons.noisy_ar,
+ match=TestSCons.match_re_dotall)
test.run(program = repository_foo, stdout =
"""repository/aaa.c
""")
test.run(chdir = 'work2', options = opts, arguments = ".",
- stderr=TestSCons.noisy_ar)
+ stderr=TestSCons.noisy_ar,
+ match=TestSCons.match_re_dotall)
test.run(program = work2_foo, stdout =
"""repository/aaa.c
import TestCmd
import TestSCons
-test = TestSCons.TestSCons(match=TestCmd.match_re_dotall)
+test = TestSCons.TestSCons()
test.write('SConstruct', """
import sys
}
""")
-test.run(arguments = '.', stderr=TestSCons.noisy_ar)
+test.run(arguments = '.',
+ stderr=TestSCons.noisy_ar,
+ match=TestSCons.match_re_dotall)
if os.name == 'posix':
os.environ['LD_LIBRARY_PATH'] = '.'
else:
test.run(arguments = '-f SConstructFoo', status=2, stderr='''\
scons: \*\*\* Source file: foo\..* is static and is not compatible with shared target: .*
-''')
+''',
+ match=TestSCons.match_re_dotall)
# Run it again to make sure that we still get the error
# even though the static objects already exist.
test.run(arguments = '-f SConstructFoo', status=2, stderr='''\
scons: \*\*\* Source file: foo\..* is static and is not compatible with shared target: .*
-''')
+''',
+ match=TestSCons.match_re_dotall)
-test.run(arguments = '-f SConstructFoo2', stderr=TestSCons.noisy_ar)
+test.run(arguments = '-f SConstructFoo2',
+ stderr=TestSCons.noisy_ar,
+ match=TestSCons.match_re_dotall)
if sys.platform == 'win32':
# Make sure we don't insert a .def source file (when
import sys
import TestSCons
-test = TestSCons.TestSCons(match=TestSCons.match_re_dotall)
+test = TestSCons.TestSCons()
if sys.platform == 'win32':
lib_static_lib = 'static.lib'
""")
-test.run(arguments = '.', stderr=TestSCons.noisy_ar)
+test.run(arguments = '.',
+ stderr=TestSCons.noisy_ar,
+ match=TestSCons.match_re_dotall)
test.up_to_date(arguments = '.')
import TestCmd
import TestSCons
-test = TestSCons.TestSCons(match=TestSCons.match_re_dotall)
+test = TestSCons.TestSCons()
test.subdir('simple',
'SLF',
create file4.x from file3.x
"""))
-test.run(arguments = 'SLF', stderr=TestSCons.noisy_ar)
+test.run(arguments = 'SLF',
+ stderr=TestSCons.noisy_ar,
+ match=TestSCons.match_re_dotall)
# XXX Note that the generated .h files still get scanned twice,
# once before they're generated and once after. That's the