2006-10-15 15:04:27 -04:00
|
|
|
#! /usr/bin/python
|
|
|
|
#
|
2007-02-22 03:06:54 -05:00
|
|
|
# pactest : run automated testing on the pacman binary
|
|
|
|
#
|
2006-10-15 15:04:27 -04:00
|
|
|
# Copyright (c) 2006 by Aurelien Foret <orelien@chez.com>
|
|
|
|
#
|
|
|
|
# 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
|
2007-12-10 23:55:22 -05:00
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2006-10-15 15:04:27 -04:00
|
|
|
|
2011-05-05 12:10:44 -04:00
|
|
|
import glob
|
2007-02-22 03:06:54 -05:00
|
|
|
from optparse import OptionParser
|
2011-05-05 12:10:44 -04:00
|
|
|
import os
|
|
|
|
import shutil
|
|
|
|
import sys
|
|
|
|
import tempfile
|
2006-10-15 15:04:27 -04:00
|
|
|
|
|
|
|
import pmenv
|
|
|
|
import util
|
|
|
|
|
|
|
|
__author__ = "Aurelien FORET"
|
2007-02-22 03:06:54 -05:00
|
|
|
__version__ = "0.4"
|
2006-10-15 15:04:27 -04:00
|
|
|
|
2007-02-22 03:06:54 -05:00
|
|
|
def resolveBinPath(option, opt_str, value, parser):
|
|
|
|
setattr(parser.values, option.dest, os.path.abspath(value))
|
2006-10-15 15:04:27 -04:00
|
|
|
|
2007-02-22 03:06:54 -05:00
|
|
|
def globTests(option, opt_str, value, parser):
|
2010-10-26 22:19:56 -04:00
|
|
|
idx = 0
|
2007-02-22 03:06:54 -05:00
|
|
|
globlist = []
|
2007-02-22 23:54:49 -05:00
|
|
|
|
|
|
|
# maintain the idx so we can modify rargs
|
2007-03-05 13:06:12 -05:00
|
|
|
while idx < len(parser.rargs) and \
|
|
|
|
not parser.rargs[idx].startswith('-'):
|
2007-02-22 23:54:49 -05:00
|
|
|
globlist += glob.glob(parser.rargs[idx])
|
|
|
|
idx += 1
|
|
|
|
|
|
|
|
parser.rargs = parser.rargs[idx:]
|
2007-02-22 03:06:54 -05:00
|
|
|
setattr(parser.values, option.dest, globlist)
|
2006-10-15 15:04:27 -04:00
|
|
|
|
2007-02-22 03:06:54 -05:00
|
|
|
def createOptParser():
|
2007-02-21 01:33:13 -05:00
|
|
|
testcases = []
|
2007-02-22 23:54:49 -05:00
|
|
|
usage = "usage: %prog [options] [[--test <path/to/testfile.py>] ...]"
|
2007-02-22 03:06:54 -05:00
|
|
|
description = "Runs automated tests on the pacman binary. Tests are " \
|
|
|
|
"described using an easy python syntax, and several can be " \
|
|
|
|
"ran at once."
|
|
|
|
parser = OptionParser(usage = usage, description = description)
|
2006-10-15 15:04:27 -04:00
|
|
|
|
2007-02-22 03:06:54 -05:00
|
|
|
parser.add_option("-v", "--verbose", action = "count",
|
|
|
|
dest = "verbose", default = 0,
|
|
|
|
help = "print verbose output")
|
|
|
|
parser.add_option("-d", "--debug", type = "int",
|
|
|
|
dest = "debug", default = 0,
|
|
|
|
help = "set debug level for pacman")
|
|
|
|
parser.add_option("-p", "--pacman", action = "callback",
|
|
|
|
callback = resolveBinPath, type = "string",
|
|
|
|
dest = "bin", default = "pacman",
|
|
|
|
help = "specify location of the pacman binary")
|
|
|
|
parser.add_option("-t", "--test", action = "callback",
|
2007-02-22 23:54:49 -05:00
|
|
|
callback = globTests, dest = "testcases",
|
2007-02-22 03:06:54 -05:00
|
|
|
help = "specify test case(s)")
|
2011-05-05 12:10:44 -04:00
|
|
|
parser.add_option("--keep-root", action = "store_true",
|
|
|
|
dest = "keeproot", default = False,
|
|
|
|
help = "don't remove the generated pacman root filesystem")
|
2007-02-22 03:06:54 -05:00
|
|
|
parser.add_option("--nolog", action = "store_true",
|
|
|
|
dest = "nolog", default = False,
|
|
|
|
help = "do not log pacman messages")
|
|
|
|
parser.add_option("--gdb", action = "store_true",
|
|
|
|
dest = "gdb", default = False,
|
|
|
|
help = "use gdb while calling pacman")
|
|
|
|
parser.add_option("--valgrind", action = "store_true",
|
|
|
|
dest = "valgrind", default = False,
|
|
|
|
help = "use valgrind while calling pacman")
|
2007-02-22 23:22:21 -05:00
|
|
|
parser.add_option("--manual-confirm", action = "store_true",
|
|
|
|
dest = "manualconfirm", default = False,
|
|
|
|
help = "do not use --noconfirm for pacman calls")
|
2007-02-22 03:06:54 -05:00
|
|
|
return parser
|
2006-10-15 15:04:27 -04:00
|
|
|
|
2007-02-22 03:06:54 -05:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
# instantiate env and parser objects
|
2011-05-05 12:10:44 -04:00
|
|
|
root_path = tempfile.mkdtemp()
|
|
|
|
env = pmenv.pmenv(root=root_path)
|
2010-10-26 22:19:56 -04:00
|
|
|
opt_parser = createOptParser()
|
|
|
|
(opts, args) = opt_parser.parse_args()
|
2006-10-15 15:04:27 -04:00
|
|
|
|
2007-02-22 03:06:54 -05:00
|
|
|
# add parsed options to env object
|
|
|
|
util.verbose = opts.verbose
|
|
|
|
env.pacman["debug"] = opts.debug
|
|
|
|
env.pacman["bin"] = opts.bin
|
|
|
|
env.pacman["nolog"] = opts.nolog
|
|
|
|
env.pacman["gdb"] = opts.gdb
|
|
|
|
env.pacman["valgrind"] = opts.valgrind
|
2007-02-22 23:22:21 -05:00
|
|
|
env.pacman["manual-confirm"] = opts.manualconfirm
|
2006-10-15 15:04:27 -04:00
|
|
|
|
2008-07-24 23:14:27 -04:00
|
|
|
if opts.testcases is None or len(opts.testcases) == 0:
|
2007-02-22 23:22:21 -05:00
|
|
|
print "no tests defined, nothing to do"
|
2011-05-05 12:10:44 -04:00
|
|
|
os.rmdir(root_path)
|
2008-07-24 23:14:27 -04:00
|
|
|
sys.exit(2)
|
2007-02-22 23:22:21 -05:00
|
|
|
|
2011-05-05 12:10:44 -04:00
|
|
|
for i in opts.testcases:
|
|
|
|
env.addtest(i)
|
|
|
|
|
|
|
|
# run tests and print overall results
|
|
|
|
env.run()
|
|
|
|
env.results()
|
2007-02-22 03:06:54 -05:00
|
|
|
|
2011-05-05 12:10:44 -04:00
|
|
|
if env.failed > 0:
|
2011-06-03 15:37:51 -04:00
|
|
|
print "pacman testing root saved: %s" % root_path
|
2011-05-05 12:10:44 -04:00
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
if not opts.keeproot:
|
|
|
|
shutil.rmtree(root_path)
|
|
|
|
else:
|
|
|
|
print "pacman testing root saved: %s" % root_path
|
2008-07-24 23:14:27 -04:00
|
|
|
|
2007-02-21 01:33:13 -05:00
|
|
|
# vim: set ts=4 sw=4 et:
|