1"""
2Test lldb data formatter subsystem.
3"""
4
5
6
7import lldb
8from lldbsuite.test.decorators import *
9from lldbsuite.test.lldbtest import *
10from lldbsuite.test import lldbutil
11
12
13class DataFormatterOneIsSingularTestCase(TestBase):
14
15    mydir = TestBase.compute_mydir(__file__)
16
17    @skipUnlessDarwin
18    def test_one_is_singular_with_run_command(self):
19        """Test that 1 item is not as reported as 1 items."""
20        self.build()
21        self.oneness_data_formatter_commands()
22
23    def setUp(self):
24        # Call super's setUp().
25        TestBase.setUp(self)
26        # Find the line number to break at.
27        self.line = line_number('main.m', '// Set break point at this line.')
28
29    def oneness_data_formatter_commands(self):
30        """Test that 1 item is not as reported as 1 items."""
31        self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET)
32
33        lldbutil.run_break_set_by_file_and_line(
34            self, "main.m", self.line, num_expected_locations=1, loc_exact=True)
35
36        self.runCmd("run", RUN_SUCCEEDED)
37
38        # The stop reason of the thread should be breakpoint.
39        self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
40                    substrs=['stopped',
41                             'stop reason = breakpoint'])
42
43        # This is the function to remove the custom formats in order to have a
44        # clean slate for the next test case.
45        def cleanup():
46            self.runCmd('type format clear', check=False)
47            self.runCmd('type summary clear', check=False)
48            self.runCmd('type synth clear', check=False)
49
50        # Execute the cleanup function during test case tear down.
51        self.addTearDownHook(cleanup)
52
53        # Now check that we are displaying Cocoa classes correctly
54        self.expect('frame variable key',
55                    substrs=['@"1 element"'])
56        self.expect('frame variable key', matching=False,
57                    substrs=['1 elements'])
58        self.expect('frame variable value',
59                    substrs=['@"1 element"'])
60        self.expect('frame variable value', matching=False,
61                    substrs=['1 elements'])
62        self.expect('frame variable dict',
63                    substrs=['1 key/value pair'])
64        self.expect('frame variable dict', matching=False,
65                    substrs=['1 key/value pairs'])
66        self.expect('frame variable imset',
67                    substrs=['1 index'])
68        self.expect('frame variable imset', matching=False,
69                    substrs=['1 indexes'])
70        self.expect('frame variable binheap_ref',
71                    substrs=['@"1 item"'])
72        self.expect('frame variable binheap_ref', matching=False,
73                    substrs=['1 items'])
74        self.expect('frame variable immutableData',
75                    substrs=['1 byte'])
76        self.expect('frame variable immutableData', matching=False,
77                    substrs=['1 bytes'])
78