1"""
2Test lldb data formatter subsystem.
3"""
4
5
6import lldb
7from lldbsuite.test.lldbtest import *
8import lldbsuite.test.lldbutil as lldbutil
9
10
11class EnumFormatTestCase(TestBase):
12    def setUp(self):
13        # Call super's setUp().
14        TestBase.setUp(self)
15        # Find the line number to break at.
16        self.line = line_number("main.cpp", "// Set break point at this line.")
17
18    def test_with_run_command(self):
19        """Test that that file and class static variables display correctly."""
20        self.build()
21        self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET)
22
23        lldbutil.run_break_set_by_file_and_line(
24            self, "main.cpp", self.line, num_expected_locations=1, loc_exact=True
25        )
26
27        self.runCmd("run", RUN_SUCCEEDED)
28
29        # The stop reason of the thread should be breakpoint.
30        self.expect(
31            "thread list",
32            STOPPED_DUE_TO_BREAKPOINT,
33            substrs=["stopped", "stop reason = breakpoint"],
34        )
35
36        self.expect(
37            "frame variable",
38            substrs=["(Foo) f = Case45", "(int) x = 1", "(int) y = 45", "(int) z = 43"],
39        )
40
41        # This is the function to remove the custom formats in order to have a
42        # clean slate for the next test case.
43        def cleanup():
44            self.runCmd("type format clear", check=False)
45            self.runCmd("type summary clear", check=False)
46
47        # Execute the cleanup function during test case tear down.
48        self.addTearDownHook(cleanup)
49
50        self.runCmd("type format add --type Foo int")
51
52        # The type format list should show our custom formats.
53        self.expect("type format list -w default", substrs=["int: as type Foo"])
54
55        self.expect(
56            "frame variable",
57            substrs=[
58                "(Foo) f = Case45",
59                "(int) x = Case1",
60                "(int) y = Case45",
61                "(int) z = 43",
62            ],
63        )
64