* Updated German translation
[pacman.git] / pactest / pactest.py
blobd2a091969773da090392a20397d245252446e4fe
1 #! /usr/bin/python
3 # pactest : run automated testing on the pacman binary
5 # Copyright (c) 2006 by Aurelien Foret <orelien@chez.com>
6 #
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
20 # USA.
22 import os, sys, glob
23 from optparse import OptionParser
25 import pmenv
26 import util
28 __author__ = "Aurelien FORET"
29 __version__ = "0.4"
31 def resolveBinPath(option, opt_str, value, parser):
32 setattr(parser.values, option.dest, os.path.abspath(value))
34 def globTests(option, opt_str, value, parser):
35 idx=0
36 globlist = []
38 # maintain the idx so we can modify rargs
39 while idx < len(parser.rargs) and \
40 not parser.rargs[idx].startswith('-'):
41 globlist += glob.glob(parser.rargs[idx])
42 idx += 1
44 parser.rargs = parser.rargs[idx:]
45 setattr(parser.values, option.dest, globlist)
47 def createOptParser():
48 testcases = []
49 usage = "usage: %prog [options] [[--test <path/to/testfile.py>] ...]"
50 description = "Runs automated tests on the pacman binary. Tests are " \
51 "described using an easy python syntax, and several can be " \
52 "ran at once."
53 parser = OptionParser(usage = usage, description = description)
55 parser.add_option("-v", "--verbose", action = "count",
56 dest = "verbose", default = 0,
57 help = "print verbose output")
58 parser.add_option("-d", "--debug", type = "int",
59 dest = "debug", default = 0,
60 help = "set debug level for pacman")
61 parser.add_option("-p", "--pacman", action = "callback",
62 callback = resolveBinPath, type = "string",
63 dest = "bin", default = "pacman",
64 help = "specify location of the pacman binary")
65 parser.add_option("-t", "--test", action = "callback",
66 callback = globTests, dest = "testcases",
67 help = "specify test case(s)")
68 parser.add_option("--nolog", action = "store_true",
69 dest = "nolog", default = False,
70 help = "do not log pacman messages")
71 parser.add_option("--gdb", action = "store_true",
72 dest = "gdb", default = False,
73 help = "use gdb while calling pacman")
74 parser.add_option("--valgrind", action = "store_true",
75 dest = "valgrind", default = False,
76 help = "use valgrind while calling pacman")
77 parser.add_option("--manual-confirm", action = "store_true",
78 dest = "manualconfirm", default = False,
79 help = "do not use --noconfirm for pacman calls")
80 return parser
83 if __name__ == "__main__":
84 # instantiate env and parser objects
85 env = pmenv.pmenv()
86 parser = createOptParser()
87 (opts, args) = parser.parse_args()
89 # add parsed options to env object
90 util.verbose = opts.verbose
91 env.pacman["debug"] = opts.debug
92 env.pacman["bin"] = opts.bin
93 env.pacman["nolog"] = opts.nolog
94 env.pacman["gdb"] = opts.gdb
95 env.pacman["valgrind"] = opts.valgrind
96 env.pacman["manual-confirm"] = opts.manualconfirm
98 if len(opts.testcases) == 0:
99 print "no tests defined, nothing to do"
100 else:
101 for i in opts.testcases: env.addtest(i)
103 # run tests and print overall results
104 env.run()
105 env.results()
107 # vim: set ts=4 sw=4 et: