summaryrefslogtreecommitdiffstats
path: root/QMTest
diff options
context:
space:
mode:
authorGreg Noel <GregNoel@tigris.org>2010-05-01 04:42:33 (GMT)
committerGreg Noel <GregNoel@tigris.org>2010-05-01 04:42:33 (GMT)
commit8c0690bceff753ce1dea6f5e14cce1a8e0af30f5 (patch)
tree8d3da1d925e17b981246ea30afe977aa83c340e6 /QMTest
parentb6a7a7b274ca097cdc2cb1eed68afe083e4c1953 (diff)
downloadSCons-8c0690bceff753ce1dea6f5e14cce1a8e0af30f5.zip
SCons-8c0690bceff753ce1dea6f5e14cce1a8e0af30f5.tar.gz
SCons-8c0690bceff753ce1dea6f5e14cce1a8e0af30f5.tar.bz2
Add test routine to exactly match a set of lines no matter the order
Diffstat (limited to 'QMTest')
-rw-r--r--QMTest/TestCommon.py52
1 files changed, 52 insertions, 0 deletions
diff --git a/QMTest/TestCommon.py b/QMTest/TestCommon.py
index fcd3e70..6ee2bd5 100644
--- a/QMTest/TestCommon.py
+++ b/QMTest/TestCommon.py
@@ -40,6 +40,8 @@ provided by the TestCommon class:
test.must_contain_any_line(output, lines, ['title', find])
+ test.exactly_contain_all_lines(output, lines, ['title', find])
+
test.must_exist('file1', ['file2', ...])
test.must_match('file', "expected contents\n")
@@ -304,6 +306,56 @@ class TestCommon(TestCmd):
sys.stdout.write(output)
self.fail_test()
+ def exactly_contain_all_lines(self, output, expect, title=None, find=None):
+ """Ensures that the specified output string (first argument)
+ contains all of the lines in the expected string (second argument)
+ with none left over.
+
+ An optional third argument can be used to describe the type
+ of output being searched, and only shows up in failure output.
+
+ An optional fourth argument can be used to supply a different
+ function, of the form "find(line, output), to use when searching
+ for lines in the output.
+ """
+ out = output.splitlines()
+ exp = expect.splitlines()
+ if sorted(out) == sorted(exp):
+ # early out for exact match
+ return
+ if find is None:
+ def find(o, l):
+ try:
+ return o.index(l)
+ except:
+ return None
+ missing = []
+ for line in exp:
+ found = find(out, line)
+ if found is None:
+ missing.append(line)
+ else:
+ out.pop(found)
+
+ if not missing and not out:
+ # all lines were matched
+ return
+
+ if title is None:
+ title = 'output'
+ if missing:
+ sys.stdout.write("Missing expected lines from %s:\n" % title)
+ for line in missing:
+ sys.stdout.write(' ' + repr(line) + '\n')
+ sys.stdout.write(self.banner('missing %s ' % title))
+ if out:
+ sys.stdout.write("Extra unexpected lines from %s:\n" % title)
+ for line in out:
+ sys.stdout.write(' ' + repr(line) + '\n')
+ sys.stdout.write(self.banner('extra %s ' % title))
+ sys.stdout.flush()
+ 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)