1"""
2Test that the user can input a format but it will not prevail over summary format's choices.
3"""
4
5
6
7import lldb
8from lldbsuite.test.lldbtest import *
9import lldbsuite.test.lldbutil as lldbutil
10
11
12class UserFormatVSSummaryTestCase(TestBase):
13
14    def setUp(self):
15        # Call super's setUp().
16        TestBase.setUp(self)
17        # Find the line number to break at.
18        self.line = line_number('main.cpp', '// Set break point at this line.')
19
20    def test_with_run_command(self):
21        """Test that the user can input a format but it will not prevail over summary format's choices."""
22        self.build()
23        self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET)
24
25        lldbutil.run_break_set_by_file_and_line(
26            self, "main.cpp", self.line, num_expected_locations=1, loc_exact=True)
27
28        self.runCmd("run", RUN_SUCCEEDED)
29
30        # The stop reason of the thread should be breakpoint.
31        self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
32                    substrs=['stopped',
33                             'stop reason = breakpoint'])
34
35        self.expect("frame variable p1", substrs=[
36                    '(Pair) p1 = (x = 3, y = -3)'])
37
38        # This is the function to remove the custom formats in order to have a
39        # clean slate for the next test case.
40        def cleanup():
41            self.runCmd('type format clear', check=False)
42            self.runCmd('type summary clear', check=False)
43
44        # Execute the cleanup function during test case tear down.
45        self.addTearDownHook(cleanup)
46
47        self.runCmd('type summary add Pair -s "x=${var.x%d},y=${var.y%u}"')
48
49        self.expect("frame variable p1", substrs=[
50                    '(Pair) p1 = x=3,y=4294967293'])
51        self.expect(
52            "frame variable -f x p1",
53            substrs=['(Pair) p1 = x=0x00000003,y=0xfffffffd'],
54            matching=False)
55        self.expect(
56            "frame variable -f d p1",
57            substrs=['(Pair) p1 = x=3,y=-3'],
58            matching=False)
59        self.expect("frame variable p1", substrs=[
60                    '(Pair) p1 = x=3,y=4294967293'])
61
62        self.runCmd('type summary add Pair -s "x=${var.x%x},y=${var.y%u}"')
63
64        self.expect("frame variable p1", substrs=[
65                    '(Pair) p1 = x=0x00000003,y=4294967293'])
66        self.expect(
67            "frame variable -f d p1",
68            substrs=['(Pair) p1 = x=3,y=-3'],
69            matching=False)
70