pacman-key: rework importing distro/repo provided keyrings
[pacman-ng.git] / test / pacman / pactest.py
blobbb198eb441f0c7b5453393a94559099482417643
1 #! /usr/bin/python
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/>.
20 import glob
21 from optparse import OptionParser
22 import os
23 import shutil
24 import sys
25 import tempfile
27 import pmenv
28 import util
30 __author__ = "Aurelien FORET"
31 __version__ = "0.4"
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):
37 idx = 0
38 globlist = []
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])
44 idx += 1
46 parser.rargs = parser.rargs[idx:]
47 setattr(parser.values, option.dest, globlist)
49 def create_parser():
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 " \
53 "ran at once."
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")
84 return parser
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"
105 os.rmdir(root_path)
106 sys.exit(2)
108 for i in opts.testcases:
109 env.addtest(i)
111 # run tests and print overall results
112 env.run()
113 env.results()
115 if not opts.keeproot:
116 shutil.rmtree(root_path)
117 else:
118 print "pacman testing root saved: %s" % root_path
120 if env.failed > 0:
121 sys.exit(1)
123 # vim: set ts=4 sw=4 et: