• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1"""
2Test lldb-vscode completions request
3"""
4
5
6import lldbvscode_testcase
7import unittest2
8import vscode
9from lldbsuite.test import lldbutil
10from lldbsuite.test.decorators import *
11from lldbsuite.test.lldbtest import *
12
13
14class TestVSCode_variables(lldbvscode_testcase.VSCodeTestCaseBase):
15
16    mydir = TestBase.compute_mydir(__file__)
17
18    def verify_completions(self, actual_list, expected_list, not_expected_list=[]):
19        for expected_item in expected_list:
20            self.assertIn(expected_item, actual_list)
21
22        for not_expected_item in not_expected_list:
23            self.assertNotIn(not_expected_item, actual_list)
24
25    @skipIfWindows
26    @skipIfDarwin # Skip this test for now until we can figure out why tings aren't working on build bots
27    def test_completions(self):
28        """
29            Tests the completion request at different breakpoints
30        """
31        program = self.getBuildArtifact("a.out")
32        self.build_and_launch(program)
33        source = "main.cpp"
34        breakpoint1_line = line_number(source, "// breakpoint 1")
35        breakpoint2_line = line_number(source, "// breakpoint 2")
36        breakpoint_ids = self.set_source_breakpoints(
37            source, [breakpoint1_line, breakpoint2_line]
38        )
39        self.continue_to_next_stop()
40
41        # shouldn't see variables inside main
42        self.verify_completions(
43            self.vscode.get_completions("var"),
44            [
45                {
46                    "text": "var",
47                    "label": "var -- vector<basic_string<char, char_traits<char>, allocator<char>>, allocator<basic_string<char, char_traits<char>, allocator<char>>>> &",
48                }
49            ],
50            [{"text": "var1", "label": "var1 -- int &"}],
51        )
52
53        # should see global keywords but not variables inside main
54        self.verify_completions(
55            self.vscode.get_completions("str"),
56            [{"text": "struct", "label": "struct"}],
57            [{"text": "str1", "label": "str1 -- std::string &"}],
58        )
59
60        self.continue_to_next_stop()
61
62        # should see variables from main but not from the other function
63        self.verify_completions(
64            self.vscode.get_completions("var"),
65            [
66                {"text": "var1", "label": "var1 -- int &"},
67                {"text": "var2", "label": "var2 -- int &"},
68            ],
69            [
70                {
71                    "text": "var",
72                    "label": "var -- vector<basic_string<char, char_traits<char>, allocator<char> >, allocator<basic_string<char, char_traits<char>, allocator<char> > > > &",
73                }
74            ],
75        )
76
77        self.verify_completions(
78            self.vscode.get_completions("str"),
79            [
80                {"text": "struct", "label": "struct"},
81                {"text": "str1", "label": "str1 -- string &"},
82            ],
83        )
84
85        # should complete arbitrary commands including word starts
86        self.verify_completions(
87            self.vscode.get_completions("`log enable  "),
88            [{"text": "gdb-remote", "label": "gdb-remote"}],
89        )
90
91        # should complete expressions with quotes inside
92        self.verify_completions(
93            self.vscode.get_completions('`expr " "; typed'),
94            [{"text": "typedef", "label": "typedef"}],
95        )
96
97        # should complete an incomplete quoted token
98        self.verify_completions(
99            self.vscode.get_completions('`setting "se'),
100            [
101                {
102                    "text": "set",
103                    "label": "set -- Set the value of the specified debugger setting.",
104                }
105            ],
106        )
107        self.verify_completions(
108            self.vscode.get_completions("`'comm"),
109            [
110                {
111                    "text": "command",
112                    "label": "command -- Commands for managing custom LLDB commands.",
113                }
114            ],
115        )
116
117        self.verify_completions(
118            self.vscode.get_completions("foo1.v"),
119            [
120                {
121                    "text": "var1",
122                    "label": "foo1.var1 -- int"
123                }
124            ]
125        )
126
127        self.verify_completions(
128            self.vscode.get_completions("foo1.my_bar_object.v"),
129            [
130                {
131                    "text": "var1",
132                    "label": "foo1.my_bar_object.var1 -- int"
133                }
134            ]
135        )
136
137        self.verify_completions(
138            self.vscode.get_completions("foo1.var1 + foo1.v"),
139            [
140                {
141                    "text": "var1",
142                    "label": "foo1.var1 -- int"
143                }
144            ]
145        )
146
147        self.verify_completions(
148            self.vscode.get_completions("foo1.var1 + v"),
149            [
150                {
151                    "text": "var1",
152                    "label": "var1 -- int &"
153                }
154            ]
155        )
156
157        #should correctly handle spaces between objects and member operators
158        self.verify_completions(
159            self.vscode.get_completions("foo1 .v"),
160            [
161                {
162                    "text": "var1",
163                    "label": ".var1 -- int"
164                }
165            ],
166            [
167                {
168                    "text": "var2",
169                    "label": ".var2 -- int"
170                }
171            ]
172        )
173
174        self.verify_completions(
175            self.vscode.get_completions("foo1 . v"),
176            [
177                {
178                    "text": "var1",
179                    "label": "var1 -- int"
180                }
181            ],
182            [
183                {
184                    "text": "var2",
185                    "label": "var2 -- int"
186                }
187            ]
188        )
189