test.must_contain('file', 'required text\n')
- test.must_contain_lines(lines, output)
+ test.must_contain_all_lines(output, lines, ['title', find])
+
+ test.must_contain_any_line(output, lines, ['title', find])
test.must_exist('file1', ['file2', ...])
test.must_not_be_writable('file1', ['file2', ...])
- test.must_not_contain_lines(lines, output)
+ test.must_not_contain_any_line(output, lines, ['title', find])
test.must_not_exist('file1', ['file2', ...])
print file_contents
self.fail_test(not contains)
- def must_contain_lines(self, lines, output, title=None):
- if title is None:
- title = 'output'
-
- missing = filter(lambda l, o=output: string.find(o, l) == -1, lines)
+ def must_contain_all_lines(self, output, lines, title=None, find=None):
+ if find is None:
+ find = lambda o, l: string.find(o, l) != -1
+ missing = []
+ for line in lines:
+ if not find(output, line):
+ missing.append(line)
if missing:
- print "Missing lines from %s:" % title
- print string.join(missing, '\n')
- print "%s ============================================================" % title
- print output
+ if title is None:
+ title = 'output'
+ sys.stdout.write("Missing expected lines from %s:\n" % title)
+ for line in missing:
+ sys.stdout.write(' ' + repr(line) + '\n')
+ separator = title + ' ' + '=' * (78 - len(title) - 1)
+ sys.stdout.write(separator + '\n')
+ sys.stdout.write(output)
self.fail_test()
+ def must_contain_any_line(self, output, lines, title=None, find=None):
+ if find is None:
+ find = lambda o, l: string.find(o, l) != -1
+ for line in lines:
+ if find(output, line):
+ return
+
+ if title is None:
+ title = 'output'
+ sys.stdout.write("Missing any expected line from %s:\n" % title)
+ for line in lines:
+ sys.stdout.write(' ' + repr(line) + '\n')
+ separator = title + ' ' + '=' * (78 - len(title) - 1)
+ sys.stdout.write(separator + '\n')
+ sys.stdout.write(output)
+ self.fail_test()
+
+ def must_contain_lines(self, lines, output, title=None):
+ # Deprecated; retain for backwards compatibility.
+ return self.must_contain_all_lines(output, lines, title)
+
def must_exist(self, *files):
"""Ensures that the specified file(s) must exist. An individual
file be specified as a list of directory names, in which case the
self.diff(expect, file_contents, 'contents ')
raise
- def must_not_contain_lines(self, lines, output=None, title=None):
- if title is None:
- title = 'output'
-
- unexpected = filter(lambda l, o=output: string.find(o, l) != -1, lines)
+ def must_not_contain_any_line(self, output, lines, title=None, find=None):
+ if find is None:
+ find = lambda o, l: string.find(o, l) != -1
+ unexpected = []
+ for line in lines:
+ if find(output, line):
+ unexpected.append(line)
if unexpected:
- print "Unexpected lines in %s:" % title
- print string.join(unexpected, '\n')
- print "%s ============================================================" % title
- print output
+ if title is None:
+ title = 'output'
+ sys.stdout.write("Unexpected lines in %s:\n" % title)
+ for line in unexpected:
+ sys.stdout.write(' ' + repr(line) + '\n')
+ separator = title + ' ' + '=' * (78 - len(title) - 1)
+ sys.stdout.write(separator + '\n')
+ sys.stdout.write(output)
self.fail_test()
+ def must_not_contain_lines(self, lines, output, title=None, find=None):
+ return self.must_not_contain_any_line(output, lines, title, find)
+
def must_not_exist(self, *files):
"""Ensures that the specified file(s) must not exist.
An individual file be specified as a list of directory names, in
else:
return os.path.splitext(path)
- def must_contain_all_lines(self, name, content, expected, exists=None):
- missing_lines = []
-
- if exists is None:
- exists = lambda e, c: string.find(c, e) != -1
-
- for e in expected:
- if not exists(e, content):
- missing_lines.append(e)
-
- if missing_lines:
- sys.stdout.write('%s is missing expected string(s):\n' % name)
- for m in missing_lines:
- sys.stdout.write(' ' + repr(m) + '\n')
- sys.stdout.write('%s content:\n' % name)
- sys.stdout.write(content)
- self.fail_test()
-
def fake_logfile(self, logfile_name, index=0):
self.write(self.workpath(logfile_name), logfile_contents % locals())
"""
import TestSCons
-import string
_python_ = TestSCons._python_
test.run()
expect = 'Archiving output.lib from file.1 file.2'
-test.fail_test(string.find(test.stdout(), expect) == -1)
-
+test.must_contain_all_lines(test.stdout(), [expect])
test.must_match('output.lib', "file.1\nfile.2\n")
test.run(arguments="-Q case=2", stderr=None)
expect = 'strip.py: %s' % test.workpath('test1.exe')
-test.fail_test(string.find(test.stdout(), expect) == -1)
+test.must_contain_all_lines(test.stdout(), [expect])
test.pass_test()
__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
-import sys, string
+import sys
import TestSCons
test = TestSCons.TestSCons()
print env.subst('$SHCXXCOMSTR')
""")
test.run(arguments = '.')
-test.fail_test(string.find(test.stdout(), "-xyz") != -1)
-test.fail_test(string.find(test.stdout(), "-abc") == -1)
+test.must_not_contain_any_line(test.stdout(), ["-xyz"])
+test.must_contain_all_lines(test.stdout(), ["-abc"])
# Test passing CFLAGS to C compiler by actually compiling programs
]
test.run(arguments = '-c clean=0')
-test.must_not_contain_lines(lines, test.stdout())
+test.must_not_contain_any_line(test.stdout(), lines)
test.run(arguments = '-c clean=1')
-test.must_contain_lines(lines, test.stdout())
+test.must_contain_all_lines(test.stdout(), lines)
test.run(arguments = '--clean clean=0')
-test.must_not_contain_lines(lines, test.stdout())
+test.must_not_contain_any_line(test.stdout(), lines)
test.run(arguments = '--clean clean=1')
-test.must_contain_lines(lines, test.stdout())
+test.must_contain_all_lines(test.stdout(), lines)
test.pass_test()
# The help setting should have no effect on -H, so the -H output
# should never contain the lines.
test.run(arguments = '-H help=0')
-test.must_not_contain_lines(lines, test.stdout())
+test.must_not_contain_any_line(test.stdout(), lines)
test.run(arguments = '-H help=1')
-test.must_not_contain_lines(lines, test.stdout())
+test.must_not_contain_any_line(test.stdout(), lines)
# For -h and --help, the lines appear or not depending on how Configure()
# is initialized.
test.run(arguments = '-h help=0')
-test.must_not_contain_lines(lines, test.stdout())
+test.must_not_contain_any_line(test.stdout(), lines)
test.run(arguments = '-h help=1')
-test.must_contain_lines(lines, test.stdout())
+test.must_contain_all_lines(test.stdout(), lines)
test.run(arguments = '--help help=0')
-test.must_not_contain_lines(lines, test.stdout())
+test.must_not_contain_any_line(test.stdout(), lines)
test.run(arguments = '--help help=1')
-test.must_contain_lines(lines, test.stdout())
+test.must_contain_all_lines(test.stdout(), lines)
test.pass_test()
"""
import os.path
-import string
import TestSCons
test.run(status=2, stderr=None)
-stderr = test.stderr()
-test.fail_test(string.find(stderr, "No such file or directory") == -1 and
- string.find(stderr, "The system cannot find the path specified") == -1)
+fail_strings = [
+ "No such file or directory",
+ "The system cannot find the path specified",
+]
+
+test.must_contain_any_line(test.stderr(), fail_strings)
test.pass_test()
import TestSCons
import sys
-import string
import re
import time
test.run(arguments = "--debug=dtree foo.xxx",
stderr = stderr)
-test.fail_test(string.find(test.stdout(), dtree1) == -1)
+test.must_contain_all_lines(test.stdout(), [dtree1])
dtree2 = """
+-.
"""
test.run(arguments = "--debug=dtree .",
stderr = stderr)
-test.fail_test(string.find(test.stdout(), dtree2) == -1)
+test.must_contain_all_lines(test.stdout(), [dtree2])
# Make sure we print the debug stuff even if there's a build failure.
test.write('bar.h', """
test.run(arguments = "--debug=dtree foo.xxx",
status = 2,
stderr = None)
-test.fail_test(string.find(test.stdout(), dtree1) == -1)
+test.must_contain_all_lines(test.stdout(), [dtree1])
test.pass_test()
import TestSCons
import sys
-import string
import re
import time
test.run(arguments = "--debug=tree Foo.xxx",
stderr = stderr)
-if string.find(test.stdout(), tree1) == -1:
- sys.stdout.write('Did not find expected tree in the following output:\n')
- sys.stdout.write(test.stdout())
- test.fail_test()
+test.must_contain_all_lines(test.stdout(), tree1)
tree2 = """
+-.
test.run(arguments = "--debug=tree .",
stderr = stderr)
-if string.find(test.stdout(), tree2) == -1:
- sys.stdout.write('Did not find expected tree in the following output:\n')
- sys.stdout.write(test.stdout())
- test.fail_test()
+test.must_contain_all_lines(test.stdout(), tree2)
# Make sure we print the debug stuff even if there's a build failure.
test.write('Bar.h', """
test.run(arguments = "--debug=tree Foo.xxx",
status = 2,
stderr = None)
-if string.find(test.stdout(), tree1) == -1:
- sys.stdout.write('Did not find expected tree in the following output:\n')
- sys.stdout.write(test.stdout())
- test.fail_test()
+test.must_contain_all_lines(test.stdout(), tree1)
test.pass_test()
__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
import os
-import string
import sys
+
import TestSCons
_python_ = TestSCons._python_
test.run()
-test.fail_test(string.find(test.stdout(), "LIST: foo%sbar"%os.pathsep) == -1)
-test.fail_test(string.find(test.stdout(), "FOO: foo") == -1)
+expect = [
+ "LIST: foo%sbar" % os.pathsep,
+ "FOO: foo",
+]
+
+test.must_contain_all_lines(test.stdout(), expect)
test.pass_test()
__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
-import string
-
import TestSCons
test = TestSCons.TestSCons(match = TestSCons.match_re_dotall)
stdout = test.stdout()
expect = "scons: `foo.out' is up to date."
-
-if string.find(stdout, expect) == -1:
- print "Did not find expected string %s" % repr(expect)
- print "STDOUT ======================================================="
- print stdout
- test.fail_test()
+test.must_contain_all_lines(test.stdout(), [expect])
test.pass_test()
Permission_denied % (test.workdir, 'f3'),
Permission_denied % (test.workdir, 'f3'),
]
- error_message_not_found = 1
- for err in errs:
- if string.find(test.stderr(), err) != -1:
- error_message_not_found = None
- break
- test.fail_test(error_message_not_found)
+ test.must_contain_any_line(test.stderr(), errs)
test.pass_test()
Permission_denied % (not_executable, 'f1'),
permission_denied % (not_executable, 'f1'),
]
- error_message_not_found = 1
- for err in errs:
- if string.find(test.stderr(), err) != -1:
- error_message_not_found = None
- break
- test.fail_test(error_message_not_found)
+ test.must_contain_any_line(test.stderr(), errs)
test.pass_test()
not_found_127 % (no_such_file, 'f1'),
No_such % (no_such_file, 'f1'),
]
- error_message_not_found = 1
- for err in errs:
- if string.find(test.stderr(), err) != -1:
- error_message_not_found = None
- break
- test.fail_test(error_message_not_found)
+ test.must_contain_any_line(test.stderr(), errs)
test.pass_test()
classdir attribute at all).
"""
-import string
-
import TestSCons
test = TestSCons.TestSCons()
foo/bar/b.class
"""
-if string.find(test.stdout(), expect) == -1:
- print "Did not find expected string in standard output."
- print "Expected =========================================================="
- print expect
- print "Output ============================================================"
- print test.stdout()
- test.fail_test()
+test.must_contain_all_lines(test.stdout(), [expect])
classes/foo/bar/b.class
"""
-if string.find(test.stdout(), expect) == -1:
- print "Did not find expected string in standard output."
- print "Expected =========================================================="
- print expect
- print "Output ============================================================"
- print test.stdout()
- test.fail_test()
+test.must_contain_all_lines(test.stdout(), [expect])
Test the PRINT_CMD_LINE_FUNC construction variable.
"""
-import string
import sys
import TestCmd
import TestSCons
"BUILDING prog%s from prog%s with" % (_exe, _obj),
]
-missing_lines = filter(lambda l: string.find(test.stdout(), l) == -1,
- expected_lines)
-if missing_lines:
- print "Expected the following lines in STDOUT:"
- print "\t" + string.join(expected_lines, "\n\t")
- print "ACTUAL STDOUT =========="
- print test.stdout()
- test.fail_test(1)
+test.must_contain_all_lines(test.stdout(), expected_lines)
test.run(arguments = '-c .')
__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
import os.path
-import string
import TestSCons
test.run(status=2, stderr=None)
-test.fail_test(string.find(test.stderr(), "No such file or directory") == -1)
+test.must_contain_all_lines(test.stderr(), ["No such file or directory"])
test.pass_test()
Test building Java applications when using Repositories.
"""
-import string
-
import TestSCons
python = TestSCons.python
test.run(chdir = 'work1', options = opts, arguments = ".")
-test.fail_test(string.find(test.stdout(), ' src/Foo1.java src/Foo2.java') == -1)
-test.fail_test(string.find(test.stdout(), ' com.sub.foo.Foo1 com.sub.foo.Foo2') == -1)
+expect = [
+ ' src/Foo1.java src/Foo2.java',
+ ' com.sub.foo.Foo1 com.sub.foo.Foo2',
+]
+
+test.must_contain_all_lines(test.stdout(), expect)
# XXX I'd rather run the resulting class files through the JVM here to
# see that they were built from the proper work1 sources, but I don't
cat(["sub/all"], ["sub/ddd.out", "sub/eee.out", "sub/fff.out"])
""", '\n')
-stdout = test.stdout()
-missing = filter(lambda l, s=stdout: string.find(s, l) == -1, lines)
-if missing:
- print "Missing the following output lines:"
- print string.join(missing, '\n')
- print "Actual STDOUT =========="
- print stdout
- test.fail_test(1)
+test.must_contain_all_lines(test.stdout(), lines)
test.must_match('all', """\
s.aaa.in aaa.in
cat(["sub/all"], ["sub/ddd.out", "sub/eee.out", "sub/fff.out"])
""", '\n')
-stdout = test.stdout()
-missing = filter(lambda l, s=stdout: string.find(s, l) == -1, lines)
-if missing:
- print "Missing the following output lines:"
- print string.join(missing, '\n')
- print "Actual STDOUT =========="
- print stdout
- test.fail_test(1)
+test.must_contain_all_lines(test.stdout(), lines)
test.must_match('all', """\
%F% aaa.in
sccs get foo.h
""", '\n')
-stdout = test.stdout()
-missing = filter(lambda l, s=stdout: string.find(s, l) == -1, lines)
-if missing:
- print "Missing the following output lines:"
- print string.join(missing, '\n')
- print "Actual STDOUT =========="
- print stdout
- test.fail_test(1)
+test.must_contain_all_lines(test.stdout(), lines)
cat(["sub/all"], ["sub/ddd.out", "sub/eee.out", "sub/fff.out"])
""", '\n')
-stdout = test.stdout()
-missing = filter(lambda l, s=stdout: string.find(s, l) == -1, lines)
-if missing:
- print "Missing the following output lines:"
- print string.join(missing, '\n')
- print "Actual STDOUT =========="
- print stdout
- test.fail_test(1)
+test.must_contain_all_lines(test.stdout(), lines)
test.must_match('all', """\
s.aaa.in aaa.in
__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
import os
-import string
import TestCmd
import TestSCons
# for the deprecation warning.
test.run(arguments = "-H")
-test.fail_test(string.find(test.stdout(), 'Help text.') >= 0)
-test.fail_test(string.find(test.stdout(), '-H, --help-options') == -1)
+test.must_not_contain_any_line(test.stdout(), ['Help text.'])
+test.must_contain_all_lines(test.stdout(), ['-H, --help-options'])
os.environ['SCONSFLAGS'] = '-Z'
when the -j option is used.
"""
-import string
-
import TestSCons
_python_ = TestSCons._python_
test.run(arguments = "-j 4 .")
-stdout = test.stdout()
-
build_lines = [
'build.py h1.in h1.out',
'build.py f3.in f3.out',
]
-missing = []
-for line in build_lines:
- if string.find(stdout, line) == -1:
- missing.append(line)
-
-if missing:
- print "===== standard output is missing the following lines:"
- print string.join(missing, '\n')
- print "===== STDOUT ========================================"
- print stdout
- test.fail_test()
-
-
-log = test.read('log.txt')
+test.must_contain_all_lines(test.stdout(), build_lines)
log_lines = [
'f3.in -> f3.out',
'g2.in -> g2.out',
]
-missing = []
-for line in log_lines:
- if string.find(log, line) == -1:
- missing.append(line)
-
-if missing:
- print "===== log file 'log.txt' is missing the following lines:"
- print string.join(missing, '\n')
- print "===== STDOUT ==========================================="
- print log
- test.fail_test()
+test.must_contain_all_lines(test.read('log.txt'), log_lines)
test.pass_test()
Test configuration contributed by Christopher Drexler.
"""
-import string
-
import TestSCons
test = TestSCons.TestSCons()
test.run(arguments = '-c .')
x = "Could not remove 'simple.aux': No such file or directory"
-test.fail_test(string.find(test.stdout(), x) != -1)
+test.must_not_contain_any_line(test.stdout(), [x])
test.must_not_exist(test.workpath('simple.aux'))
test.must_not_exist(test.workpath('simple.bbl'))
Test configuration courtesy Joel B. Mohler.
"""
-import string
-
import TestSCons
test = TestSCons.TestSCons()
test.run(arguments = '-c .')
x = "Could not remove 'no_index.aux': No such file or directory"
-test.fail_test(string.find(test.stdout(), x) != -1)
+test.must_not_contain_any_line(test.stdout(), [x])
x = "Could not remove 'simple.aux': No such file or directory"
-test.fail_test(string.find(test.stdout(), x) != -1)
+test.must_not_contain_any_line(test.stdout(), [x])
test.must_not_exist(test.workpath('simple.aux'))
test.must_not_exist(test.workpath('simple.idx'))
Also verifies that package warnings are caught and re-run as needed.
"""
-import string
-
import TestSCons
test = TestSCons.TestSCons()
test.must_exist(['work1', 'foo.bbl'])
foo_log = test.read(['work1', 'foo.log'])
- if string.find(foo_log, 'undefined references') != -1:
- print 'foo.log contains "undefined references":'
- print foo_log
- test.fail_test(1)
+ test.must_not_contain_any_line(foo_log, ['undefined references'], 'foo.log')
test.write(['work3', 'SConstruct'], """\
import os
test.run(chdir = 'work3', arguments = '.')
foo_log = test.read(['work3', 'foo3.log'])
- if string.find(foo_log, 'Rerun LaTeX') != -1:
- print 'foo.log contains "Rerun LaTeX":'
- print foo_log
- test.fail_test(1)
+ test.must_not_contain_any_line(foo_log, ['Rerun LaTeX'], 'foo3.log')
test.must_exist(['work2', 'foo.bbl'])
foo_log = test.read(['work2', 'foo.log'])
- if string.find(foo_log, 'undefined references') != -1:
- print 'foo.log contains "undefined references":'
- print foo_log
- test.fail_test(1)
+ test.must_not_contain_any_line(foo_log, ['undefined references'], 'foo.log')
test.write(['work3', 'SConstruct'], """\
import os
test.run(chdir = 'work3', arguments = '.')
foo_log = test.read(['work3', 'foo3.log'])
- if string.find(foo_log, 'Rerun LaTeX') != -1:
- print 'foo.log contains "Rerun LaTeX":'
- print foo_log
- test.fail_test(1)
+ test.must_not_contain_any_line(foo_log, ['Rerun LaTeX'], 'foo3.log')
test.write(['work4', 'SConstruct'], """\
import os
import re
-import string
import sys
import TestSCons
import TestCmd
out3 = """create\\(\\["f3.out"\\], \\[<.*.Custom instance at """
#" <- unconfuses emacs syntax highlighting
- test.fail_test(string.find(test.stdout(), out1) == -1)
- test.fail_test(string.find(test.stdout(), out2) == -1)
- test.fail_test(string.find(test.stdout(), out7) == -1)
- test.fail_test(string.find(test.stdout(), out8) == -1)
+ test.must_contain_all_lines(test.stdout(), [out1, out2, out7, out8])
test.fail_test(re.search(out3, test.stdout()) == None)
test.must_match('f1.out', "/usr/local")
out5 = """create(["f2.out"], [4])"""
out6 = """create\\(\\["f3.out"\\], \\[<.*.Custom instance at """
#" <- unconfuses emacs syntax highlighting
- test.fail_test(string.find(test.stdout(), out4) == -1)
- test.fail_test(string.find(test.stdout(), out5) == -1)
+ test.must_contain_all_lines(test.stdout(), [out4, out5])
test.fail_test(re.search(out6, test.stdout()) == None)
test.must_match('f1.out', "/usr")
test.run(arguments='prefix=/var')
out4 = """create(["f1.out"], ['/var'])"""
- test.fail_test(string.find(test.stdout(), out4) == -1)
- test.fail_test(string.find(test.stdout(), out5) != -1)
- test.fail_test(string.find(test.stdout(), out7) == -1)
- test.fail_test(string.find(test.stdout(), out8) == -1)
+ test.must_contain_all_lines(test.stdout(), [out4, out7, out8])
+ test.must_not_contain_any_line(test.stdout(), [out5])
test.fail_test(re.search(out6, test.stdout()) == None)
test.up_to_date('prefix=/var', '.')
__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
import os
-import string
import sys
+
import TestSCons
_python_ = TestSCons._python_
""")
test.run(status=2, stderr=None)
-err = test.stderr()
-test.fail_test(string.find(err, 'Exception') != -1 or \
- string.find(err, 'Traceback') != -1)
+test.must_not_contain_any_line(test.stderr(), ['Exception', 'Traceback'])
# Test ETOOLONG (arg list too long). This is not in exitvalmap,
"""%long_cmd)
test.run(status=2, stderr=None)
-err = test.stderr()
-test.fail_test(string.find(err, 'Exception') != -1 or \
- string.find(err, 'Traceback') != -1)
+
+test.must_not_contain_any_line(test.stderr(), ['Exception', 'Traceback'])
+
# Python 1.5.2 on a FC3 system doesn't even get to the exitvalmap
# because it fails with "No such file or directory." Just comment
# this out for now, there are plenty of other good tests below.
-#test.fail_test(string.find(err, "too long") == -1 and # posix
-# string.find(err, "nvalid argument") == -1) # win32
+#expected = [
+# "too long", # posix
+# "nvalid argument", # win32
+#]
+#test.must_contain_any_line(test.stderr(), expected)
# Test bad shell ('./one' is a dir, so it can't be used as a shell).
""")
test.run(status=2, stderr=None)
-err = test.stderr()
-if string.find(err, 'Exception') != -1 or string.find(err, 'Traceback') != -1:
- print "Exception or Traceback found in the following error output:"
- print err
- test.fail_test()
-if string.find(err, 'ermission') == -1 and string.find(err, 'such file') == -1:
- print "Missing '[Pp]ermission' or 'such file' string in the following error output:"
- print err
- test.fail_test()
+test.must_not_contain_any_line(test.stderr(), ['Exception', 'Traceback'])
+expect = [
+ 'No such file',
+ 'Permission denied',
+ 'permission denied',
+]
+test.must_contain_any_line(test.stderr(), expect)
# Test command with exit status -1.
""")
test.run(status=2, stderr=None)
-err = test.stderr()
-test.fail_test(string.find(err, 'Exception') != -1 or \
- string.find(err, 'Traceback') != -1)
+test.must_not_contain_any_line(test.stderr(), ['Exception', 'Traceback'])
# Test SConscript with errors and an atexit function.
""")
test.run(status=2, stderr=None)
-err = test.stderr()
-test.fail_test(string.find(err, 'Exception') != -1 or \
- string.find(err, 'Traceback') != -1)
+test.must_not_contain_any_line(test.stderr(), ['Exception', 'Traceback'])
# No tests failed; OK.
that we look up.
"""
-import string
-
import TestSCons
test = TestSCons.TestSCons()
test.run()
test.run(arguments='--diskcheck=match', status=2, stderr=None)
-test.fail_test(string.find(test.stderr(), "found where file expected") == -1)
+test.must_contain_all_lines(test.stderr(), ["found where file expected"])
test.run()
test.run(arguments='--diskcheck=match', status=2, stderr=None)
-test.fail_test(string.find(test.stderr(), "found where directory expected") == -1)
+test.must_contain_all_lines(test.stderr(), ["found where directory expected"])
test.run()
test.run(arguments='--diskcheck=match', status=2, stderr=None)
-test.fail_test(string.find(test.stderr(), "found where directory expected") == -1)
+test.must_contain_all_lines(test.stderr(), ["found where directory expected"])
import os
import re
-import string
import sys
import TestSCons
import TestCmd
test.run(arguments = '-j7 -k .', status = 2, stderr = None)
-missing = []
-for es in expected_stderr_list:
- if string.find(test.stderr(), es) == -1:
- missing.append(es)
-
-if missing:
- sys.stderr.write("Missing the following lines from stderr:\n")
- for m in missing:
- sys.stderr.write(m)
- sys.stderr.write('STDERR ===============================================\n')
- sys.stderr.write(test.stderr())
- test.fail_test(1)
+test.must_contain_all_lines(test.stderr(), expected_stderr_list)
test.pass_test()
builder that produces multiple targets.
"""
-import string
-
import TestSCons
test = TestSCons.TestSCons()
test.must_exist('x.a')
test.must_exist('x.b')
-test.fail_test(string.find(test.stdout(), 'Copy') == -1)
+test.must_contain_all_lines(test.stdout(), ['Copy'])
# Double check that targets are not rebuilt.
test.run(arguments = '.')
test.must_exist('x.a')
test.must_exist('x.b')
-test.fail_test(string.find(test.stdout(), 'Copy') != -1)
+test.must_not_contain_any_line(test.stdout(), ['Copy'])
# Double check that targets are not rebuilt even with --implicit-cache
test.run(arguments = '--implicit-cache x.a')
test.must_exist('x.a')
test.must_exist('x.b')
-test.fail_test(string.find(test.stdout(), 'Copy') != -1)
+test.must_not_contain_any_line(test.stdout(), ['Copy'])
# Double check that targets are not rebuilt even with --implicit-cache
# a second time.
test.must_exist('x.a')
test.must_exist('x.b')
-test.fail_test(string.find(test.stdout(), 'Copy') != -1)
+test.must_not_contain_any_line(test.stdout(), ['Copy'])
# Double check that targets are not rebuilt if we reran without
# --implicit-cache
test.must_exist('x.a')
test.must_exist('x.b')
-test.fail_test(string.find(test.stdout(), 'Copy') != -1)
+test.must_not_contain_any_line(test.stdout(), ['Copy'])
# Double check again
test.run(arguments = '.')
test.must_exist('x.a')
test.must_exist('x.b')
-test.fail_test(string.find(test.stdout(), 'Copy') != -1)
+test.must_not_contain_any_line(test.stdout(), ['Copy'])
# Then only of the targets using --implicit-cache
test.pass_test()
a subset of the targets need to be rebuilt.
"""
-import string
-
import TestSCons
test = TestSCons.TestSCons()
# Build everything first.
test.run(arguments = 'duplicate=False view_all_dependencies=True .')
test.must_exist('build/dir1/x.cpp')
-test.fail_test(string.find(test.stdout(), "`.' is up to date.") != -1)
+test.must_not_contain_any_line(test.stdout(), ["`.' is up to date."])
# Double check that targets are not rebuilt.
test.run(arguments = 'duplicate=False view_all_dependencies=True .')
test.must_exist('build/dir1/x.cpp')
-test.fail_test(string.find(test.stdout(), "`.' is up to date.") == -1)
+test.must_contain_all_lines(test.stdout(), ["`.' is up to date."])
# Clean-up only the object file
test.run(arguments = 'duplicate=False view_all_dependencies=False -c .')
# Rebuild the only object file without seeing all the dependencies.
test.run(arguments = 'duplicate=False view_all_dependencies=False .')
test.must_exist('build/dir1/x.cpp')
-test.fail_test(string.find(test.stdout(), "`.' is up to date.") != -1)
+test.must_not_contain_any_line(test.stdout(), ["`.' is up to date."])
# Double check that targets are not rebuilt without and with all the
# dependencies.
test.run(arguments = 'duplicate=False view_all_dependencies=False .')
test.must_exist('build/dir1/x.cpp')
-test.fail_test(string.find(test.stdout(), "`.' is up to date.") == -1)
+test.must_contain_all_lines(test.stdout(), ["`.' is up to date."])
test.run(arguments = 'duplicate=False view_all_dependencies=True .')
test.must_exist('build/dir1/x.cpp')
-test.fail_test(string.find(test.stdout(), "`.' is up to date.") == -1)
+test.must_contain_all_lines(test.stdout(), ["`.' is up to date."])
# Clean-up everything.
test.run(arguments = 'duplicate=False view_all_dependencies=True -c .')
# # Build everything first.
# test.run(arguments = 'duplicate=True view_all_dependencies=True .')
# test.must_exist('build/dir1/x.cpp')
-# test.fail_test(string.find(test.stdout(), "`.' is up to date.") != -1)
+# test.must_not_contain_any_line(test.stdout(), ["`.' is up to date."])
# # Double check that targets are not rebuilt.
# test.run(arguments = 'duplicate=True view_all_dependencies=True .')
# test.must_exist('build/dir1/x.cpp')
-# test.fail_test(string.find(test.stdout(), "`.' is up to date.") == -1)
+# test.must_contain_all_lines(test.stdout(), ["`.' is up to date."])
# # Clean-up only the object file
# test.run(arguments = 'duplicate=True view_all_dependencies=False -c .')
# # Rebuild the only object file without seeing all the dependencies.
# test.run(arguments = 'duplicate=True view_all_dependencies=False .')
# test.must_exist('build/dir1/x.cpp')
-# test.fail_test(string.find(test.stdout(), "`.' is up to date.") != -1)
+# test.must_not_contain_any_line(test.stdout(), ["`.' is up to date."])
# # Double check that targets are not rebuilt without and with all the
# # dependencies.
# test.run(arguments = 'duplicate=True view_all_dependencies=False .')
# test.must_exist('build/dir1/x.cpp')
-# test.fail_test(string.find(test.stdout(), "`.' is up to date.") == -1)
+# test.must_contain_all_lines(test.stdout(), ["`.' is up to date."])
# test.run(arguments = 'duplicate=True view_all_dependencies=True .')
# test.must_exist('build/dir1/x.cpp')
-# test.fail_test(string.find(test.stdout(), "`.' is up to date.") == -1)
+# test.must_contain_all_lines(test.stdout(), ["`.' is up to date."])
# # Clean-up everything.
# test.run(arguments = 'duplicate=True view_all_dependencies=True -c .')
"""scons: warning: parallel builds are unsupported by this version of Python;
\tignoring -j or num_jobs option.
"""
-test.fail_test(string.find(test.stderr(), warn) == -1)
+test.must_contain_all_lines(test.stderr(), [warn])
str = test.read("f1")
start1,finish1 = map(float, string.split(str, "\n"))
import TestSCons
import sys
-import string
import re
import time
"""
test.run(arguments = "--debug=includes foo.obj")
-if string.find(test.stdout(), includes) == -1:
- print "Did not find expected string in standard output."
- print "Expected =========================================================="
- print includes
- print "Actual ============================================================"
- print test.stdout()
- test.fail_test()
+test.must_contain_all_lines(test.stdout(), [includes])
#test.run(arguments = "--debug=includes foo.exe",
# status = 2,
# stderr = None)
-#test.fail_test(string.find(test.stdout(), includes) == -1)
+#test.must_contain_all_lines(test.stdout(), [includes])
import os
import new
-import string
-
import TestSCons
test = TestSCons.TestSCons(match = TestSCons.match_re_dotall)
def run_and_check(test, args, desc):
test.run(arguments = args)
- stdout = test.stdout()
- missing = filter(lambda e, s=stdout: string.find(s, e) == -1, expect)
- if missing:
- print "Missing the following strings in the %s output:" % desc
- print " " + string.join(missing, "\n ")
- print "STDOUT ============"
- print stdout
- test.fail_test()
+ test.must_contain_any_line(test.stdout(), expect)
else:
def run_and_check(test, args, desc):
test.run(arguments = args, stderr = expect_no_metaclasses)
- stdout = test.stdout()
- present = filter(lambda e, s=stdout: string.find(s, e) != -1, expect)
- if present:
- print "The following unexpected strings are present in the %s output:" % desc
- print " " + string.join(present, "\n ")
- print "STDOUT ============"
- print stdout
- test.fail_test()
+ test.must_contain_not_contain_any_line(test.stdout(), expect)
for args in ['-h --debug=memoizer', '--debug=memoizer']:
__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
-import string
-
import TestSCons
test = TestSCons.TestSCons()
""")
test.run(arguments = "--debug=pdb", stdin = "n\ns\nq\n")
-test.fail_test(string.find(test.stdout(), "(Pdb)") == -1)
-test.fail_test(string.find(test.stdout(), "SCons") == -1)
+test.must_contain_all_lines(test.stdout(), ["(Pdb)", "SCons"])
test.pass_test()
"""
import TestSCons
-import sys
-import string
-import re
-import time
test = TestSCons.TestSCons()
-def must_contain_all_lines(content, lines):
- missing = filter(lambda l, c=content: string.find(c, l) == -1, lines)
- if missing:
- return [
- "Missing the following lines:\n",
- "\t" + string.join(missing, "\n\t") + "\n",
- "Output =====\n",
- content
- ]
- return None
-
-
-
test.write('SConstruct', """\
def kfile_scan(node, env, target):
raise Exception, "kfile_scan error"
'raise Exception, "kfile_scan error"',
]
-err = must_contain_all_lines(test.stderr(), lines)
-if err:
- print string.join(err, '')
- test.fail_test(1)
+test.must_contain_all_lines(test.stderr(), lines)
status = 2,
stderr = None)
-lines = [
+user_error_lines = [
'UserError: explicit UserError!',
'scons: *** explicit UserError!',
]
# The "(most recent call last)" message is used by more recent Python
# versions than the "(innermost last)" message, so that's the one
# we report if neither matches.
-recent_lines = [ "Traceback (most recent call last)" ] + lines
-inner_lines = [ "Traceback (innermost last)" ] + lines
-
-err = must_contain_all_lines(test.stderr(), recent_lines)
-if err and must_contain_all_lines(test.stderr(), inner_lines):
- print string.join(err, '')
- test.fail_test(1)
-
+traceback_lines = [
+ "Traceback (most recent call last)",
+ "Traceback (innermost last)",
+]
+test.must_contain_all_lines(test.stderr(), user_error_lines)
+test.must_contain_any_line(test.stderr(), traceback_lines)
# Test that full path names to SConscript files show up in stack traces.
' File "%s", line 1:' % test.workpath('SConstruct'),
]
-err = must_contain_all_lines(test.stderr(), lines)
-if err:
- print string.join(err, '')
- test.fail_test(1)
+test.must_contain_all_lines(test.stderr(), lines)
__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
-import string
-
import TestSCons
test = TestSCons.TestSCons()
test.run(arguments = '-h')
-test.fail_test(string.find(test.stdout(), '-h, --help') == -1)
+test.must_contain_all_lines(test.stdout(), ['-h, --help'])
test.run(arguments = '-u -h')
-test.fail_test(string.find(test.stdout(), '-h, --help') == -1)
+test.must_contain_all_lines(test.stdout(), ['-h, --help'])
test.run(arguments = '-U -h')
-test.fail_test(string.find(test.stdout(), '-h, --help') == -1)
+test.must_contain_all_lines(test.stdout(), ['-h, --help'])
test.run(arguments = '-D -h')
-test.fail_test(string.find(test.stdout(), '-h, --help') == -1)
+test.must_contain_all_lines(test.stdout(), ['-h, --help'])
test.write('SConstruct', "")
test.run(arguments = '-h')
-test.fail_test(string.find(test.stdout(), '-h, --help') == -1)
+test.must_contain_all_lines(test.stdout(), ['-h, --help'])
test.run(arguments = '-u -h')
-test.fail_test(string.find(test.stdout(), '-h, --help') == -1)
+test.must_contain_all_lines(test.stdout(), ['-h, --help'])
test.run(arguments = '-U -h')
-test.fail_test(string.find(test.stdout(), '-h, --help') == -1)
+test.must_contain_all_lines(test.stdout(), ['-h, --help'])
test.run(arguments = '-D -h')
-test.fail_test(string.find(test.stdout(), '-h, --help') == -1)
+test.must_contain_all_lines(test.stdout(), ['-h, --help'])
test.pass_test()
test.run(arguments = '-H')
-test.fail_test(string.find(test.stdout(), '-H, --help-options') == -1)
-test.fail_test(string.find(test.stdout(), '--debug=TYPE') == -1)
+expect = [
+ '-H, --help-options',
+ '--debug=TYPE',
+]
+test.must_contain_all_lines(test.stdout(), expect)
# Validate that the help output lists the options in case-insensitive
# alphabetical order.
scons_prof = test.workpath('scons.prof')
test.run(arguments = "--profile=%s -h" % scons_prof)
-test.fail_test(string.find(test.stdout(), 'usage: scons [OPTION]') == -1)
+test.must_contain_all_lines(test.stdout(), ['usage: scons [OPTION]'])
try:
save_stdout = sys.stdout
finally:
sys.stdout = save_stdout
-test.fail_test(string.find(s, 'Main.py') == -1)
-test.fail_test(string.find(s, '_main') == -1)
+test.must_contain_all_lines(s, ['Main.py', '_main'])
finally:
sys.stdout = save_stdout
-test.fail_test(string.find(s, 'Main.py') == -1)
-test.fail_test(string.find(s, '_main') == -1)
-test.fail_test(string.find(s, 'FS.py') == -1)
+test.must_contain_all_lines(s, ['Main.py', '_main', 'FS.py'])
scons_prof = test.workpath('scons3.prof')
test.run(arguments = "--profile %s --debug=memory -h" % scons_prof)
-test.fail_test(string.find(test.stdout(), 'usage: scons [OPTION]') == -1)
-test.fail_test(string.find(test.stdout(), 'Options:') == -1)
+expect = [
+ 'usage: scons [OPTION]',
+ 'Options:'
+]
+test.must_contain_all_lines(test.stdout(), expect)
expect = 'Memory before reading SConscript files'
lines = string.split(test.stdout(), '\n')
""" % locals()
test.run(arguments = "--tree=all .")
-if string.find(test.stdout(), tree2) == -1:
- sys.stdout.write('Did not find expected tree in the following output:\n')
- sys.stdout.write(test.stdout())
- test.fail_test()
+test.must_contain_all_lines(test.stdout(), [tree2])
tree3 = """
+-.
import TestSCons
import sys
-import string
import re
import time
"""
test.run(arguments = "--tree=derived foo.xxx")
-test.fail_test(string.find(test.stdout(), dtree1) == -1)
+test.must_contain_all_lines(test.stdout(), [dtree1])
dtree2 = """
+-.
"""
test.run(arguments = "--tree=derived .")
-test.fail_test(string.find(test.stdout(), dtree2) == -1)
+test.must_contain_all_lines(test.stdout(), [dtree2])
dtree3 = """
+-.
"""
test.run(arguments = "--tree=derived,prune .")
-test.fail_test(string.find(test.stdout(), dtree3) == -1)
+test.must_contain_all_lines(test.stdout(), [dtree3])
dtree4 = """
E = exists
test.run(arguments = '-c foo.xxx')
test.run(arguments = "--no-exec --tree=derived,status foo.xxx")
-test.fail_test(string.find(test.stdout(), dtree4) == -1)
+test.must_contain_all_lines(test.stdout(), [dtree4])
# Make sure we print the debug stuff even if there's a build failure.
test.write('bar.h', """
test.run(arguments = "--tree=derived foo.xxx",
status = 2,
stderr = None)
-test.fail_test(string.find(test.stdout(), dtree1) == -1)
+test.must_contain_all_lines(test.stdout(), [dtree1])
test.pass_test()
Issue 1363: http://scons.tigris.org/issues/show_bug.cgi?id=1363
"""
-import string
import sys
import TestSCons
"""
test.run(arguments = '--tree=derived foo.h')
-if string.find(test.stdout(), expect) == -1:
- sys.stdout.write('Did not find expected tree in the following output:\n')
- sys.stdout.write(test.stdout())
- test.fail_test()
+test.must_contain_all_lines(test.stdout(), [expect])
test.up_to_date(arguments = 'foo.h')
"""
import os
-import string
import TestSCons
test.fail_test( not os.popen('rpm -qpl %s' % src_rpm).read()=='foo-1.2.3.spec\nfoo-1.2.3.tar.gz\n')
expect = '(0755, root, users) /bin/main'
-test.fail_test(string.find(test.read('foo-1.2.3.spec'), expect) == -1)
+test.must_contain_all_lines(test.read('foo-1.2.3.spec'), [expect])
test.pass_test()
test.run(arguments = 'func -h')
-test.must_contain_all_lines('Standard output', test.stdout(), expect)
+test.must_contain_all_lines(test.stdout(), expect)
test.run(arguments = 'func -?')
-test.must_contain_all_lines('Standard output', test.stdout(), expect)
+test.must_contain_all_lines(test.stdout(), expect)
test.run(arguments = 'func --help')
-test.must_contain_all_lines('Standard output', test.stdout(), expect)
+test.must_contain_all_lines(test.stdout(), expect)
test.run(arguments = 'help func')
-test.must_contain_all_lines('Standard output', test.stdout(), expect)
+test.must_contain_all_lines(test.stdout(), expect)
test.pass_test()
test.run(arguments = 'help')
-test.must_contain_all_lines('Standard output', test.stdout(), expect)
+test.must_contain_all_lines(test.stdout(), expect)
test.pass_test()
test.run(arguments = 'help')
-test.must_contain_all_lines('Standard output', test.stdout(), expect)
+test.must_contain_all_lines(test.stdout(), expect)
test.run(arguments = '-h')
-test.must_contain_all_lines('Standard output', test.stdout(), expect)
+test.must_contain_all_lines(test.stdout(), expect)
test.run(arguments = '-?')
-test.must_contain_all_lines('Standard output', test.stdout(), expect)
+test.must_contain_all_lines(test.stdout(), expect)
test.run(arguments = '--help')
-test.must_contain_all_lines('Standard output', test.stdout(), expect)
+test.must_contain_all_lines(test.stdout(), expect)
test.pass_test()
test.run(arguments = 'mem -h')
-test.must_contain_all_lines('Standard output', test.stdout(), expect)
+test.must_contain_all_lines(test.stdout(), expect)
test.run(arguments = 'mem -?')
-test.must_contain_all_lines('Standard output', test.stdout(), expect)
+test.must_contain_all_lines(test.stdout(), expect)
test.run(arguments = 'mem --help')
-test.must_contain_all_lines('Standard output', test.stdout(), expect)
+test.must_contain_all_lines(test.stdout(), expect)
test.run(arguments = 'help mem')
-test.must_contain_all_lines('Standard output', test.stdout(), expect)
+test.must_contain_all_lines(test.stdout(), expect)
test.pass_test()
test.run(arguments = 'obj -h')
-test.must_contain_all_lines('Standard output', test.stdout(), expect)
+test.must_contain_all_lines(test.stdout(), expect)
test.run(arguments = 'obj -?')
-test.must_contain_all_lines('Standard output', test.stdout(), expect)
+test.must_contain_all_lines(test.stdout(), expect)
test.run(arguments = 'obj --help')
-test.must_contain_all_lines('Standard output', test.stdout(), expect)
+test.must_contain_all_lines(test.stdout(), expect)
test.run(arguments = 'help obj')
-test.must_contain_all_lines('Standard output', test.stdout(), expect)
+test.must_contain_all_lines(test.stdout(), expect)
test.pass_test()
content = test.read(test.workpath('foo-321-2.log'))
-test.must_contain_all_lines('foo-617-2.log', content, expect, re.search)
+def re_find(content, line):
+ return re.search(line, content)
+test.must_contain_all_lines(content, expect, 'foo-617-2.log', re_find)
test.pass_test()
test.run(arguments = 'run -h')
-test.must_contain_all_lines('Standard output', test.stdout(), expect)
+test.must_contain_all_lines(test.stdout(), expect)
test.run(arguments = 'run -?')
-test.must_contain_all_lines('Standard output', test.stdout(), expect)
+test.must_contain_all_lines(test.stdout(), expect)
test.run(arguments = 'run --help')
-test.must_contain_all_lines('Standard output', test.stdout(), expect)
+test.must_contain_all_lines(test.stdout(), expect)
test.run(arguments = 'help run')
-test.must_contain_all_lines('Standard output', test.stdout(), expect)
+test.must_contain_all_lines(test.stdout(), expect)
test.pass_test()
content = test.read(test.workpath('foo-617-2.log'), mode='r')
-test.must_contain_all_lines('foo-617-2.log', content, expect, re.search)
+def re_find(content, line):
+ return re.search(line, content)
+test.must_contain_all_lines(content, expect, 'foo-617-2.log', re_find)
test.pass_test()
test.run(arguments = 'time -h')
-test.must_contain_all_lines('Standard output', test.stdout(), expect)
+test.must_contain_all_lines(test.stdout(), expect)
test.run(arguments = 'time -?')
-test.must_contain_all_lines('Standard output', test.stdout(), expect)
+test.must_contain_all_lines(test.stdout(), expect)
test.run(arguments = 'time --help')
-test.must_contain_all_lines('Standard output', test.stdout(), expect)
+test.must_contain_all_lines(test.stdout(), expect)
test.run(arguments = 'help time')
-test.must_contain_all_lines('Standard output', test.stdout(), expect)
+test.must_contain_all_lines(test.stdout(), expect)
test.pass_test()
Verify appropriate printing of "is up to date" messages.
"""
-import string
-
import TestSCons
_python_ = TestSCons._python_
]
test.run(options = '-j4 f1.out f2.out f3.out f4.out')
-stdout = test.stdout()
-
-missing = []
-for line in expected_lines:
- if string.find(stdout, line) == -1:
- missing.append(line)
-if missing:
- print "Missing the following expected lines:"
- for line in missing:
- print line
- print "STDOUT =========="
- print stdout
- test.fail_test()
+test.must_contain_all_lines(test.stdout(), expected_lines)
test.pass_test()