add 'file_equal' and 'file_match'

This commit is contained in:
Johan Holmberg 2015-06-15 22:35:06 +02:00
parent 4d1fdabb55
commit 58260c5a21
2 changed files with 15 additions and 1 deletions

View File

@ -98,6 +98,12 @@ class TC_example(TestCase):
], 'utf-16')
c.stdout_match("tt", 'utf-16')
c.file_equal("abc.txt", [
'detta är abc.txtx',
'räksmörgås',
], 'utf-16')
c.file_match("abc.txt", "tt", 'utf-16')
with self.cmd("true") as c:
pass

View File

@ -63,7 +63,7 @@ def error_show(name, what, arg):
try:
msg = arg.error_msg(what)
except:
if name.startswith('stdout_') or name.startswith('stderr_'):
if re.match(r'(stdout|stderr|file)_', name):
print(what)
if len(arg) == 0:
print(" <<empty>>")
@ -231,6 +231,14 @@ class Result:
expect = ExpectFile(self, content, encoding)
expect.check("stderr_equal", self._stderr)
def file_match(self, fname, pattern, encoding='utf-8'):
expect = ExpectPattern(self, pattern, encoding)
expect.check("file_match %s" % fname, File(fname))
def file_equal(self, fname, content, encoding='utf-8'):
expect = ExpectFile(self, content, encoding)
expect.check("file_equal %s" % fname, File(fname))
TESTS = {
"created_files" : (lambda before,after: not before and after,
{"created"}),