[lit] Factor out a separate Test.Result() object.
[oota-llvm.git] / utils / lit / lit / Test.py
1 import os
2
3 # Test results.
4
5 class ResultCode(object):
6     """Test result codes."""
7
8     def __init__(self, name, isFailure):
9         self.name = name
10         self.isFailure = isFailure
11
12     def __repr__(self):
13         return '%s%r' % (self.__class__.__name__,
14                          (self.name, self.isFailure))
15
16 PASS        = ResultCode('PASS', False)
17 XFAIL       = ResultCode('XFAIL', False)
18 FAIL        = ResultCode('FAIL', True)
19 XPASS       = ResultCode('XPASS', True)
20 UNRESOLVED  = ResultCode('UNRESOLVED', True)
21 UNSUPPORTED = ResultCode('UNSUPPORTED', False)
22
23 class Result(object):
24     """Wrapper for the results of executing an individual test."""
25
26     def __init__(self, code, output, elapsed):
27         # The result code.
28         self.code = code
29         # The test output.
30         self.output = output
31         # The wall timing to execute the test, if timing.
32         self.elapsed = elapsed
33
34 # Test classes.
35
36 class TestSuite:
37     """TestSuite - Information on a group of tests.
38
39     A test suite groups together a set of logically related tests.
40     """
41
42     def __init__(self, name, source_root, exec_root, config):
43         self.name = name
44         self.source_root = source_root
45         self.exec_root = exec_root
46         # The test suite configuration.
47         self.config = config
48
49     def getSourcePath(self, components):
50         return os.path.join(self.source_root, *components)
51
52     def getExecPath(self, components):
53         return os.path.join(self.exec_root, *components)
54
55 class Test:
56     """Test - Information on a single test instance."""
57
58     def __init__(self, suite, path_in_suite, config):
59         self.suite = suite
60         self.path_in_suite = path_in_suite
61         self.config = config
62         # The test result, once complete.
63         self.result = None
64
65     def setResult(self, result, output, elapsed):
66         assert self.result is None, "Test result already set!"
67         self.result = Result(result, output, elapsed)
68
69     def getFullName(self):
70         return self.suite.config.name + ' :: ' + '/'.join(self.path_in_suite)
71
72     def getSourcePath(self):
73         return self.suite.getSourcePath(self.path_in_suite)
74
75     def getExecPath(self):
76         return self.suite.getExecPath(self.path_in_suite)