199451b44SJordan Rupprecht"""
299451b44SJordan RupprechtTest lldb data formatter subsystem.
399451b44SJordan Rupprecht"""
499451b44SJordan Rupprecht
599451b44SJordan Rupprecht
699451b44SJordan Rupprechtimport lldb
799451b44SJordan Rupprechtfrom lldbsuite.test.decorators import *
899451b44SJordan Rupprechtfrom lldbsuite.test.lldbtest import *
999451b44SJordan Rupprechtfrom lldbsuite.test import lldbutil
1099451b44SJordan Rupprecht
1199451b44SJordan Rupprecht
1299451b44SJordan Rupprechtclass PyObjectSynthProviderTestCase(TestBase):
1399451b44SJordan Rupprecht    NO_DEBUG_INFO_TESTCASE = True
1499451b44SJordan Rupprecht
1599451b44SJordan Rupprecht    def test_print_array(self):
1699451b44SJordan Rupprecht        """Test that expr -Z works"""
1799451b44SJordan Rupprecht        self.build()
1899451b44SJordan Rupprecht        self.provider_data_formatter_commands()
1999451b44SJordan Rupprecht
2099451b44SJordan Rupprecht    def setUp(self):
2199451b44SJordan Rupprecht        # Call super's setUp().
2299451b44SJordan Rupprecht        TestBase.setUp(self)
2399451b44SJordan Rupprecht        # Find the line number to break at.
24*2238dcc3SJonas Devlieghere        self.line = line_number("main.cpp", "break here")
2599451b44SJordan Rupprecht
2699451b44SJordan Rupprecht    def provider_data_formatter_commands(self):
2799451b44SJordan Rupprecht        """Test that the PythonObjectSyntheticChildProvider helper class works"""
2899451b44SJordan Rupprecht        self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET)
2999451b44SJordan Rupprecht
3099451b44SJordan Rupprecht        lldbutil.run_break_set_by_file_and_line(
31*2238dcc3SJonas Devlieghere            self, "main.cpp", self.line, num_expected_locations=1, loc_exact=True
32*2238dcc3SJonas Devlieghere        )
3399451b44SJordan Rupprecht
3499451b44SJordan Rupprecht        self.runCmd("run", RUN_SUCCEEDED)
3599451b44SJordan Rupprecht
3699451b44SJordan Rupprecht        # The stop reason of the thread should be breakpoint.
37*2238dcc3SJonas Devlieghere        self.expect(
38*2238dcc3SJonas Devlieghere            "thread list",
39*2238dcc3SJonas Devlieghere            STOPPED_DUE_TO_BREAKPOINT,
40*2238dcc3SJonas Devlieghere            substrs=["stopped", "stop reason = breakpoint"],
41*2238dcc3SJonas Devlieghere        )
4299451b44SJordan Rupprecht
4399451b44SJordan Rupprecht        # This is the function to remove the custom formats in order to have a
4499451b44SJordan Rupprecht        # clean slate for the next test case.
4599451b44SJordan Rupprecht        def cleanup():
46*2238dcc3SJonas Devlieghere            self.runCmd("type format clear", check=False)
47*2238dcc3SJonas Devlieghere            self.runCmd("type summary clear", check=False)
48*2238dcc3SJonas Devlieghere            self.runCmd("type synth clear", check=False)
4999451b44SJordan Rupprecht
5099451b44SJordan Rupprecht        # Execute the cleanup function during test case tear down.
5199451b44SJordan Rupprecht        self.addTearDownHook(cleanup)
5299451b44SJordan Rupprecht
53*2238dcc3SJonas Devlieghere        self.runCmd("command script import provider.py")
5499451b44SJordan Rupprecht        self.runCmd(
55*2238dcc3SJonas Devlieghere            "type synthetic add Foo --python-class provider.SyntheticChildrenProvider"
56*2238dcc3SJonas Devlieghere        )
57*2238dcc3SJonas Devlieghere        self.expect("frame variable f.Name", substrs=['"Enrico"'])
5899451b44SJordan Rupprecht        self.expect(
59*2238dcc3SJonas Devlieghere            "frame variable f",
60*2238dcc3SJonas Devlieghere            substrs=["ID = 123456", 'Name = "Enrico"', "Rate = 1.25"],
61*2238dcc3SJonas Devlieghere        )
6299451b44SJordan Rupprecht        self.expect(
63*2238dcc3SJonas Devlieghere            "expression f", substrs=["ID = 123456", 'Name = "Enrico"', "Rate = 1.25"]
64*2238dcc3SJonas Devlieghere        )
65