3 # pactest : run automated testing on the pacman binary
5 # Copyright (c) 2006 by Aurelien Foret <orelien@chez.com>
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, see <http://www.gnu.org/licenses/>.
21 from optparse
import OptionParser
26 __author__
= "Aurelien FORET"
29 def resolveBinPath(option
, opt_str
, value
, parser
):
30 setattr(parser
.values
, option
.dest
, os
.path
.abspath(value
))
32 def globTests(option
, opt_str
, value
, parser
):
36 # maintain the idx so we can modify rargs
37 while idx
< len(parser
.rargs
) and \
38 not parser
.rargs
[idx
].startswith('-'):
39 globlist
+= glob
.glob(parser
.rargs
[idx
])
42 parser
.rargs
= parser
.rargs
[idx
:]
43 setattr(parser
.values
, option
.dest
, globlist
)
45 def createOptParser():
47 usage
= "usage: %prog [options] [[--test <path/to/testfile.py>] ...]"
48 description
= "Runs automated tests on the pacman binary. Tests are " \
49 "described using an easy python syntax, and several can be " \
51 parser
= OptionParser(usage
= usage
, description
= description
)
53 parser
.add_option("-v", "--verbose", action
= "count",
54 dest
= "verbose", default
= 0,
55 help = "print verbose output")
56 parser
.add_option("-d", "--debug", type = "int",
57 dest
= "debug", default
= 0,
58 help = "set debug level for pacman")
59 parser
.add_option("-p", "--pacman", action
= "callback",
60 callback
= resolveBinPath
, type = "string",
61 dest
= "bin", default
= "pacman",
62 help = "specify location of the pacman binary")
63 parser
.add_option("-t", "--test", action
= "callback",
64 callback
= globTests
, dest
= "testcases",
65 help = "specify test case(s)")
66 parser
.add_option("--nolog", action
= "store_true",
67 dest
= "nolog", default
= False,
68 help = "do not log pacman messages")
69 parser
.add_option("--gdb", action
= "store_true",
70 dest
= "gdb", default
= False,
71 help = "use gdb while calling pacman")
72 parser
.add_option("--valgrind", action
= "store_true",
73 dest
= "valgrind", default
= False,
74 help = "use valgrind while calling pacman")
75 parser
.add_option("--manual-confirm", action
= "store_true",
76 dest
= "manualconfirm", default
= False,
77 help = "do not use --noconfirm for pacman calls")
81 if __name__
== "__main__":
82 # instantiate env and parser objects
84 parser
= createOptParser()
85 (opts
, args
) = parser
.parse_args()
87 # add parsed options to env object
88 util
.verbose
= opts
.verbose
89 env
.pacman
["debug"] = opts
.debug
90 env
.pacman
["bin"] = opts
.bin
91 env
.pacman
["nolog"] = opts
.nolog
92 env
.pacman
["gdb"] = opts
.gdb
93 env
.pacman
["valgrind"] = opts
.valgrind
94 env
.pacman
["manual-confirm"] = opts
.manualconfirm
96 if opts
.testcases
is None or len(opts
.testcases
) == 0:
97 print "no tests defined, nothing to do"
100 for i
in opts
.testcases
:
103 # run tests and print overall results
110 # vim: set ts=4 sw=4 et: