1
0
mirror of https://github.com/moparisthebest/pacman synced 2024-12-23 08:18:51 -05:00

pactest: exit with a non-zero error code on unexpected failure

This will allow the return code of pactest to be useful, for such things as
use in a git-bisect test script.

Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
Dan McGee 2008-07-24 22:14:27 -05:00
parent 9f57921467
commit cf25884e99
4 changed files with 28 additions and 26 deletions

View File

@ -93,13 +93,18 @@ if __name__ == "__main__":
env.pacman["valgrind"] = opts.valgrind env.pacman["valgrind"] = opts.valgrind
env.pacman["manual-confirm"] = opts.manualconfirm env.pacman["manual-confirm"] = opts.manualconfirm
if len(opts.testcases) == 0: if opts.testcases is None or len(opts.testcases) == 0:
print "no tests defined, nothing to do" print "no tests defined, nothing to do"
sys.exit(2)
else: else:
for i in opts.testcases: env.addtest(i) for i in opts.testcases:
env.addtest(i)
# run tests and print overall results # run tests and print overall results
env.run() env.run()
env.results() env.results()
if env.failed > 0:
sys.exit(1)
# vim: set ts=4 sw=4 et: # vim: set ts=4 sw=4 et:

View File

@ -27,6 +27,12 @@ class pmenv:
"""Environment object """Environment object
""" """
testcases = []
passed = 0
failed = 0
expectedfail = 0
unexpectedpass = 0
def __init__(self, root = "root"): def __init__(self, root = "root"):
self.root = os.path.abspath(root) self.root = os.path.abspath(root)
self.pacman = { self.pacman = {
@ -36,7 +42,6 @@ class pmenv:
"valgrind": 0, "valgrind": 0,
"nolog": 0 "nolog": 0
} }
self.testcases = []
def __str__(self): def __str__(self):
return "root = %s\n" \ return "root = %s\n" \
@ -47,8 +52,7 @@ class pmenv:
""" """
""" """
if not os.path.isfile(testcase): if not os.path.isfile(testcase):
err("file %s not found" % testcase) raise IOError("test file %s not found" % testcase)
return
test = pmtest.pmtest(testcase, self.root) test = pmtest.pmtest(testcase, self.root)
self.testcases.append(test) self.testcases.append(test)
@ -84,27 +88,23 @@ class pmenv:
def results(self): def results(self):
""" """
""" """
passed = 0
tpassed = [] tpassed = []
failed = 0
tfailed = [] tfailed = []
expectedfail = 0
texpectedfail = [] texpectedfail = []
unexpectedpass = 0
tunexpectedpass = [] tunexpectedpass = []
for test in self.testcases: for test in self.testcases:
fail = test.result["fail"] fail = test.result["fail"]
if fail == 0 and not test.expectfailure: if fail == 0 and not test.expectfailure:
passed += 1 self.passed += 1
tpassed.append(test) tpassed.append(test)
elif fail != 0 and test.expectfailure: elif fail != 0 and test.expectfailure:
expectedfail += 1 self.expectedfail += 1
texpectedfail.append(test) texpectedfail.append(test)
elif fail == 0: # and not test.expectfail elif fail == 0: # and not test.expectfail
unexpectedpass += 1 self.unexpectedpass += 1
tunexpectedpass.append(test) tunexpectedpass.append(test)
else: else:
failed += 1 self.failed += 1
tfailed.append(test) tfailed.append(test)
def _printtest(t): def _printtest(t):
@ -142,13 +142,13 @@ class pmenv:
total = len(self.testcases) total = len(self.testcases)
print "Total = %3u" % total print "Total = %3u" % total
if total: if total:
print "Pass = %3u (%6.2f%%)" % (passed, float(passed) * 100 / total) print "Pass = %3u (%6.2f%%)" % (self.passed, float(self.passed) * 100 / total)
print "Expected Fail = %3u (%6.2f%%)" % (expectedfail, float(expectedfail) * 100 / total) print "Expected Fail = %3u (%6.2f%%)" % (self.expectedfail, float(self.expectedfail) * 100 / total)
print "Unexpected Pass = %3u (%6.2f%%)" % (unexpectedpass, float(unexpectedpass) * 100 / total) print "Unexpected Pass = %3u (%6.2f%%)" % (self.unexpectedpass, float(self.unexpectedpass) * 100 / total)
print "Fail = %3u (%6.2f%%)" % (failed, float(failed) * 100 / total) print "Fail = %3u (%6.2f%%)" % (self.failed, float(self.failed) * 100 / total)
print "" print ""
if __name__ == "__main__": if __name__ == "__main__":
env = pmenv("/tmp") pass
print env
# vim: set ts=4 sw=4 et: # vim: set ts=4 sw=4 et:

View File

@ -95,7 +95,7 @@ class pmtest:
if os.path.isfile(self.name): if os.path.isfile(self.name):
execfile(self.name) execfile(self.name)
else: else:
err("file %s does not exist!" % self.name) raise IOerror("file %s does not exist!" % self.name)
def generate(self): def generate(self):
""" """
@ -268,6 +268,6 @@ class pmtest:
if __name__ == "__main__": if __name__ == "__main__":
test = pmtest("test1", "./root") pass
print test
# vim: set ts=4 sw=4 et: # vim: set ts=4 sw=4 et:

View File

@ -43,10 +43,6 @@ LOGFILE = "var/log/pactest.log"
verbose = 0 verbose = 0
def err(msg):
print "error: " + msg
sys.exit(1)
def vprint(msg): def vprint(msg):
if verbose: if verbose:
print msg print msg
@ -273,4 +269,5 @@ def mkdir(dir):
if __name__ == "__main__": if __name__ == "__main__":
pass pass
# vim: set ts=4 sw=4 et: # vim: set ts=4 sw=4 et: