1
0
mirror of https://github.com/moparisthebest/pacman synced 2024-12-22 07:48:50 -05:00

convert pactest to TAP output

Each test produces a single TAP result with the rules run in a sub-test.
This reduces output when run under automake and makes it possible to
continue setting expectfailure at the test level rather than per-rule.

Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com>
Signed-off-by: Allan McRae <allan@archlinux.org>
This commit is contained in:
Andrew Gregory 2013-07-29 15:22:07 -04:00 committed by Allan McRae
parent 429b956fb2
commit 1152052b3e
7 changed files with 121 additions and 59 deletions

View File

@ -26,6 +26,7 @@ import sys
import tempfile import tempfile
import pmenv import pmenv
import tap
import util import util
__author__ = "Aurelien FORET" __author__ = "Aurelien FORET"
@ -110,7 +111,7 @@ if __name__ == "__main__":
env.pacman["ldconfig"] = opts.ldconfig env.pacman["ldconfig"] = opts.ldconfig
if opts.testcases is None or len(opts.testcases) == 0: if opts.testcases is None or len(opts.testcases) == 0:
print "no tests defined, nothing to do" tap.bail("no tests defined, nothing to do")
os.rmdir(root_path) os.rmdir(root_path)
sys.exit(2) sys.exit(2)
@ -124,7 +125,7 @@ if __name__ == "__main__":
if not opts.keeproot: if not opts.keeproot:
shutil.rmtree(root_path) shutil.rmtree(root_path)
else: else:
print "pacman testing root saved: %s" % root_path tap.diag("pacman testing root saved: %s" % root_path)
if env.failed > 0: if env.failed > 0:
sys.exit(1) sys.exit(1)

View File

@ -23,6 +23,7 @@ from StringIO import StringIO
import tarfile import tarfile
import pmpkg import pmpkg
import tap
import util import util
def _getsection(fd): def _getsection(fd):
@ -105,7 +106,7 @@ class pmdb(object):
# desc # desc
filename = os.path.join(path, "desc") filename = os.path.join(path, "desc")
if not os.path.isfile(filename): if not os.path.isfile(filename):
print "invalid db entry found (desc missing) for pkg", pkgname tap.bail("invalid db entry found (desc missing) for pkg " + pkgname)
return None return None
fd = open(filename, "r") fd = open(filename, "r")
while 1: while 1:
@ -160,7 +161,7 @@ class pmdb(object):
# files # files
filename = os.path.join(path, "files") filename = os.path.join(path, "files")
if not os.path.isfile(filename): if not os.path.isfile(filename):
print "invalid db entry found (files missing) for pkg", pkgname tap.bail("invalid db entry found (files missing) for pkg " + pkgname)
return None return None
fd = open(filename, "r") fd = open(filename, "r")
while 1: while 1:

View File

@ -20,6 +20,7 @@
import os import os
import pmtest import pmtest
import tap
class pmenv(object): class pmenv(object):
@ -58,26 +59,18 @@ class pmenv(object):
def run(self): def run(self):
""" """
""" """
tap.plan(len(self.testcases))
for t in self.testcases: for t in self.testcases:
print "=========="*8 tap.diag("==========" * 8)
print "Running '%s'" % t.testname tap.diag("Running '%s'" % t.testname)
t.load() t.load()
print t.description
print "----------"*8
t.generate(self.pacman) t.generate(self.pacman)
t.run(self.pacman) t.run(self.pacman)
t.check() tap.diag("==> Checking rules")
print "==> Test result" tap.todo = t.expectfailure
if t.result["fail"] == 0: tap.subtest(lambda: t.check(), t.description)
print "\tPASS"
else:
print "\tFAIL"
print
def results(self): def results(self):
""" """
@ -109,40 +102,42 @@ class pmenv(object):
result = "[PASS]" result = "[PASS]"
else: else:
result = "[FAIL]" result = "[FAIL]"
print result, tap.diag("%s %s Rules: OK = %2u FAIL = %2u" \
print "%s Rules: OK = %2u FAIL = %2u" \ % (result, t.testname.ljust(34), success, fail))
% (t.testname.ljust(34), success, fail)
if fail != 0: if fail != 0:
# print test description if test failed # print test description if test failed
print " ", t.description tap.diag(" " + t.description)
print "=========="*8 tap.diag("==========" * 8)
print "Results" tap.diag("Results")
print "----------"*8 tap.diag("----------" * 8)
print " Passed:" tap.diag(" Passed:")
for test in tpassed: for test in tpassed:
_printtest(test) _printtest(test)
print "----------"*8 tap.diag("----------" * 8)
print " Expected Failures:" tap.diag(" Expected Failures:")
for test in texpectedfail: for test in texpectedfail:
_printtest(test) _printtest(test)
print "----------"*8 tap.diag("----------" * 8)
print " Unexpected Passes:" tap.diag(" Unexpected Passes:")
for test in tunexpectedpass: for test in tunexpectedpass:
_printtest(test) _printtest(test)
print "----------"*8 tap.diag("----------" * 8)
print " Failed:" tap.diag(" Failed:")
for test in tfailed: for test in tfailed:
_printtest(test) _printtest(test)
print "----------"*8 tap.diag("----------" * 8)
total = len(self.testcases) total = len(self.testcases)
print "Total = %3u" % total tap.diag("Total = %3u" % total)
if total: if total:
print "Pass = %3u (%6.2f%%)" % (self.passed, float(self.passed) * 100 / total) tap.diag("Pass = %3u (%6.2f%%)" % (self.passed,
print "Expected Fail = %3u (%6.2f%%)" % (self.expectedfail, float(self.expectedfail) * 100 / total) float(self.passed) * 100 / total))
print "Unexpected Pass = %3u (%6.2f%%)" % (self.unexpectedpass, float(self.unexpectedpass) * 100 / total) tap.diag("Expected Fail = %3u (%6.2f%%)" % (self.expectedfail,
print "Fail = %3u (%6.2f%%)" % (self.failed, float(self.failed) * 100 / total) float(self.expectedfail) * 100 / total))
print "" tap.diag("Unexpected Pass = %3u (%6.2f%%)" % (self.unexpectedpass,
float(self.unexpectedpass) * 100 / total))
tap.diag("Fail = %3u (%6.2f%%)" % (self.failed,
float(self.failed) * 100 / total))
# vim: set ts=4 sw=4 et: # vim: set ts=4 sw=4 et:

View File

@ -19,6 +19,7 @@
import os import os
import stat import stat
import tap
import util import util
class pmrule(object): class pmrule(object):
@ -57,12 +58,12 @@ class pmrule(object):
elif case == "OUTPUT": elif case == "OUTPUT":
logfile = os.path.join(test.root, util.LOGFILE) logfile = os.path.join(test.root, util.LOGFILE)
if not os.access(logfile, os.F_OK): if not os.access(logfile, os.F_OK):
print "LOGFILE not found, cannot validate 'OUTPUT' rule" tap.diag("LOGFILE not found, cannot validate 'OUTPUT' rule")
success = 0 success = 0
elif not util.grep(logfile, key): elif not util.grep(logfile, key):
success = 0 success = 0
else: else:
print "PACMAN rule '%s' not found" % case tap.diag("PACMAN rule '%s' not found" % case)
success = -1 success = -1
elif kind == "PKG": elif kind == "PKG":
localdb = test.db["local"] localdb = test.db["local"]
@ -108,7 +109,7 @@ class pmrule(object):
if not found: if not found:
success = 0 success = 0
else: else:
print "PKG rule '%s' not found" % case tap.diag("PKG rule '%s' not found" % case)
success = -1 success = -1
elif kind == "FILE": elif kind == "FILE":
filename = os.path.join(test.root, key) filename = os.path.join(test.root, key)
@ -148,7 +149,7 @@ class pmrule(object):
if not os.path.isfile("%s.pacsave" % filename): if not os.path.isfile("%s.pacsave" % filename):
success = 0 success = 0
else: else:
print "FILE rule '%s' not found" % case tap.diag("FILE rule '%s' not found" % case)
success = -1 success = -1
elif kind == "DIR": elif kind == "DIR":
filename = os.path.join(test.root, key) filename = os.path.join(test.root, key)
@ -156,7 +157,7 @@ class pmrule(object):
if not os.path.isdir(filename): if not os.path.isdir(filename):
success = 0 success = 0
else: else:
print "DIR rule '%s' not found" % case tap.diag("DIR rule '%s' not found" % case)
success = -1 success = -1
elif kind == "LINK": elif kind == "LINK":
filename = os.path.join(test.root, key) filename = os.path.join(test.root, key)
@ -164,7 +165,7 @@ class pmrule(object):
if not os.path.islink(filename): if not os.path.islink(filename):
success = 0 success = 0
else: else:
print "LINK rule '%s' not found" % case tap.diag("LINK rule '%s' not found" % case)
success = -1 success = -1
elif kind == "CACHE": elif kind == "CACHE":
cachedir = os.path.join(test.root, util.PM_CACHEDIR) cachedir = os.path.join(test.root, util.PM_CACHEDIR)
@ -174,7 +175,7 @@ class pmrule(object):
os.path.join(cachedir, pkg.filename())): os.path.join(cachedir, pkg.filename())):
success = 0 success = 0
else: else:
print "Rule kind '%s' not found" % kind tap.diag("Rule kind '%s' not found" % kind)
success = -1 success = -1
if self.false and success != -1: if self.false and success != -1:

View File

@ -27,6 +27,7 @@ import time
import pmrule import pmrule
import pmdb import pmdb
import pmfile import pmfile
import tap
import util import util
from util import vprint from util import vprint
@ -104,7 +105,7 @@ class pmtest(object):
raise IOError("file %s does not exist!" % self.name) raise IOError("file %s does not exist!" % self.name)
def generate(self, pacman): def generate(self, pacman):
print "==> Generating test environment" tap.diag("==> Generating test environment")
# Cleanup leftover files from a previous test session # Cleanup leftover files from a previous test session
if os.path.isdir(self.root): if os.path.isdir(self.root):
@ -192,23 +193,23 @@ class pmtest(object):
def run(self, pacman): def run(self, pacman):
if os.path.isfile(util.PM_LOCK): if os.path.isfile(util.PM_LOCK):
print "\tERROR: another pacman session is on-going -- skipping" tap.bail("\tERROR: another pacman session is on-going -- skipping")
return return
print "==> Running test" tap.diag("==> Running test")
vprint("\tpacman %s" % self.args) vprint("\tpacman %s" % self.args)
cmd = [] cmd = []
if os.geteuid() != 0: if os.geteuid() != 0:
fakeroot = util.which("fakeroot") fakeroot = util.which("fakeroot")
if not fakeroot: if not fakeroot:
print "WARNING: fakeroot not found!" tap.diag("WARNING: fakeroot not found!")
else: else:
cmd.append("fakeroot") cmd.append("fakeroot")
fakechroot = util.which("fakechroot") fakechroot = util.which("fakechroot")
if not fakechroot: if not fakechroot:
print "WARNING: fakechroot not found!" tap.diag("WARNING: fakechroot not found!")
else: else:
cmd.append("fakechroot") cmd.append("fakechroot")
@ -252,23 +253,20 @@ class pmtest(object):
# Check if the lock is still there # Check if the lock is still there
if os.path.isfile(util.PM_LOCK): if os.path.isfile(util.PM_LOCK):
print "\tERROR: %s not removed" % util.PM_LOCK tap.diag("\tERROR: %s not removed" % util.PM_LOCK)
os.unlink(util.PM_LOCK) os.unlink(util.PM_LOCK)
# Look for a core file # Look for a core file
if os.path.isfile(os.path.join(self.root, util.TMPDIR, "core")): if os.path.isfile(os.path.join(self.root, util.TMPDIR, "core")):
print "\tERROR: pacman dumped a core file" tap.diag("\tERROR: pacman dumped a core file")
def check(self): def check(self):
print "==> Checking rules" tap.plan(len(self.rules))
for i in self.rules: for i in self.rules:
success = i.check(self) success = i.check(self)
if success == 1: if success == 1:
msg = " OK "
self.result["success"] += 1 self.result["success"] += 1
else: else:
msg = "FAIL"
self.result["fail"] += 1 self.result["fail"] += 1
print "\t[%s] %s" % (msg, i) tap.ok(success, i)
# vim: set ts=4 sw=4 et: # vim: set ts=4 sw=4 et:

64
test/pacman/tap.py Normal file
View File

@ -0,0 +1,64 @@
# Copyright (c) 2013 Pacman Development Team <pacman-dev@archlinux.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
todo = None
count = 0
level = 0
failed = 0
def _output(msg):
print("%s%s" % (" "*level, msg))
def ok(ok, description=""):
global count, failed
count += 1
if not ok:
failed += 1
directive = " # TODO" if todo else ""
_output("%s %d - %s%s" % ("ok" if ok else "not ok", count,
description, directive))
def plan(count):
_output("1..%d" % (count))
def diag(msg):
_output("# %s" % (msg))
def bail(reason=""):
_output("Bail out! %s" % (reason))
def subtest(func, description=""):
global todo, count, level, failed
save_todo = todo
save_count = count
save_level = level
save_failed = failed
todo = None
count = 0
level += 1
failed = 0
func()
subtest_ok = not failed
todo = save_todo
count = save_count
level = save_level
failed = save_failed
ok(subtest_ok, description)

View File

@ -21,6 +21,8 @@ import os
import re import re
import hashlib import hashlib
import tap
SELFPATH = os.path.abspath(os.path.dirname(__file__)) SELFPATH = os.path.abspath(os.path.dirname(__file__))
# ALPM # ALPM
@ -43,7 +45,7 @@ verbose = 0
def vprint(msg): def vprint(msg):
if verbose: if verbose:
print msg tap.diag(msg)
# #
# Methods to generate files # Methods to generate files