Remove unnecessary NULL check in FREE() macro
[pacman-ng.git] / pactest / pmenv.py
blobf2327f9188c1748db38416e57f952dc5683e0bdc
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 def __init__(self, root = "root"):
31 self.root = os.path.abspath(root)
32 self.pacman = {
33 "bin": "pacman",
34 "debug": 0,
35 "gdb": 0,
36 "valgrind": 0,
37 "nolog": 0
39 self.testcases = []
41 def __str__(self):
42 return "root = %s\n" \
43 "pacman = %s" \
44 % (self.root, self.pacman)
46 def addtest(self, testcase):
47 """
48 """
49 if not os.path.isfile(testcase):
50 err("file %s not found" % testcase)
51 return
52 test = pmtest.pmtest(testcase, self.root)
53 self.testcases.append(test)
55 def run(self):
56 """
57 """
59 for t in self.testcases:
60 print "=========="*8
61 print "Running '%s'" % t.testname
63 t.load()
64 print t.description
65 print "----------"*8
67 t.generate()
68 # Hack for mtimes consistency
69 for i in t.rules:
70 if i.rule.find("MODIFIED") != -1:
71 time.sleep(1.5)
72 break
74 t.run(self.pacman)
76 t.check()
77 print "==> Test result"
78 if t.result["fail"] == 0:
79 print "\tPASS"
80 else:
81 print "\tFAIL"
82 print
84 def results(self):
85 """
86 """
87 passed = 0
88 tpassed = []
89 tfailed = []
90 for test in self.testcases:
91 fail = test.result["fail"]
92 if fail == 0:
93 passed += 1
94 tpassed.append(test)
95 else:
96 tfailed.append(test)
98 def _printtest(t):
99 success = test.result["success"]
100 fail = test.result["fail"]
101 rules = len(test.rules)
102 if fail == 0:
103 result = "[PASS]"
104 else:
105 result = "[FAIL]"
106 print result,
107 print "%s Rules: OK = %2u FAIL = %2u SKIP = %2u" \
108 % (test.testname.ljust(34), success, fail, \
109 rules - (success + fail))
110 if fail != 0:
111 # print test description if test failed
112 print " ", test.description
114 print "=========="*8
115 print "Results"
116 print "----------"*8
117 for test in tpassed: _printtest(test)
118 print "----------"*8
119 for test in tfailed: _printtest(test)
120 print "----------"*8
122 total = len(self.testcases)
123 failed = total - passed
124 print "TOTAL = %3u" % total
125 if total:
126 print "PASS = %3u (%6.2f%%)" % (passed, float(passed) * 100 / total)
127 print "FAIL = %3u (%6.2f%%)" % (failed, float(failed) * 100 / total)
128 print ""
130 if __name__ == "__main__":
131 env = pmenv("/tmp")
132 print env
133 # vim: set ts=4 sw=4 et: