1import unittest
2import Test
3
4"""
5TestCase adaptor for providing a 'unittest' compatible interface to 'lit' tests.
6"""
7
8class UnresolvedError(RuntimeError):
9    pass
10
11class LitTestCase(unittest.TestCase):
12    def __init__(self, test, lit_config):
13        unittest.TestCase.__init__(self)
14        self._test = test
15        self._lit_config = lit_config
16
17    def id(self):
18        return self._test.getFullName()
19
20    def shortDescription(self):
21        return self._test.getFullName()
22
23    def runTest(self):
24        tr, output = self._test.config.test_format.execute(
25            self._test, self._lit_config)
26
27        if tr is Test.UNRESOLVED:
28            raise UnresolvedError(output)
29        elif tr.isFailure:
30            self.fail(output)
31