]> wolfpit.net Git - tool/Arch-pacman/.git/blob - test/pacman/pactest.py
pactest: remove results summary
[tool/Arch-pacman/.git] / test / pacman / pactest.py
1 #! /usr/bin/python2
2 #
3 # pactest : run automated testing on the pacman binary
4 #
5 # Copyright (c) 2006 by Aurelien Foret <orelien@chez.com>
6 # Copyright (c) 2006-2013 Pacman Development Team <pacman-dev@archlinux.org>
7 #
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2 of the License, or
11 # (at your option) any later version.
12 #
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20
21 import glob
22 from optparse import OptionParser
23 import os
24 import shutil
25 import sys
26 import tempfile
27
28 import pmenv
29 import tap
30 import util
31
32 __author__ = "Aurelien FORET"
33 __version__ = "0.4"
34
35 def resolve_binary_path(option, opt_str, value, parser):
36 setattr(parser.values, option.dest, os.path.abspath(value))
37
38 def create_parser():
39 usage = "usage: %prog [options] <path/to/testfile.py>..."
40 description = "Runs automated tests on the pacman binary. Tests are " \
41 "described using an easy python syntax, and several can be " \
42 "ran at once."
43 parser = OptionParser(usage = usage, description = description)
44
45 parser.add_option("-v", "--verbose", action = "count",
46 dest = "verbose", default = 0,
47 help = "print verbose output")
48 parser.add_option("-d", "--debug", type = "int",
49 dest = "debug", default = 0,
50 help = "set debug level for pacman")
51 parser.add_option("-p", "--pacman", action = "callback",
52 callback = resolve_binary_path, type = "string",
53 dest = "bin", default = "pacman",
54 help = "specify location of the pacman binary")
55 parser.add_option("--keep-root", action = "store_true",
56 dest = "keeproot", default = False,
57 help = "don't remove the generated pacman root filesystem")
58 parser.add_option("--nolog", action = "store_true",
59 dest = "nolog", default = False,
60 help = "do not log pacman messages")
61 parser.add_option("--gdb", action = "store_true",
62 dest = "gdb", default = False,
63 help = "use gdb while calling pacman")
64 parser.add_option("--valgrind", action = "store_true",
65 dest = "valgrind", default = False,
66 help = "use valgrind while calling pacman")
67 parser.add_option("--manual-confirm", action = "store_true",
68 dest = "manualconfirm", default = False,
69 help = "do not use --noconfirm for pacman calls")
70 parser.add_option("--scriptlet-shell", type = "string",
71 dest = "scriptletshell", default = "/bin/sh",
72 help = "specify path to shell used for install scriptlets")
73 parser.add_option("--ldconfig", type = "string",
74 dest = "ldconfig", default = "/sbin/ldconfig",
75 help = "specify path to ldconfig")
76 return parser
77
78
79 if __name__ == "__main__":
80 # instantiate env and parser objects
81 root_path = tempfile.mkdtemp()
82 env = pmenv.pmenv(root=root_path)
83 opt_parser = create_parser()
84 (opts, args) = opt_parser.parse_args()
85
86 # add parsed options to env object
87 util.verbose = opts.verbose
88 env.pacman["debug"] = opts.debug
89 env.pacman["bin"] = opts.bin
90 env.pacman["nolog"] = opts.nolog
91 env.pacman["gdb"] = opts.gdb
92 env.pacman["valgrind"] = opts.valgrind
93 env.pacman["manual-confirm"] = opts.manualconfirm
94 env.pacman["scriptlet-shell"] = opts.scriptletshell
95 env.pacman["ldconfig"] = opts.ldconfig
96
97 opts.testcases = []
98 for path in args:
99 opts.testcases += glob.glob(path)
100 if opts.testcases is None or len(opts.testcases) == 0:
101 tap.bail("no tests defined, nothing to do")
102 os.rmdir(root_path)
103 sys.exit(2)
104
105 for i in opts.testcases:
106 env.addtest(i)
107
108 # run tests
109 env.run()
110
111 if not opts.keeproot:
112 shutil.rmtree(root_path)
113 else:
114 tap.diag("pacman testing root saved: %s" % root_path)
115
116 if env.failed > 0:
117 sys.exit(1)
118
119 # vim: set ts=4 sw=4 et: