summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDirk Baechle <dl9obn@darc.de>2012-12-16 17:56:16 (GMT)
committerDirk Baechle <dl9obn@darc.de>2012-12-16 17:56:16 (GMT)
commit78785a796c5cb080dc6a0e7bc99c720a349b3859 (patch)
tree53e4be521ebf4c4f65c14c9e68b64b5327bf61c4
parent1bf9aa83fc024950012dd76d110443fc2d30c92a (diff)
downloadSCons-78785a796c5cb080dc6a0e7bc99c720a349b3859.zip
SCons-78785a796c5cb080dc6a0e7bc99c720a349b3859.tar.gz
SCons-78785a796c5cb080dc6a0e7bc99c720a349b3859.tar.bz2
- extended the must_contain* methods of the test framework, such that they all support user-defined find/search functions
- relaxed several of the regex comparisons for better cross-platform compatibility
-rw-r--r--QMTest/TestCommon.py31
-rw-r--r--QMTest/TestSCons.py28
-rw-r--r--test/Delete.py1
-rw-r--r--test/Errors/execute-a-directory.py47
-rw-r--r--test/Errors/non-executable-file.py38
-rw-r--r--test/Errors/nonexistent-executable.py53
-rw-r--r--test/Execute.py20
-rw-r--r--test/Install/Install.py1
-rw-r--r--test/Interactive/shell.py16
-rw-r--r--test/Object.py6
-rw-r--r--test/Repository/StaticLibrary.py11
-rw-r--r--test/scons-time/func/file.py11
12 files changed, 133 insertions, 130 deletions
diff --git a/QMTest/TestCommon.py b/QMTest/TestCommon.py
index 90aaed2..6d47149 100644
--- a/QMTest/TestCommon.py
+++ b/QMTest/TestCommon.py
@@ -286,11 +286,17 @@ class TestCommon(TestCmd):
print "Unwritable files: `%s'" % "', `".join(unwritable)
self.fail_test(missing + unwritable)
- def must_contain(self, file, required, mode = 'rb'):
+ def must_contain(self, file, required, mode = 'rb', find = None):
"""Ensures that the specified file contains the required text.
"""
file_contents = self.read(file, mode)
- contains = (file_contents.find(required) != -1)
+ if find is None:
+ def find(o, l):
+ try:
+ return o.index(l)
+ except ValueError:
+ return None
+ contains = find(file_contents, required)
if not contains:
print "File `%s' does not contain required string." % file
print self.banner('Required string ')
@@ -317,6 +323,9 @@ class TestCommon(TestCmd):
except ValueError:
return None
missing = []
+ if is_List(output):
+ output = '\n'.join(output)
+
for line in lines:
if find(output, line) is None:
missing.append(line)
@@ -415,9 +424,9 @@ class TestCommon(TestCmd):
sys.stdout.flush()
self.fail_test()
- def must_contain_lines(self, lines, output, title=None):
+ def must_contain_lines(self, lines, output, title=None, find = None):
# Deprecated; retain for backwards compatibility.
- return self.must_contain_all_lines(output, lines, title)
+ return self.must_contain_all_lines(output, lines, title, find)
def must_exist(self, *files):
"""Ensures that the specified file(s) must exist. An individual
@@ -467,11 +476,17 @@ class TestCommon(TestCmd):
self.diff(expect, file_contents, 'contents ')
raise
- def must_not_contain(self, file, banned, mode = 'rb'):
+ def must_not_contain(self, file, banned, mode = 'rb', find = None):
"""Ensures that the specified file doesn't contain the banned text.
"""
file_contents = self.read(file, mode)
- contains = (file_contents.find(banned) != -1)
+ if find is None:
+ def find(o, l):
+ try:
+ return o.index(l)
+ except ValueError:
+ return None
+ contains = find(file_contents, banned)
if contains:
print "File `%s' contains banned string." % file
print self.banner('Banned string ')
@@ -512,8 +527,8 @@ class TestCommon(TestCmd):
sys.stdout.write(output)
self.fail_test()
- def must_not_contain_lines(self, lines, output, title=None):
- return self.must_not_contain_any_line(output, lines, title)
+ 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.
diff --git a/QMTest/TestSCons.py b/QMTest/TestSCons.py
index 296af67..ea18757 100644
--- a/QMTest/TestSCons.py
+++ b/QMTest/TestSCons.py
@@ -108,7 +108,35 @@ def re_escape(str):
str = str.replace(c, '\\' + c)
return str
+#
+# Helper functions that we use as a replacement to the default re.match
+# when searching for special strings in stdout/stderr.
+#
+def search_re(out, l):
+ """ Search the regular expression 'l' in the output 'out'
+ and return the start index when successful.
+ """
+ m = re.search(l, out)
+ if m:
+ return m.start()
+
+ return None
+
+def search_re_in_list(out, l):
+ """ Search the regular expression 'l' in each line of
+ the given string list 'out' and return the line's index
+ when successful.
+ """
+ for idx, o in enumerate(out):
+ m = re.search(l, o)
+ if m:
+ return idx
+
+ return None
+#
+# Helpers for handling Python version numbers
+#
def python_version_string():
return sys.version.split()[0]
diff --git a/test/Delete.py b/test/Delete.py
index 49b4600..94ba24a 100644
--- a/test/Delete.py
+++ b/test/Delete.py
@@ -212,6 +212,7 @@ fail_strings = [
"No such file or directory",
"The system cannot find the file specified",
"The system cannot find the path specified",
+ "Das System kann die angegebene Datei nicht finden",
]
test.must_contain_any_line(test.stderr(), fail_strings)
diff --git a/test/Errors/execute-a-directory.py b/test/Errors/execute-a-directory.py
index 1b679c6..1d2036e 100644
--- a/test/Errors/execute-a-directory.py
+++ b/test/Errors/execute-a-directory.py
@@ -53,63 +53,58 @@ Bad command or file name
"""
unrecognized = """\
-'%s' is not recognized as an internal or external command,
+'.+' is not recognized as an internal or external command,
operable program or batch file.
-scons: *** [%s] Error 1
+scons: \*\*\* \[%s\] Error 1
"""
unspecified = """\
The name specified is not recognized as an
internal or external command, operable program or batch file.
-scons: *** [%s] Error 1
+scons: \*\*\* \[%s\] Error 1
"""
cannot_execute = """\
-%s: cannot execute
-scons: *** [%s] Error %s
-"""
-
-Permission_denied = """\
-%s: Permission denied
-scons: *** [%s] Error %s
+(sh: )*.+: cannot execute
+scons: \*\*\* \[%s\] Error %s
"""
permission_denied = """\
-%s: permission denied
-scons: *** [%s] Error %s
+.+: (p|P)ermission denied
+scons: \*\*\* \[%s\] Error %s
"""
is_a_directory = """\
-%s: is a directory
-scons: *** [%s] Error %s
+.+: (i|I)s a directory
+scons: \*\*\* \[%s\] Error %s
"""
-Is_a_directory = """\
-%s: Is a directory
-scons: *** [%s] Error %s
+konnte_nicht_gefunden_werden = """\
+Der Befehl ".+" ist entweder falsch geschrieben oder
+konnte nicht gefunden werden.
+scons: \*\*\* \[%s\] Error %s
"""
test.description_set("Incorrect STDERR:\n%s\n" % test.stderr())
if os.name == 'nt':
errs = [
bad_command,
- unrecognized % (test.workdir, 'f3'),
+ unrecognized % 'f3',
+ konnte_nicht_gefunden_werden % ('f3', 1),
unspecified % 'f3'
]
- test.fail_test(not test.stderr() in errs)
elif sys.platform.find('sunos') != -1:
errs = [
- cannot_execute % ('sh: %s' % test.workdir, 'f3', 1),
+ cannot_execute % ('f3', 1),
]
- test.fail_test(not test.stderr() in errs)
else:
errs = [
- cannot_execute % (not_executable, 'f3', 126),
- is_a_directory % (test.workdir, 'f3', 126),
- Is_a_directory % (test.workdir, 'f3', 126),
- Permission_denied % (test.workdir, 'f3', 126),
+ cannot_execute % ('f3', 126),
+ is_a_directory % ('f3', 126),
+ permission_denied % ('f3', 126),
]
- test.must_contain_any_line(test.stderr(), errs)
+
+test.must_contain_any_line(test.stderr(), errs, find=TestSCons.search_re)
test.pass_test()
diff --git a/test/Errors/non-executable-file.py b/test/Errors/non-executable-file.py
index db7c88a..e1b8f4e 100644
--- a/test/Errors/non-executable-file.py
+++ b/test/Errors/non-executable-file.py
@@ -42,30 +42,31 @@ Bad command or file name
"""
unrecognized = """\
-'%s' is not recognized as an internal or external command,
+'.+' is not recognized as an internal or external command,
operable program or batch file.
-scons: *** [%s] Error 1
+scons: \*\*\* \[%s\] Error 1
"""
unspecified = """\
The name specified is not recognized as an
internal or external command, operable program or batch file.
-scons: *** [%s] Error 1
+scons: \*\*\* \[%s\] Error 1
"""
cannot_execute = """\
-%s: cannot execute
-scons: *** [%s] Error %s
+(sh: )*.+: cannot execute
+scons: \*\*\* \[%s\] Error %s
"""
-Permission_denied = """\
-%s: Permission denied
-scons: *** [%s] Error %s
+permission_denied = """\
+.+: (p|P)ermission denied
+scons: \*\*\* \[%s\] Error %s
"""
-permission_denied = """\
-%s: permission denied
-scons: *** [%s] Error %s
+konnte_nicht_gefunden_werden = """\
+Der Befehl ".+" ist entweder falsch geschrieben oder
+konnte nicht gefunden werden.
+scons: \*\*\* \[%s\] Error %s
"""
test.write('SConstruct', r"""
@@ -83,22 +84,21 @@ test.description_set("Incorrect STDERR:\n%s\n" % test.stderr())
if os.name == 'nt':
errs = [
bad_command,
- unrecognized % (not_executable, 'f1'),
+ unrecognized % 'f1',
+ konnte_nicht_gefunden_werden % ('f1', 1),
unspecified % 'f1'
]
- test.fail_test(not test.stderr() in errs)
elif sys.platform.find('sunos') != -1:
errs = [
- cannot_execute % ('sh: %s' % not_executable, 'f1', 1),
+ cannot_execute % ('f1', 1),
]
- test.fail_test(not test.stderr() in errs)
else:
errs = [
- cannot_execute % (not_executable, 'f1', 126),
- Permission_denied % (not_executable, 'f1', 126),
- permission_denied % (not_executable, 'f1', 126),
+ cannot_execute % ('f1', 126),
+ permission_denied % ('f1', 126),
]
- test.must_contain_any_line(test.stderr(), errs)
+
+test.must_contain_any_line(test.stderr(), errs, find=TestSCons.search_re)
test.pass_test()
diff --git a/test/Errors/nonexistent-executable.py b/test/Errors/nonexistent-executable.py
index b9deea1..acaaaeb 100644
--- a/test/Errors/nonexistent-executable.py
+++ b/test/Errors/nonexistent-executable.py
@@ -46,58 +46,33 @@ test.run(arguments='.',
stderr = None,
status = 2)
-bad_command = """\
-Bad command or file name
-"""
-
-unrecognized = """\
-'%s' is not recognized as an internal or external command,
-operable program or batch file.
-scons: *** [%s] Error 1
-"""
-
-unspecified = """\
-The name specified is not recognized as an
-internal or external command, operable program or batch file.
-scons: *** [%s] Error 1
-"""
-
-not_found_1_space = """\
-sh: %s: not found
-scons: *** [%s] Error %s
-"""
-
-not_found_2_spaces = """\
-sh: %s: not found
-scons: *** [%s] Error %s
-"""
-
-No_such = """\
-%s: No such file or directory
-scons: *** [%s] Error %s
-"""
+bad_command = """Bad command or file name"""
+unrecognized = r"""'.+' is not recognized as an internal or external command,\s+operable program or batch file.\sscons: \*\*\* \[%s\] Error 1"""
+unspecified = r"""The name specified is not recognized as an\s+internal or external command, operable program or batch file.\s+scons: \*\*\* \[%s\] Error 1"""
+not_found_space = r"""sh: (\d: )*.+: \s*not found\s+scons: \*\*\* \[%s\] Error %s"""
+No_such = r""".+: No such file or directory\s+scons: \*\*\* \[%s\] Error %s"""
+konnte_nicht_gefunden_werden = r"""Der Befehl ".+" ist entweder falsch geschrieben oder\s+konnte nicht gefunden werden.\s+scons: \*\*\* \[%s\] Error %s"""
test.description_set("Incorrect STDERR:\n%s\n" % test.stderr())
if os.name == 'nt':
errs = [
bad_command,
- unrecognized % (no_such_file, 'f1'),
+ unrecognized % 'f1',
+ konnte_nicht_gefunden_werden % ('f1', 1),
unspecified % 'f1'
]
- test.fail_test(not test.stderr() in errs)
elif sys.platform.find('sunos') != -1:
errs = [
- not_found_1_space % (no_such_file, 'f1', 1),
+ not_found_space % ('f1', 1),
]
- test.fail_test(not test.stderr() in errs)
else:
errs = [
- not_found_1_space % (no_such_file, 'f1', 1),
- not_found_2_spaces % (no_such_file, 'f1', 1),
- not_found_1_space % (no_such_file, 'f1', 127),
- No_such % (no_such_file, 'f1', 127),
+ not_found_space % ('f1', 1),
+ not_found_space % ('f1', 127),
+ No_such % ('f1', 127),
]
- test.must_contain_any_line(test.stderr(), errs)
+
+test.must_contain_any_line(test.stderr(), errs, find=TestSCons.search_re)
test.pass_test()
diff --git a/test/Execute.py b/test/Execute.py
index 4caa4c4..2e53444 100644
--- a/test/Execute.py
+++ b/test/Execute.py
@@ -84,19 +84,17 @@ test.write('m.in', "m.in\n")
import sys
if sys.platform == 'win32':
- expect = """\
-scons: *** Error 1
-scons: *** Error 2
-scons: *** nonexistent.in/*.*: The system cannot find the path specified
-"""
+ expect = r"""scons: \*\*\* Error 1
+scons: \*\*\* Error 2
+scons: \*\*\* nonexistent.in/\*\.\*: (The system cannot find the path specified|Das System kann den angegebenen Pfad nicht finden)"""
else:
- expect = """\
-scons: *** Error 1
-scons: *** Error 2
-scons: *** nonexistent.in: No such file or directory
-"""
+ expect = r"""scons: \*\*\* Error 1
+scons: \*\*\* Error 2
+scons: \*\*\* nonexistent\.in: No such file or directory"""
+
+test.run(arguments = '.', stdout = None, stderr = None)
-test.run(arguments = '.', stderr=expect)
+test.must_contain_all_lines(test.stderr(), expect.splitlines(), find=TestSCons.search_re)
test.must_match('a.out', "a.in\n")
test.must_match('b.out', "b.in\n")
diff --git a/test/Install/Install.py b/test/Install/Install.py
index 29a8276..adadfd9 100644
--- a/test/Install/Install.py
+++ b/test/Install/Install.py
@@ -136,6 +136,7 @@ f = open(f1_out, 'rb')
expect = [
"Permission denied",
"The process cannot access the file because it is being used by another process",
+ "Der Prozess kann nicht auf die Datei zugreifen, da sie von einem anderen Prozess verwendet wird",
]
test.run(chdir = 'work', arguments = f1_out, stderr=None, status=2)
diff --git a/test/Interactive/shell.py b/test/Interactive/shell.py
index f4e89bd..842a12e 100644
--- a/test/Interactive/shell.py
+++ b/test/Interactive/shell.py
@@ -83,21 +83,21 @@ scons.send("build foo.out\n")
scons.send("\n")
if sys.platform == 'win32':
- no_such_error = "'no_such_command' is not recognized as an internal or external command,\noperable program or batch file."
+ no_such_error = r"('no_such_command' is not recognized as an internal or external command,\s+operable program or batch file\.|Der Befehl \"no_such_command\" ist entweder falsch geschrieben oder\s+konnte nicht gefunden werden\.)"
else:
no_such_error = 'scons: no_such_command: No such file or directory'
expect_stdout = """\
-scons>>> Copy("foo.out", "foo.in")
-Touch("1")
+scons>>> Copy\("foo.out", "foo.in"\)
+Touch\("1"\)
scons>>> hello from shell_command.py
-scons>>> !%(_python_)s %(_shell_command_py_)s
+scons>>> ![^"]+ ".*"
hello from shell_command.py
scons>>> hello from shell_command.py
-scons>>> shell %(_python_)s %(_shell_command_py_)s
+scons>>> shell [^"]+ ".*"
hello from shell_command.py
scons>>> hello from shell_command.py
-scons>>> sh %(_python_)s %(_shell_command_py_)s
+scons>>> sh [^"]+ ".*"
hello from shell_command.py
scons>>> %(no_such_error)s
scons>>> !no_such_command arg1 arg2
@@ -108,9 +108,9 @@ scons: `foo.out' is up to date.
scons>>>
""" % locals()
-test.finish(scons, stdout = expect_stdout)
-
+test.finish(scons, stdout = None)
+test.must_contain_all_lines(test.stdout(), expect_stdout.splitlines(), find=TestSCons.search_re)
test.pass_test()
diff --git a/test/Object.py b/test/Object.py
index 406c2c1..c07da46 100644
--- a/test/Object.py
+++ b/test/Object.py
@@ -24,13 +24,9 @@
__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
-import sys
import TestSCons
-if sys.platform == 'win32':
- _obj = '.obj'
-else:
- _obj = '.o'
+_obj = TestSCons._obj
test = TestSCons.TestSCons()
diff --git a/test/Repository/StaticLibrary.py b/test/Repository/StaticLibrary.py
index e5c76f9..4f8160c 100644
--- a/test/Repository/StaticLibrary.py
+++ b/test/Repository/StaticLibrary.py
@@ -25,17 +25,10 @@
__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
import os.path
-import sys
import TestSCons
-if sys.platform == 'win32':
- _obj = '.obj'
- _exe = '.exe'
-else:
- _obj = '.o'
- _exe = ''
-
-
+_obj = TestSCons._obj
+_exe = TestSCons._exe
test = TestSCons.TestSCons()
diff --git a/test/scons-time/func/file.py b/test/scons-time/func/file.py
index fa9d36e..1fe3513 100644
--- a/test/scons-time/func/file.py
+++ b/test/scons-time/func/file.py
@@ -76,13 +76,13 @@ r"""set title "ST2.CONF TITLE"
set key bottom left
set label 3 "label 1.5" at 0.5,0.5 right
set label 4 "label 1.6" at 0.6,0.4 right
-plot '-' title "Startup" with lines lt 1, \
- '-' notitle with lines lt 7, \
- '-' title "label 1.5" with lines lt 7, \
+plot '-' title "Startup" with lines lt 1, \\
+ '-' notitle with lines lt 7, \\
+ '-' title "label 1.5" with lines lt 7, \\
'-' title "label 1.6" with lines lt 7
# Startup
1 0.000
-2 0.000
+2 0.\d*
e
1.4 0
1.4 1
@@ -95,8 +95,9 @@ e
e
"""
-test.run(arguments = 'func --file st2.conf --fmt gnuplot', stdout = expect2)
+test.run(arguments = 'func --file st2.conf --fmt gnuplot')
+test.must_contain_exactly_lines(test.stdout(), expect2, find=TestSCons.search_re_in_list)
test.pass_test()