xref: /llvm-project/lldb/test/API/tools/lldb-dap/variables/children/TestDAP_variables_children.py (revision d00731cb7fcc91047531069e029964a39935a5bb)
1f38ebec7SPavel Labathimport os
2f38ebec7SPavel Labath
3f38ebec7SPavel Labathimport dap_server
4f38ebec7SPavel Labathimport lldbdap_testcase
5f38ebec7SPavel Labathfrom lldbsuite.test import lldbutil
6f38ebec7SPavel Labathfrom lldbsuite.test.decorators import *
7f38ebec7SPavel Labathfrom lldbsuite.test.lldbtest import *
8f38ebec7SPavel Labath
9f38ebec7SPavel Labath
10f38ebec7SPavel Labathclass TestDAP_variables_children(lldbdap_testcase.DAPTestCaseBase):
11f38ebec7SPavel Labath    def test_get_num_children(self):
12f38ebec7SPavel Labath        """Test that GetNumChildren is not called for formatters not producing indexed children."""
13f38ebec7SPavel Labath        program = self.getBuildArtifact("a.out")
14f38ebec7SPavel Labath        self.build_and_launch(
15f38ebec7SPavel Labath            program,
16f38ebec7SPavel Labath            preRunCommands=[
17f38ebec7SPavel Labath                "command script import '%s'" % self.getSourcePath("formatter.py")
18f38ebec7SPavel Labath            ],
19f38ebec7SPavel Labath        )
20f38ebec7SPavel Labath        source = "main.cpp"
21f38ebec7SPavel Labath        breakpoint1_line = line_number(source, "// break here")
22f38ebec7SPavel Labath        lines = [breakpoint1_line]
23f38ebec7SPavel Labath
24f38ebec7SPavel Labath        breakpoint_ids = self.set_source_breakpoints(
25f38ebec7SPavel Labath            source, [line_number(source, "// break here")]
26f38ebec7SPavel Labath        )
27f38ebec7SPavel Labath        self.continue_to_breakpoints(breakpoint_ids)
28f38ebec7SPavel Labath
29f38ebec7SPavel Labath        local_vars = self.dap_server.get_local_variables()
30f38ebec7SPavel Labath        print(local_vars)
31f38ebec7SPavel Labath        indexed = next(filter(lambda x: x["name"] == "indexed", local_vars))
32f38ebec7SPavel Labath        not_indexed = next(filter(lambda x: x["name"] == "not_indexed", local_vars))
33f38ebec7SPavel Labath        self.assertIn("indexedVariables", indexed)
34*d00731cbSPavel Labath        self.assertEqual(indexed["indexedVariables"], 1)
35f38ebec7SPavel Labath        self.assertNotIn("indexedVariables", not_indexed)
36f38ebec7SPavel Labath
37f38ebec7SPavel Labath        self.assertIn(
38f38ebec7SPavel Labath            "['Indexed']",
39f38ebec7SPavel Labath            self.dap_server.request_evaluate(
40f38ebec7SPavel Labath                "`script formatter.num_children_calls", context="repl"
41f38ebec7SPavel Labath            )["body"]["result"],
42f38ebec7SPavel Labath        )
43