Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/pactest/pmenv.py
blob: b86abe949d3f1d4bcffd3c1989b1e96b9b9658c0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#! /usr/bin/python
#
#  Copyright (c) 2006 by Aurelien Foret <orelien@chez.com>
# 
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or
#  (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program.  If not, see <http://www.gnu.org/licenses/>.


import os
import os.path
import time

import pmtest


class pmenv:
    """Environment object
    """

    def __init__(self, root = "root"):
        self.root = os.path.abspath(root)
        self.pacman = {
            "bin": "pacman",
            "debug": 0,
            "gdb": 0,
            "valgrind": 0,
            "nolog": 0
        }
        self.testcases = []

    def __str__(self):
        return "root = %s\n" \
               "pacman = %s" \
               % (self.root, self.pacman)

    def addtest(self, testcase):
        """
        """
        if not os.path.isfile(testcase):
            err("file %s not found" % testcase)
            return
        test = pmtest.pmtest(testcase, self.root)
        self.testcases.append(test)

    def run(self):
        """
        """

        for t in self.testcases:
            print "=========="*8
            print "Running '%s'" % t.testname

            t.load()
            print t.description
            print "----------"*8

            t.generate()
            # Hack for mtimes consistency
            for i in t.rules:
                if i.rule.find("MODIFIED") != -1:
                    time.sleep(1.5)
                    break

            t.run(self.pacman)

            t.check()
            print "==> Test result"
            if t.result["fail"] == 0:
                print "\tPASS"
            else:
                print "\tFAIL"
            print

    def results(self):
        """
        """
        passed = 0
        tpassed = []
        failed = 0
        tfailed = []
        expectedfail = 0
        texpectedfail = []
        unexpectedpass = 0
        tunexpectedpass = []
        for test in self.testcases:
            fail = test.result["fail"]
            if fail == 0 and not test.expectfailure:
                passed += 1
                tpassed.append(test)
            elif fail != 0 and test.expectfailure:
                expectedfail += 1
                texpectedfail.append(test)
            elif fail == 0: # and not test.expectfail
                unexpectedpass += 1
                tunexpectedpass.append(test)
            else:
                failed += 1
                tfailed.append(test)

        def _printtest(t):
            success = test.result["success"]
            fail = test.result["fail"]
            rules = len(test.rules)
            if fail == 0:
                result = "[PASS]"
            else:
                result = "[FAIL]"
            print result,
            print "%s Rules: OK = %2u  FAIL = %2u  SKIP = %2u" \
                    % (test.testname.ljust(34), success, fail, \
                       rules - (success + fail))
            if fail != 0:
                # print test description if test failed
                print "      ", test.description

        print "=========="*8
        print "Results"
        print "----------"*8
        print " Passed:"
        for test in tpassed: _printtest(test)
        print "----------"*8
        print " Expected Failures:"
        for test in texpectedfail: _printtest(test)
        print "----------"*8
        print " Unexpected Passes:"
        for test in tunexpectedpass: _printtest(test)
        print "----------"*8
        print " Failed:"
        for test in tfailed: _printtest(test)
        print "----------"*8

        total = len(self.testcases)
        print "Total            = %3u" % total
        if total:
            print "Pass             = %3u (%6.2f%%)" % (passed, float(passed) * 100 / total)
            print "Expected Fail    = %3u (%6.2f%%)" % (expectedfail, float(expectedfail) * 100 / total)
            print "Unexpected Pass  = %3u (%6.2f%%)" % (unexpectedpass, float(unexpectedpass) * 100 / total)
            print "Fail             = %3u (%6.2f%%)" % (failed, float(failed) * 100 / total)
        print ""

if __name__ == "__main__":
    env = pmenv("/tmp")
    print env
# vim: set ts=4 sw=4 et: