makepkg: fix my own stupid mistake
[pacman-ng.git] / pactest / pmenv.py
blobcc433dd0920f43113fdaa34c1d7e8b16ba2408d6
1 #! /usr/bin/python
3 # Copyright (c) 2006 by Aurelien Foret <orelien@chez.com>
4 #
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 import os
20 import os.path
21 import time
23 import pmtest
26 class pmenv:
27 """Environment object
28 """
30 testcases = []
31 passed = 0
32 failed = 0
33 expectedfail = 0
34 unexpectedpass = 0
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
46 def __str__(self):
47 return "root = %s\n" \
48 "pacman = %s" \
49 % (self.root, self.pacman)
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)
59 def run(self):
60 """
61 """
63 for t in self.testcases:
64 print "=========="*8
65 print "Running '%s'" % t.testname
67 t.load()
68 print t.description
69 print "----------"*8
71 t.generate()
72 # Hack for mtimes consistency
73 for i in t.rules:
74 if i.rule.find("FILE_MODIFIED") != -1:
75 [test, arg] = i.rule.split("=")
76 for f in t.files:
77 if f.name == arg:
78 f.resettimes()
80 t.run(self.pacman)
82 t.check()
83 print "==> Test result"
84 if t.result["fail"] == 0:
85 print "\tPASS"
86 else:
87 print "\tFAIL"
88 print
90 def results(self):
91 """
92 """
93 tpassed = []
94 tfailed = []
95 texpectedfail = []
96 tunexpectedpass = []
97 for test in self.testcases:
98 fail = test.result["fail"]
99 if fail == 0 and not test.expectfailure:
100 self.passed += 1
101 tpassed.append(test)
102 elif fail != 0 and test.expectfailure:
103 self.expectedfail += 1
104 texpectedfail.append(test)
105 elif fail == 0: # and not test.expectfail
106 self.unexpectedpass += 1
107 tunexpectedpass.append(test)
108 else:
109 self.failed += 1
110 tfailed.append(test)
112 def _printtest(t):
113 success = test.result["success"]
114 fail = test.result["fail"]
115 rules = len(test.rules)
116 if fail == 0:
117 result = "[PASS]"
118 else:
119 result = "[FAIL]"
120 print result,
121 print "%s Rules: OK = %2u FAIL = %2u SKIP = %2u" \
122 % (test.testname.ljust(34), success, fail, \
123 rules - (success + fail))
124 if fail != 0:
125 # print test description if test failed
126 print " ", test.description
128 print "=========="*8
129 print "Results"
130 print "----------"*8
131 print " Passed:"
132 for test in tpassed: _printtest(test)
133 print "----------"*8
134 print " Expected Failures:"
135 for test in texpectedfail: _printtest(test)
136 print "----------"*8
137 print " Unexpected Passes:"
138 for test in tunexpectedpass: _printtest(test)
139 print "----------"*8
140 print " Failed:"
141 for test in tfailed: _printtest(test)
142 print "----------"*8
144 total = len(self.testcases)
145 print "Total = %3u" % total
146 if total:
147 print "Pass = %3u (%6.2f%%)" % (self.passed, float(self.passed) * 100 / total)
148 print "Expected Fail = %3u (%6.2f%%)" % (self.expectedfail, float(self.expectedfail) * 100 / total)
149 print "Unexpected Pass = %3u (%6.2f%%)" % (self.unexpectedpass, float(self.unexpectedpass) * 100 / total)
150 print "Fail = %3u (%6.2f%%)" % (self.failed, float(self.failed) * 100 / total)
151 print ""
153 if __name__ == "__main__":
154 pass
156 # vim: set ts=4 sw=4 et: