d1d92346e436b603cbb9015e5c1f99811aa85825
[openbsd] /
1 """
2 Test lldb-vscode completions request
3 """
4
5
6 import lldbvscode_testcase
7 import unittest2
8 import vscode
9 from lldbsuite.test import lldbutil
10 from lldbsuite.test.decorators import *
11 from lldbsuite.test.lldbtest import *
12
13
14 class 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.assertTrue(expected_item in actual_list)
21
22         for not_expected_item in not_expected_list:
23             self.assertFalse(not_expected_item in 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         )