xref: /aosp_15_r20/external/llvm/utils/lit/lit/LitTestCase.py (revision 9880d6810fe72a1726cb53787c6711e909410d58)
1from __future__ import absolute_import
2import unittest
3
4import lit.Test
5
6"""
7TestCase adaptor for providing a 'unittest' compatible interface to 'lit' tests.
8"""
9
10class UnresolvedError(RuntimeError):
11    pass
12
13class LitTestCase(unittest.TestCase):
14    def __init__(self, test, run):
15        unittest.TestCase.__init__(self)
16        self._test = test
17        self._run = run
18
19    def id(self):
20        return self._test.getFullName()
21
22    def shortDescription(self):
23        return self._test.getFullName()
24
25    def runTest(self):
26        # Run the test.
27        self._run.execute_test(self._test)
28
29        # Adapt the result to unittest.
30        result = self._test.result
31        if result.code is lit.Test.UNRESOLVED:
32            raise UnresolvedError(result.output)
33        elif result.code.isFailure:
34            self.fail(result.output)
35