1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/tests/test.py Sat Nov 17 18:41:01 2012 -0800
1.3 @@ -0,0 +1,60 @@
1.4 +# vim: set ts=2 sw=4 tw=99 ft=python et:
1.5 +import os
1.6 +import os.path
1.7 +
1.8 +class Result:
1.9 + def __init__(self, ok, out, err, code, timeout, message):
1.10 + self.ok = ok
1.11 + self.out = out
1.12 + self.err = err
1.13 + self.code = code
1.14 + self.timeout = timeout
1.15 + self.message = message
1.16 +
1.17 +class Test:
1.18 + def __init__(self, path, name, type):
1.19 + self.path = path
1.20 + self.name = name
1.21 + self.type = type
1.22 +
1.23 + def cmd(self):
1.24 + return os.path.join(self.path, self.name + '.sp')
1.25 +
1.26 + def compare(self, text):
1.27 + ok = True
1.28 + message = None
1.29 + with open(os.path.join(self.path, self.name + '.' + self.type)) as f:
1.30 + lines = text.split('\n')
1.31 + i = 0
1.32 + for line in f:
1.33 + line = line.rstrip('\r\n')
1.34 + if line != lines[i]:
1.35 + message = 'Got "' + lines[i] + '", expected "' + line + '"'
1.36 + ok = False
1.37 + break
1.38 + i += 1
1.39 + return (ok, message)
1.40 +
1.41 + def check(self, out, err, code, timeout):
1.42 + if not out:
1.43 + out = ''
1.44 + if not err:
1.45 + err = ''
1.46 + if self.type == 'err':
1.47 + if code == 0:
1.48 + message = 'Expected failure, got success'
1.49 + ok = False
1.50 + else:
1.51 + (ok, message) = self.compare(err)
1.52 + elif self.type == 'out':
1.53 + if code != 0:
1.54 + message = 'Expected success, got failure (code: ' + str(code) + ')'
1.55 + ok = False
1.56 + else:
1.57 + (ok, message) = self.compare(out)
1.58 +
1.59 + if timeout:
1.60 + ok = false
1.61 + message = 'timeout'
1.62 +
1.63 + return Result(ok, out, err, code, timeout, message)