@@ -16,7 +16,7 @@ class ParsedCommandTestCase(TestBase):
16
16
def test (self ):
17
17
self .pycmd_tests ()
18
18
19
- def check_help_options (self , cmd_name , opt_list , substrs = []):
19
+ def check_help_options (self , cmd_name , opt_list , substrs = []):
20
20
"""
21
21
Pass the command name in cmd_name and a vector of the short option, type & long option.
22
22
This will append the checks for all the options and test "help command".
@@ -30,117 +30,170 @@ def check_help_options(self, cmd_name, opt_list, substrs = []):
30
30
(short_opt , type , long_opt ) = elem
31
31
substrs .append (f"-{ short_opt } <{ type } > ( --{ long_opt } <{ type } > )" )
32
32
print (f"Opt Vec\n { substrs } " )
33
- self .expect ("help " + cmd_name , substrs = substrs )
33
+ self .expect ("help " + cmd_name , substrs = substrs )
34
34
35
35
def pycmd_tests (self ):
36
36
source_dir = self .getSourceDir ()
37
37
test_file_path = os .path .join (source_dir , "test_commands.py" )
38
38
self .runCmd ("command script import " + test_file_path )
39
- self .expect ("help" , substrs = ["no-args" , "one-arg-no-opt" , "two-args" ])
39
+ self .expect ("help" , substrs = ["no-args" , "one-arg-no-opt" , "two-args" ])
40
40
41
41
# Test that we did indeed add these commands as user commands:
42
42
43
43
# This is the function to remove the custom commands in order to have a
44
44
# clean slate for the next test case.
45
45
def cleanup ():
46
- self .runCmd ("command script delete no-args one-arg-no-opt two-args" , check = False )
46
+ self .runCmd (
47
+ "command script delete no-args one-arg-no-opt two-args" , check = False
48
+ )
47
49
48
50
# Execute the cleanup function during test case tear down.
49
51
self .addTearDownHook (cleanup )
50
52
51
53
# First test the no arguments command. Make sure the help is right:
52
- no_arg_opts = [["b" , "boolean" , "bool-arg" ],
53
- "+a boolean arg, defaults to True" ,
54
- ["d" , "filename" , "disk-file-name" ],
55
- "+An on disk filename" ,
56
- ["e" , "none" , "enum-option" ],
57
- "+An enum, doesn't actually do anything" ,
58
- "+Values: foo | bar | baz" ,
59
- ["l" , "linenum" , "line-num" ],
60
- "+A line number" ,
61
- ["s" , "shlib-name" , "shlib-name" ],
62
- "+A shared library name" ]
63
- substrs = ["Example command for use in debugging" ,
64
- "Syntax: no-args <cmd-options>" ]
65
-
54
+ no_arg_opts = [
55
+ ["b" , "boolean" , "bool-arg" ],
56
+ "+a boolean arg, defaults to True" ,
57
+ ["d" , "filename" , "disk-file-name" ],
58
+ "+An on disk filename" ,
59
+ ["e" , "none" , "enum-option" ],
60
+ "+An enum, doesn't actually do anything" ,
61
+ "+Values: foo | bar | baz" ,
62
+ ["l" , "linenum" , "line-num" ],
63
+ "+A line number" ,
64
+ ["s" , "shlib-name" , "shlib-name" ],
65
+ "+A shared library name" ,
66
+ ]
67
+ substrs = [
68
+ "Example command for use in debugging" ,
69
+ "Syntax: no-args <cmd-options>" ,
70
+ ]
71
+
66
72
self .check_help_options ("no-args" , no_arg_opts , substrs )
67
73
68
74
# Make sure the command doesn't accept arguments:
69
- self .expect ("no-args an-arg" , substrs = ["'no-args' doesn't take any arguments." ],
70
- error = True )
75
+ self .expect (
76
+ "no-args an-arg" ,
77
+ substrs = ["'no-args' doesn't take any arguments." ],
78
+ error = True ,
79
+ )
71
80
72
81
# Try setting the bool with the wrong value:
73
- self .expect ("no-args -b Something" ,
74
- substrs = ["Error setting option: bool-arg to Something" ],
75
- error = True )
82
+ self .expect (
83
+ "no-args -b Something" ,
84
+ substrs = ["Error setting option: bool-arg to Something" ],
85
+ error = True ,
86
+ )
76
87
# Try setting the enum to an illegal value as well:
77
- self .expect ("no-args --enum-option Something" ,
78
- substrs = ["error: Error setting option: enum-option to Something" ],
79
- error = True )
80
-
88
+ self .expect (
89
+ "no-args --enum-option Something" ,
90
+ substrs = ["error: Error setting option: enum-option to Something" ],
91
+ error = True ,
92
+ )
93
+
81
94
# Check some of the command groups:
82
- self .expect ("no-args -b true -s Something -l 10" ,
83
- substrs = ["error: invalid combination of options for the given command" ],
84
- error = True )
85
-
95
+ self .expect (
96
+ "no-args -b true -s Something -l 10" ,
97
+ substrs = ["error: invalid combination of options for the given command" ],
98
+ error = True ,
99
+ )
100
+
86
101
# Now set the bool arg correctly, note only the first option was set:
87
- self .expect ("no-args -b true" , substrs = ["bool-arg (set: True): True" ,
88
- "shlib-name (set: False):" ,
89
- "disk-file-name (set: False):" ,
90
- "line-num (set: False):" ,
91
- "enum-option (set: False):" ])
102
+ self .expect (
103
+ "no-args -b true" ,
104
+ substrs = [
105
+ "bool-arg (set: True): True" ,
106
+ "shlib-name (set: False):" ,
107
+ "disk-file-name (set: False):" ,
108
+ "line-num (set: False):" ,
109
+ "enum-option (set: False):" ,
110
+ ],
111
+ )
92
112
93
113
# Now set the enum arg correctly, note only the first option was set:
94
- self .expect ("no-args -e foo" , substrs = ["bool-arg (set: False):" ,
95
- "shlib-name (set: False):" ,
96
- "disk-file-name (set: False):" ,
97
- "line-num (set: False):" ,
98
- "enum-option (set: True): foo" ])
114
+ self .expect (
115
+ "no-args -e foo" ,
116
+ substrs = [
117
+ "bool-arg (set: False):" ,
118
+ "shlib-name (set: False):" ,
119
+ "disk-file-name (set: False):" ,
120
+ "line-num (set: False):" ,
121
+ "enum-option (set: True): foo" ,
122
+ ],
123
+ )
99
124
# Try a pair together:
100
- self .expect ("no-args -b false -s Something" , substrs = ["bool-arg (set: True): False" ,
101
- "shlib-name (set: True): Something" ,
102
- "disk-file-name (set: False):" ,
103
- "line-num (set: False):" ,
104
- "enum-option (set: False):" ])
125
+ self .expect (
126
+ "no-args -b false -s Something" ,
127
+ substrs = [
128
+ "bool-arg (set: True): False" ,
129
+ "shlib-name (set: True): Something" ,
130
+ "disk-file-name (set: False):" ,
131
+ "line-num (set: False):" ,
132
+ "enum-option (set: False):" ,
133
+ ],
134
+ )
105
135
106
136
# Next try some completion tests:
107
137
108
138
interp = self .dbg .GetCommandInterpreter ()
109
139
matches = lldb .SBStringList ()
110
140
descriptions = lldb .SBStringList ()
111
141
112
- # First try an enum completion:
113
- num_completions = interp .HandleCompletionWithDescriptions ("no-args -e f" , 12 , 0 ,
114
- 1000 , matches , descriptions )
142
+ # First try an enum completion:
143
+ num_completions = interp .HandleCompletionWithDescriptions (
144
+ "no-args -e f" , 12 , 0 , 1000 , matches , descriptions
145
+ )
115
146
self .assertEqual (num_completions , 1 , "Only one completion for foo" )
116
- self .assertEqual (matches .GetSize (), 2 , "The first element is the complete additional text" )
117
- self .assertEqual (matches .GetStringAtIndex (0 ), "oo " , "And we got the right extra characters" )
118
- self .assertEqual (matches .GetStringAtIndex (1 ), "foo" , "And we got the right match" )
119
- self .assertEqual (descriptions .GetSize (), 2 , "descriptions matche the return length" )
147
+ self .assertEqual (
148
+ matches .GetSize (), 2 , "The first element is the complete additional text"
149
+ )
150
+ self .assertEqual (
151
+ matches .GetStringAtIndex (0 ), "oo " , "And we got the right extra characters"
152
+ )
153
+ self .assertEqual (
154
+ matches .GetStringAtIndex (1 ), "foo" , "And we got the right match"
155
+ )
156
+ self .assertEqual (
157
+ descriptions .GetSize (), 2 , "descriptions matche the return length"
158
+ )
120
159
# FIXME: we don't return descriptions for enum elements
121
- #self.assertEqual(descriptions.GetStringAtIndex(1), "does foo things", "And we got the right description")
160
+ # self.assertEqual(descriptions.GetStringAtIndex(1), "does foo things", "And we got the right description")
122
161
123
162
# Now try an internal completer, the on disk file one is handy:
124
163
partial_name = os .path .join (source_dir , "test_" )
125
164
cmd_str = f"no-args -d '{ partial_name } '"
126
165
127
166
matches .Clear ()
128
167
descriptions .Clear ()
129
- num_completions = interp .HandleCompletionWithDescriptions (cmd_str , len (cmd_str ) - 1 , 0 ,
130
- 1000 , matches , descriptions )
131
- print (f"First: { matches .GetStringAtIndex (0 )} \n Second: { matches .GetStringAtIndex (1 )} \n Third: { matches .GetStringAtIndex (2 )} " )
168
+ num_completions = interp .HandleCompletionWithDescriptions (
169
+ cmd_str , len (cmd_str ) - 1 , 0 , 1000 , matches , descriptions
170
+ )
171
+ print (
172
+ f"First: { matches .GetStringAtIndex (0 )} \n Second: { matches .GetStringAtIndex (1 )} \n Third: { matches .GetStringAtIndex (2 )} "
173
+ )
132
174
self .assertEqual (num_completions , 1 , "Only one completion for source file" )
133
175
self .assertEqual (matches .GetSize (), 2 , "The first element is the complete line" )
134
- self .assertEqual (matches .GetStringAtIndex (0 ), "commands.py' " , "And we got the right extra characters" )
135
- self .assertEqual (matches .GetStringAtIndex (1 ), test_file_path , "And we got the right match" )
136
- self .assertEqual (descriptions .GetSize (), 2 , "descriptions match the return length" )
176
+ self .assertEqual (
177
+ matches .GetStringAtIndex (0 ),
178
+ "commands.py' " ,
179
+ "And we got the right extra characters" ,
180
+ )
181
+ self .assertEqual (
182
+ matches .GetStringAtIndex (1 ), test_file_path , "And we got the right match"
183
+ )
184
+ self .assertEqual (
185
+ descriptions .GetSize (), 2 , "descriptions match the return length"
186
+ )
137
187
# FIXME: we don't return descriptions for enum elements
138
- #self.assertEqual(descriptions.GetStringAtIndex(1), "does foo things", "And we got the right description")
139
-
188
+ # self.assertEqual(descriptions.GetStringAtIndex(1), "does foo things", "And we got the right description")
189
+
140
190
# Try a command with arguments.
141
191
# FIXME: It should be enough to define an argument and it's type to get the completer
142
192
# wired up for that argument type if it is a known type. But that isn't wired up in the
143
193
# command parser yet, so I don't have any tests for that. We also don't currently check
144
194
# that the arguments passed match the argument specifications, so here I just pass a couple
145
195
# sets of arguments and make sure we get back what we put in:
146
- self .expect ("two-args 'First Argument' 'Second Argument'" , substrs = ["0: First Argument" , "1: Second Argument" ])
196
+ self .expect (
197
+ "two-args 'First Argument' 'Second Argument'" ,
198
+ substrs = ["0: First Argument" , "1: Second Argument" ],
199
+ )
0 commit comments