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    @skipUnlessDarwin
16    def test_one_is_singular_with_run_command(self):
17        """Test that 1 item is not as reported as 1 items."""
18        self.build()
19        self.oneness_data_formatter_commands()
20
21    def setUp(self):
22        # Call super's setUp().
23        TestBase.setUp(self)
24        # Find the line number to break at.
25        self.line = line_number('main.m', '// Set break point at this line.')
26
27    def oneness_data_formatter_commands(self):
28        """Test that 1 item is not as reported as 1 items."""
29        self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET)
30
31        lldbutil.run_break_set_by_file_and_line(
32            self, "main.m", self.line, num_expected_locations=1, loc_exact=True)
33
34        self.runCmd("run", RUN_SUCCEEDED)
35
36        # The stop reason of the thread should be breakpoint.
37        self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
38                    substrs=['stopped',
39                             'stop reason = breakpoint'])
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            self.runCmd('type synth clear', check=False)
47
48        # Execute the cleanup function during test case tear down.
49        self.addTearDownHook(cleanup)
50
51        # Now check that we are displaying Cocoa classes correctly
52        self.expect('frame variable key',
53                    substrs=['@"1 element"'])
54        self.expect('frame variable key', matching=False,
55                    substrs=['1 elements'])
56        self.expect('frame variable value',
57                    substrs=['@"1 element"'])
58        self.expect('frame variable value', matching=False,
59                    substrs=['1 elements'])
60        self.expect('frame variable dict',
61                    substrs=['1 key/value pair'])
62        self.expect('frame variable dict', matching=False,
63                    substrs=['1 key/value pairs'])
64        self.expect('frame variable imset',
65                    substrs=['1 index'])
66        self.expect('frame variable imset', matching=False,
67                    substrs=['1 indexes'])
68        self.expect('frame variable binheap_ref',
69                    substrs=['@"1 item"'])
70        self.expect('frame variable binheap_ref', matching=False,
71                    substrs=['1 items'])
72        self.expect('frame variable immutableData',
73                    substrs=['1 byte'])
74        self.expect('frame variable immutableData', matching=False,
75                    substrs=['1 bytes'])
76