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
30 __author__
= "Aurelien FORET"
33 def resolve_binary_path(option
, opt_str
, value
, parser
):
34 setattr(parser
.values
, option
.dest
, os
.path
.abspath(value
))
36 def glob_tests(option
, opt_str
, value
, parser
):
40 # maintain the idx so we can modify rargs
41 while idx
< len(parser
.rargs
) and \
42 not parser
.rargs
[idx
].startswith('-'):
43 globlist
+= glob
.glob(parser
.rargs
[idx
])
46 parser
.rargs
= parser
.rargs
[idx
:]
47 setattr(parser
.values
, option
.dest
, globlist
)
50 usage
= "usage: %prog [options] [[--test <path/to/testfile.py>] ...]"
51 description
= "Runs automated tests on the pacman binary. Tests are " \
52 "described using an easy python syntax, and several can be " \
54 parser
= OptionParser(usage
= usage
, description
= description
)
56 parser
.add_option("-v", "--verbose", action
= "count",
57 dest
= "verbose", default
= 0,
58 help = "print verbose output")
59 parser
.add_option("-d", "--debug", type = "int",
60 dest
= "debug", default
= 0,
61 help = "set debug level for pacman")
62 parser
.add_option("-p", "--pacman", action
= "callback",
63 callback
= resolve_binary_path
, type = "string",
64 dest
= "bin", default
= "pacman",
65 help = "specify location of the pacman binary")
66 parser
.add_option("-t", "--test", action
= "callback",
67 callback
= glob_tests
, dest
= "testcases",
68 help = "specify test case(s)")
69 parser
.add_option("--keep-root", action
= "store_true",
70 dest
= "keeproot", default
= False,
71 help = "don't remove the generated pacman root filesystem")
72 parser
.add_option("--nolog", action
= "store_true",
73 dest
= "nolog", default
= False,
74 help = "do not log pacman messages")
75 parser
.add_option("--gdb", action
= "store_true",
76 dest
= "gdb", default
= False,
77 help = "use gdb while calling pacman")
78 parser
.add_option("--valgrind", action
= "store_true",
79 dest
= "valgrind", default
= False,
80 help = "use valgrind while calling pacman")
81 parser
.add_option("--manual-confirm", action
= "store_true",
82 dest
= "manualconfirm", default
= False,
83 help = "do not use --noconfirm for pacman calls")
87 if __name__
== "__main__":
88 # instantiate env and parser objects
89 root_path
= tempfile
.mkdtemp()
90 env
= pmenv
.pmenv(root
=root_path
)
91 opt_parser
= create_parser()
92 (opts
, args
) = opt_parser
.parse_args()
94 # add parsed options to env object
95 util
.verbose
= opts
.verbose
96 env
.pacman
["debug"] = opts
.debug
97 env
.pacman
["bin"] = opts
.bin
98 env
.pacman
["nolog"] = opts
.nolog
99 env
.pacman
["gdb"] = opts
.gdb
100 env
.pacman
["valgrind"] = opts
.valgrind
101 env
.pacman
["manual-confirm"] = opts
.manualconfirm
103 if opts
.testcases
is None or len(opts
.testcases
) == 0:
104 print "no tests defined, nothing to do"
108 for i
in opts
.testcases
:
111 # run tests and print overall results
115 if not opts
.keeproot
:
116 shutil
.rmtree(root_path
)
118 print "pacman testing root saved: %s" % root_path
123 # vim: set ts=4 sw=4 et: