]>
Commit | Line | Data |
---|---|---|
82abe079 | 1 | #! /usr/bin/python2 |
1dc81514 AG |
2 | # |
3 | # Copyright (c) 2006 by Aurelien Foret <orelien@chez.com> | |
801f7d10 | 4 | # Copyright (c) 2006-2013 Pacman Developmet Team <pacman-dev@archlinux.org> |
3ceef977 | 5 | # |
1dc81514 AG |
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 | |
9781d0d6 | 17 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
1dc81514 AG |
18 | |
19 | ||
20 | import os | |
1dc81514 AG |
21 | |
22 | import pmtest | |
23 | ||
24 | ||
b3d71bf7 | 25 | class pmenv(object): |
786cd38c AG |
26 | """Environment object |
27 | """ | |
28 | ||
cf25884e DM |
29 | testcases = [] |
30 | passed = 0 | |
31 | failed = 0 | |
32 | expectedfail = 0 | |
33 | unexpectedpass = 0 | |
34 | ||
786cd38c AG |
35 | def __init__(self, root = "root"): |
36 | self.root = os.path.abspath(root) | |
37 | self.pacman = { | |
38 | "bin": "pacman", | |
39 | "debug": 0, | |
40 | "gdb": 0, | |
41 | "valgrind": 0, | |
42 | "nolog": 0 | |
43 | } | |
786cd38c AG |
44 | |
45 | def __str__(self): | |
46 | return "root = %s\n" \ | |
47 | "pacman = %s" \ | |
48 | % (self.root, self.pacman) | |
49 | ||
50 | def addtest(self, testcase): | |
51 | """ | |
52 | """ | |
53 | if not os.path.isfile(testcase): | |
cf25884e | 54 | raise IOError("test file %s not found" % testcase) |
786cd38c AG |
55 | test = pmtest.pmtest(testcase, self.root) |
56 | self.testcases.append(test) | |
57 | ||
58 | def run(self): | |
59 | """ | |
60 | """ | |
61 | ||
62 | for t in self.testcases: | |
63 | print "=========="*8 | |
25223d67 | 64 | print "Running '%s'" % t.testname |
786cd38c AG |
65 | |
66 | t.load() | |
67 | print t.description | |
68 | print "----------"*8 | |
69 | ||
801f7d10 | 70 | t.generate(self.pacman) |
786cd38c AG |
71 | |
72 | t.run(self.pacman) | |
73 | ||
74 | t.check() | |
75 | print "==> Test result" | |
76 | if t.result["fail"] == 0: | |
efca1cc0 | 77 | print "\tPASS" |
786cd38c | 78 | else: |
efca1cc0 | 79 | print "\tFAIL" |
786cd38c AG |
80 | |
81 | ||
82 | def results(self): | |
83 | """ | |
84 | """ | |
25223d67 AG |
85 | tpassed = [] |
86 | tfailed = [] | |
9f579214 | 87 | texpectedfail = [] |
9f579214 | 88 | tunexpectedpass = [] |
786cd38c | 89 | for test in self.testcases: |
25223d67 | 90 | fail = test.result["fail"] |
9f579214 | 91 | if fail == 0 and not test.expectfailure: |
cf25884e | 92 | self.passed += 1 |
25223d67 | 93 | tpassed.append(test) |
9f579214 | 94 | elif fail != 0 and test.expectfailure: |
cf25884e | 95 | self.expectedfail += 1 |
9f579214 DM |
96 | texpectedfail.append(test) |
97 | elif fail == 0: # and not test.expectfail | |
cf25884e | 98 | self.unexpectedpass += 1 |
9f579214 | 99 | tunexpectedpass.append(test) |
25223d67 | 100 | else: |
cf25884e | 101 | self.failed += 1 |
25223d67 AG |
102 | tfailed.append(test) |
103 | ||
104 | def _printtest(t): | |
11d84187 DM |
105 | success = t.result["success"] |
106 | fail = t.result["fail"] | |
107 | rules = len(t.rules) | |
786cd38c | 108 | if fail == 0: |
efca1cc0 | 109 | result = "[PASS]" |
786cd38c | 110 | else: |
efca1cc0 | 111 | result = "[FAIL]" |
13e21110 | 112 | print result, |
429b956f AG |
113 | print "%s Rules: OK = %2u FAIL = %2u" \ |
114 | % (t.testname.ljust(34), success, fail) | |
13e21110 DM |
115 | if fail != 0: |
116 | # print test description if test failed | |
11d84187 | 117 | print " ", t.description |
25223d67 AG |
118 | |
119 | print "=========="*8 | |
120 | print "Results" | |
786cd38c | 121 | print "----------"*8 |
9f579214 | 122 | print " Passed:" |
11d84187 DM |
123 | for test in tpassed: |
124 | _printtest(test) | |
25223d67 | 125 | print "----------"*8 |
9f579214 | 126 | print " Expected Failures:" |
11d84187 DM |
127 | for test in texpectedfail: |
128 | _printtest(test) | |
9f579214 DM |
129 | print "----------"*8 |
130 | print " Unexpected Passes:" | |
11d84187 DM |
131 | for test in tunexpectedpass: |
132 | _printtest(test) | |
9f579214 DM |
133 | print "----------"*8 |
134 | print " Failed:" | |
11d84187 DM |
135 | for test in tfailed: |
136 | _printtest(test) | |
25223d67 AG |
137 | print "----------"*8 |
138 | ||
786cd38c | 139 | total = len(self.testcases) |
9f579214 | 140 | print "Total = %3u" % total |
786cd38c | 141 | if total: |
cf25884e DM |
142 | print "Pass = %3u (%6.2f%%)" % (self.passed, float(self.passed) * 100 / total) |
143 | print "Expected Fail = %3u (%6.2f%%)" % (self.expectedfail, float(self.expectedfail) * 100 / total) | |
144 | print "Unexpected Pass = %3u (%6.2f%%)" % (self.unexpectedpass, float(self.unexpectedpass) * 100 / total) | |
145 | print "Fail = %3u (%6.2f%%)" % (self.failed, float(self.failed) * 100 / total) | |
25223d67 | 146 | print "" |
1dc81514 | 147 | |
786cd38c | 148 | # vim: set ts=4 sw=4 et: |