1
0
mirror of https://github.com/moparisthebest/pacman synced 2024-12-22 15:58:50 -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["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"
sys.exit(2)
else:
for i in opts.testcases: env.addtest(i)
for i in opts.testcases:
env.addtest(i)
# run tests and print overall results
env.run()
env.results()
if env.failed > 0:
sys.exit(1)
# vim: set ts=4 sw=4 et:

View File

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

View File

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

View File

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