xref: /llvm-project/lldb/test/API/test_utils/base/TestBaseTest.py (revision 2238dcc39358353cac21df75c3c3286ab20b8f53)
1"""
2Test TestBase test functions.
3"""
4
5import io
6
7from lldbsuite.test.lldbtest import *
8from lldbsuite.test_event import build_exception
9
10
11class TestBuildMethod(Base):
12    def setUp(self):
13        super().setUp()
14        self._traces = []
15        self.traceAlways = True
16
17    # override the parent trace method
18    def trace(self, *args, **kwargs):
19        buf = io.StringIO()
20        print(*args, file=buf, **kwargs)
21        self._traces.append(buf.getvalue())
22
23    def test_build_fails_helpfully(self):
24        try:
25            self.build(dictionary={"CXX_SOURCES": "nonexisting-file.cpp"})
26        except build_exception.BuildError as e:
27            self.assertIn("nonexisting-file.cpp", str(e))
28        else:
29            self.fail("BuildError not raised!")
30
31    def test_build_logs_traces(self):
32        self.build(dictionary={"CXX_SOURCES": "return0.cpp"})
33        self.assertIn("CXX_SOURCES", self._traces[0])
34        self.assertIn("return0.o", self._traces[1])
35