summaryrefslogtreecommitdiff
path: root/pactest
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2008-07-24 22:14:27 -0500
committerDan McGee <dan@archlinux.org>2008-07-24 22:16:29 -0500
commitcf25884e992e9c0dd6e4bf2f7cd4bb3252578bf6 (patch)
tree430b9f5675db96ea803aa52b081547bdedc83efc /pactest
parent9f57921467ea368be96ffc09c8c35e9acfcc41ed (diff)
downloadpacman-cf25884e992e9c0dd6e4bf2f7cd4bb3252578bf6.tar.xz
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>
Diffstat (limited to 'pactest')
-rwxr-xr-xpactest/pactest.py9
-rwxr-xr-xpactest/pmenv.py34
-rwxr-xr-xpactest/pmtest.py6
-rwxr-xr-xpactest/util.py5
4 files changed, 28 insertions, 26 deletions
diff --git a/pactest/pactest.py b/pactest/pactest.py
index 7cda2556..f95ef3c1 100755
--- a/pactest/pactest.py
+++ b/pactest/pactest.py
@@ -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:
diff --git a/pactest/pmenv.py b/pactest/pmenv.py
index b86abe94..e9d0b4c9 100755
--- a/pactest/pmenv.py
+++ b/pactest/pmenv.py
@@ -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:
diff --git a/pactest/pmtest.py b/pactest/pmtest.py
index f31563b1..39f4deab 100755
--- a/pactest/pmtest.py
+++ b/pactest/pmtest.py
@@ -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:
diff --git a/pactest/util.py b/pactest/util.py
index c6d5a594..db9560fe 100755
--- a/pactest/util.py
+++ b/pactest/util.py
@@ -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: