Skip to content

Commit 61c1a9f

Browse files
committed
add tests
1 parent 739841c commit 61c1a9f

File tree

1 file changed

+110
-0
lines changed

1 file changed

+110
-0
lines changed

test/test_completion.py

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
# a commercial license, send an email to license@arduino.cc.
1515

1616

17+
# test if the completion command behaves correctly
1718
def test_completion_no_args(run_command):
1819
result = run_command(["completion"])
1920
assert not result.ok
@@ -85,3 +86,112 @@ def test_completion_powershell_no_desc(run_command):
8586
assert not result.ok
8687
assert result.stdout == ""
8788
assert "Error: command description is not supported by powershell" in result.stderr
89+
90+
91+
# test if the completion suggestions returned are meaningful
92+
# we use the __complete hidden command
93+
# https://github.com/spf13/cobra/blob/master/shell_completions.md#debugging
94+
95+
# test static completions
96+
def test_static_completions(run_command):
97+
result = run_command(
98+
[
99+
"__complete",
100+
"--format",
101+
"",
102+
]
103+
)
104+
assert "json" in result.stdout
105+
result = run_command(
106+
[
107+
"__complete",
108+
"--log-format",
109+
"",
110+
]
111+
)
112+
assert "json" in result.stdout
113+
result = run_command(
114+
[
115+
"__complete",
116+
"--log-level",
117+
"",
118+
]
119+
)
120+
assert "trace" in result.stdout
121+
122+
123+
# here we test if the completions coming from the core are working
124+
def test_config_completion(run_command):
125+
result = run_command(["__complete", "config", "add", ""])
126+
assert "board_manager.additional_urls" in result.stdout
127+
result = run_command(["__complete", "config", "remove", ""])
128+
assert "board_manager.additional_urls" in result.stdout
129+
result = run_command(["__complete", "config", "delete", ""])
130+
assert "board_manager.additional_urls" in result.stdout
131+
result = run_command(["__complete", "config", "set", ""])
132+
assert "board_manager.additional_urls" in result.stdout
133+
134+
135+
# here we test if the completions coming from the libs are working
136+
def test_lib_completion(run_command):
137+
assert run_command(["lib", "update-index"])
138+
result = run_command(["__complete", "lib", "install", ""])
139+
assert "WiFi101" in result.stdout
140+
result = run_command(["__complete", "lib", "download", ""])
141+
assert "WiFi101" in result.stdout
142+
result = run_command(["__complete", "lib", "uninstall", ""])
143+
assert "WiFi101" not in result.stdout # not yet installed
144+
145+
assert run_command(["lib", "install", "WiFi101"])
146+
result = run_command(["__complete", "lib", "uninstall", ""])
147+
assert "WiFi101" in result.stdout
148+
result = run_command(["__complete", "lib", "examples", ""])
149+
assert "WiFi101" in result.stdout
150+
result = run_command(["__complete", "lib", "deps", ""])
151+
assert "WiFi101" in result.stdout
152+
153+
154+
# here we test if the completions coming from the core are working
155+
def test_core_completion(run_command):
156+
assert run_command(["core", "update-index"])
157+
result = run_command(["__complete", "core", "install", ""])
158+
assert "arduino:avr" in result.stdout
159+
result = run_command(["__complete", "core", "download", ""])
160+
assert "arduino:avr" in result.stdout
161+
result = run_command(["__complete", "core", "uninstall", ""])
162+
assert "arduino:avr" not in result.stdout
163+
164+
# we install a core because the provided completions comes from it
165+
assert run_command(["core", "install", "arduino:avr@1.8.3"])
166+
167+
result = run_command(["__complete", "core", "uninstall", ""])
168+
assert "arduino:avr" in result.stdout
169+
170+
result = run_command(["__complete", "board", "details", "-b", ""])
171+
assert "arduino:avr:uno" in result.stdout
172+
result = run_command(["__complete", "burn-bootloader", "-b", ""])
173+
assert "arduino:avr:uno" in result.stdout
174+
result = run_command(["__complete", "compile", "-b", ""])
175+
assert "arduino:avr:uno" in result.stdout
176+
result = run_command(["__complete", "debug", "-b", ""])
177+
assert "arduino:avr:uno" in result.stdout
178+
result = run_command(["__complete", "lib", "examples", "-b", ""])
179+
assert "arduino:avr:uno" in result.stdout
180+
result = run_command(["__complete", "upload", "-b", ""])
181+
assert "arduino:avr:uno" in result.stdout
182+
result = run_command(["__complete", "burn-bootloader", "-l", ""])
183+
assert "network" in result.stdout
184+
result = run_command(["__complete", "compile", "-l", ""])
185+
assert "network" in result.stdout
186+
result = run_command(["__complete", "debug", "-l", ""])
187+
assert "network" in result.stdout
188+
result = run_command(["__complete", "upload", "-l", ""])
189+
assert "network" in result.stdout
190+
result = run_command(["__complete", "burn-bootloader", "-P", ""])
191+
assert "atmel_ice" in result.stdout
192+
result = run_command(["__complete", "compile", "-P", ""])
193+
assert "atmel_ice" in result.stdout
194+
result = run_command(["__complete", "debug", "-P", ""])
195+
assert "atmel_ice" in result.stdout
196+
result = run_command(["__complete", "upload", "-P", ""])
197+
assert "atmel_ice" in result.stdout

0 commit comments

Comments
 (0)