]> wolfpit.net Git - tool/Arch-pacman/.git/blob - test/pacman/pmenv.py
a3a8f54f19506c832cf6162ababef8ac8bde5173
[tool/Arch-pacman/.git] / test / pacman / pmenv.py
1 #! /usr/bin/python2
2 #
3 # Copyright (c) 2006 by Aurelien Foret <orelien@chez.com>
4 # Copyright (c) 2006-2013 Pacman Developmet Team <pacman-dev@archlinux.org>
5 #
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18
19
20 import os
21
22 import pmtest
23 import tap
24
25
26 class pmenv(object):
27 """Environment object
28 """
29
30 testcases = []
31 passed = 0
32 failed = 0
33 expectedfail = 0
34 unexpectedpass = 0
35
36 def __init__(self, root = "root"):
37 self.root = os.path.abspath(root)
38 self.pacman = {
39 "bin": "pacman",
40 "debug": 0,
41 "gdb": 0,
42 "valgrind": 0,
43 "nolog": 0
44 }
45
46 def __str__(self):
47 return "root = %s\n" \
48 "pacman = %s" \
49 % (self.root, self.pacman)
50
51 def addtest(self, testcase):
52 """
53 """
54 if not os.path.isfile(testcase):
55 raise IOError("test file %s not found" % testcase)
56 test = pmtest.pmtest(testcase, self.root)
57 self.testcases.append(test)
58
59 def run(self):
60 """
61 """
62 tap.plan(len(self.testcases))
63 for t in self.testcases:
64 tap.diag("==========" * 8)
65 tap.diag("Running '%s'" % t.testname)
66
67 t.load()
68 t.generate(self.pacman)
69 t.run(self.pacman)
70
71 tap.diag("==> Checking rules")
72 tap.todo = t.expectfailure
73 tap.subtest(lambda: t.check(), t.description)
74
75 def results(self):
76 """
77 """
78 tpassed = []
79 tfailed = []
80 texpectedfail = []
81 tunexpectedpass = []
82 for test in self.testcases:
83 fail = test.result["fail"]
84 if fail == 0 and not test.expectfailure:
85 self.passed += 1
86 tpassed.append(test)
87 elif fail != 0 and test.expectfailure:
88 self.expectedfail += 1
89 texpectedfail.append(test)
90 elif fail == 0: # and not test.expectfail
91 self.unexpectedpass += 1
92 tunexpectedpass.append(test)
93 else:
94 self.failed += 1
95 tfailed.append(test)
96
97 def _printtest(t):
98 success = t.result["success"]
99 fail = t.result["fail"]
100 rules = len(t.rules)
101 if fail == 0:
102 result = "[PASS]"
103 else:
104 result = "[FAIL]"
105 tap.diag("%s %s Rules: OK = %2u FAIL = %2u" \
106 % (result, t.testname.ljust(34), success, fail))
107 if fail != 0:
108 # print test description if test failed
109 tap.diag(" " + t.description)
110
111 tap.diag("==========" * 8)
112 tap.diag("Results")
113 tap.diag("----------" * 8)
114 tap.diag(" Passed:")
115 for test in tpassed:
116 _printtest(test)
117 tap.diag("----------" * 8)
118 tap.diag(" Expected Failures:")
119 for test in texpectedfail:
120 _printtest(test)
121 tap.diag("----------" * 8)
122 tap.diag(" Unexpected Passes:")
123 for test in tunexpectedpass:
124 _printtest(test)
125 tap.diag("----------" * 8)
126 tap.diag(" Failed:")
127 for test in tfailed:
128 _printtest(test)
129 tap.diag("----------" * 8)
130
131 total = len(self.testcases)
132 tap.diag("Total = %3u" % total)
133 if total:
134 tap.diag("Pass = %3u (%6.2f%%)" % (self.passed,
135 float(self.passed) * 100 / total))
136 tap.diag("Expected Fail = %3u (%6.2f%%)" % (self.expectedfail,
137 float(self.expectedfail) * 100 / total))
138 tap.diag("Unexpected Pass = %3u (%6.2f%%)" % (self.unexpectedpass,
139 float(self.unexpectedpass) * 100 / total))
140 tap.diag("Fail = %3u (%6.2f%%)" % (self.failed,
141 float(self.failed) * 100 / total))
142
143 # vim: set ts=4 sw=4 et: