Unverified Commit 50366976 authored by MatteoPologruto's avatar MatteoPologruto Committed by GitHub

[skip-changelog] Migrate tests from `test_completion.py` to `completion_test.go` (#1844)

* Migrated TestCompletionNoArgs from test_completion.py to completion_test.go

* Migrated TestCompletionBash from test_completion.py to completion_test.go

* Migrated TestCompletionZsh from test_completion.py to completion_test.go

* Migrated TestCompletionFish from test_completion.py to completion_test.go

* Migrated TestCompletionPowershell from test_completion.py to completion_test.go

* Migrated TestCompletionBashNoDesc from test_completion.py to completion_test.go

* Migrated TestCompletionZshNoDesc from test_completion.py to completion_test.go

* Migrated TestCompletionFishNoDesc from test_completion.py to completion_test.go

* Migrated TestCompletionPowershellNoDesc from test_completion.py to completion_test.go

* Migrated TestStaticCompletions from test_completion.py to completion_test.go

* Migrated TestConfigCompletion from test_completion.py to completion_test.go

* Migrated TestLibCompletion from test_completion.py to completion_test.go

* Migrated TestCoreCompletion to completion_test.go and deleted test_completion.py
parent fd63b210
// This file is part of arduino-cli.
//
// Copyright 2022 ARDUINO SA (http://www.arduino.cc/)
//
// This software is released under the GNU General Public License version 3,
// which covers the main part of arduino-cli.
// The terms of this license can be found at:
// https://www.gnu.org/licenses/gpl-3.0.en.html
//
// You can be released from the requirements of the above licenses by purchasing
// a commercial license. Buying such a license is mandatory if you want to
// modify or otherwise use the software for commercial activities involving the
// Arduino software without disclosing the source code of your own applications.
// To purchase a commercial license, send an email to license@arduino.cc.
package completion_test
import (
"testing"
"github.com/arduino/arduino-cli/internal/integrationtest"
"github.com/stretchr/testify/require"
)
// test if the completion command behaves correctly
func TestCompletionNoArgs(t *testing.T) {
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
defer env.CleanUp()
stdout, stderr, err := cli.Run("completion")
require.Error(t, err)
require.Contains(t, string(stderr), "Error: accepts 1 arg(s), received 0")
require.Empty(t, stdout)
}
func TestCompletionBash(t *testing.T) {
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
defer env.CleanUp()
stdout, stderr, err := cli.Run("completion", "bash")
require.NoError(t, err)
require.Empty(t, stderr)
require.Contains(t, string(stdout), "# bash completion V2 for arduino-cli")
require.Contains(t, string(stdout), "__start_arduino-cli()")
}
func TestCompletionZsh(t *testing.T) {
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
defer env.CleanUp()
stdout, stderr, err := cli.Run("completion", "zsh")
require.NoError(t, err)
require.Empty(t, stderr)
require.Contains(t, string(stdout), "#compdef _arduino-cli arduino-cli")
require.Contains(t, string(stdout), "_arduino-cli()")
}
func TestCompletionFish(t *testing.T) {
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
defer env.CleanUp()
stdout, stderr, err := cli.Run("completion", "fish")
require.NoError(t, err)
require.Empty(t, stderr)
require.Contains(t, string(stdout), "# fish completion for arduino-cli")
require.Contains(t, string(stdout), "function __arduino_cli_perform_completion")
}
func TestCompletionPowershell(t *testing.T) {
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
defer env.CleanUp()
stdout, stderr, err := cli.Run("completion", "powershell")
require.NoError(t, err)
require.Empty(t, stderr)
require.Contains(t, string(stdout), "# powershell completion for arduino-cli")
require.Contains(t, string(stdout), "Register-ArgumentCompleter -CommandName 'arduino-cli' -ScriptBlock")
}
func TestCompletionBashNoDesc(t *testing.T) {
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
defer env.CleanUp()
stdout, stderr, err := cli.Run("completion", "bash", "--no-descriptions")
require.NoError(t, err)
require.Empty(t, stderr)
require.Contains(t, string(stdout), "# bash completion V2 for arduino-cli")
require.Contains(t, string(stdout), "__start_arduino-cli()")
require.Contains(t, string(stdout), "__completeNoDesc")
}
func TestCompletionZshNoDesc(t *testing.T) {
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
defer env.CleanUp()
stdout, stderr, err := cli.Run("completion", "zsh", "--no-descriptions")
require.NoError(t, err)
require.Empty(t, stderr)
require.Contains(t, string(stdout), "#compdef _arduino-cli arduino-cli")
require.Contains(t, string(stdout), "_arduino-cli()")
require.Contains(t, string(stdout), "__completeNoDesc")
}
func TestCompletionFishNoDesc(t *testing.T) {
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
defer env.CleanUp()
stdout, stderr, err := cli.Run("completion", "fish", "--no-descriptions")
require.NoError(t, err)
require.Empty(t, stderr)
require.Contains(t, string(stdout), "# fish completion for arduino-cli")
require.Contains(t, string(stdout), "function __arduino_cli_perform_completion")
require.Contains(t, string(stdout), "__completeNoDesc")
}
func TestCompletionPowershellNoDesc(t *testing.T) {
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
defer env.CleanUp()
stdout, stderr, err := cli.Run("completion", "powershell", "--no-descriptions")
require.Error(t, err)
require.Empty(t, stdout)
require.Contains(t, string(stderr), "Error: command description is not supported by powershell")
}
// test if the completion suggestions returned are meaningful
// we use the __complete hidden command
// https://github.com/spf13/cobra/blob/master/shell_completions.md#debugging
// test static completions
func TestStaticCompletions(t *testing.T) {
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
defer env.CleanUp()
stdout, _, _ := cli.Run("__complete", "--format", "")
require.Contains(t, string(stdout), "json")
stdout, _, _ = cli.Run("__complete", "--log-format", "")
require.Contains(t, string(stdout), "json")
stdout, _, _ = cli.Run("__complete", "--log-level", "")
require.Contains(t, string(stdout), "trace")
}
// here we test if the completions coming from the core are working
func TestConfigCompletion(t *testing.T) {
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
defer env.CleanUp()
stdout, _, _ := cli.Run("__complete", "config", "add", "")
require.Contains(t, string(stdout), "board_manager.additional_urls")
stdout, _, _ = cli.Run("__complete", "config", "remove", "")
require.Contains(t, string(stdout), "board_manager.additional_urls")
stdout, _, _ = cli.Run("__complete", "config", "delete", "")
require.Contains(t, string(stdout), "board_manager.additional_urls")
stdout, _, _ = cli.Run("__complete", "config", "set", "")
require.Contains(t, string(stdout), "board_manager.additional_urls")
}
// here we test if the completions coming from the libs are working
func TestLibCompletion(t *testing.T) {
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
defer env.CleanUp()
_, _, err := cli.Run("lib", "update-index")
require.NoError(t, err)
stdout, _, _ := cli.Run("__complete", "lib", "install", "")
require.Contains(t, string(stdout), "WiFi101")
stdout, _, _ = cli.Run("__complete", "lib", "download", "")
require.Contains(t, string(stdout), "WiFi101")
stdout, _, _ = cli.Run("__complete", "lib", "uninstall", "")
require.NotContains(t, string(stdout), "WiFi101") // not yet installed
_, _, err = cli.Run("lib", "install", "Wifi101")
require.NoError(t, err)
stdout, _, _ = cli.Run("__complete", "lib", "uninstall", "")
require.Contains(t, string(stdout), "WiFi101")
stdout, _, _ = cli.Run("__complete", "lib", "examples", "")
require.Contains(t, string(stdout), "WiFi101")
stdout, _, _ = cli.Run("__complete", "lib", "deps", "")
require.Contains(t, string(stdout), "WiFi101")
}
// here we test if the completions coming from the core are working
func TestCoreCompletion(t *testing.T) {
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
defer env.CleanUp()
_, _, err := cli.Run("core", "update-index")
require.NoError(t, err)
stdout, _, _ := cli.Run("__complete", "core", "install", "")
require.Contains(t, string(stdout), "arduino:avr")
stdout, _, _ = cli.Run("__complete", "core", "download", "")
require.Contains(t, string(stdout), "arduino:avr")
stdout, _, _ = cli.Run("__complete", "core", "uninstall", "")
require.NotContains(t, string(stdout), "arduino:avr")
// we install a core because the provided completions comes from it
_, _, err = cli.Run("core", "install", "arduino:avr@1.8.3")
require.NoError(t, err)
stdout, _, _ = cli.Run("__complete", "core", "uninstall", "")
require.Contains(t, string(stdout), "arduino:avr")
stdout, _, _ = cli.Run("__complete", "board", "details", "-b", "")
require.Contains(t, string(stdout), "arduino:avr:uno")
stdout, _, _ = cli.Run("__complete", "burn-bootloader", "-b", "")
require.Contains(t, string(stdout), "arduino:avr:uno")
stdout, _, _ = cli.Run("__complete", "compile", "-b", "")
require.Contains(t, string(stdout), "arduino:avr:uno")
stdout, _, _ = cli.Run("__complete", "debug", "-b", "")
require.Contains(t, string(stdout), "arduino:avr:uno")
stdout, _, _ = cli.Run("__complete", "lib", "examples", "-b", "")
require.Contains(t, string(stdout), "arduino:avr:uno")
stdout, _, _ = cli.Run("__complete", "upload", "-b", "")
require.Contains(t, string(stdout), "arduino:avr:uno")
stdout, _, _ = cli.Run("__complete", "monitor", "-b", "")
require.Contains(t, string(stdout), "arduino:avr:uno")
stdout, _, _ = cli.Run("__complete", "burn-bootloader", "-l", "")
require.Contains(t, string(stdout), "network")
stdout, _, _ = cli.Run("__complete", "compile", "-l", "")
require.Contains(t, string(stdout), "network")
stdout, _, _ = cli.Run("__complete", "debug", "-l", "")
require.Contains(t, string(stdout), "network")
stdout, _, _ = cli.Run("__complete", "upload", "-l", "")
require.Contains(t, string(stdout), "network")
stdout, _, _ = cli.Run("__complete", "monitor", "-l", "")
require.Contains(t, string(stdout), "network")
stdout, _, _ = cli.Run("__complete", "burn-bootloader", "-P", "")
require.Contains(t, string(stdout), "atmel_ice")
stdout, _, _ = cli.Run("__complete", "compile", "-P", "")
require.Contains(t, string(stdout), "atmel_ice")
stdout, _, _ = cli.Run("__complete", "debug", "-P", "")
require.Contains(t, string(stdout), "atmel_ice")
stdout, _, _ = cli.Run("__complete", "upload", "-P", "")
require.Contains(t, string(stdout), "atmel_ice")
}
# This file is part of arduino-cli.
#
# Copyright 2020 ARDUINO SA (http://www.arduino.cc/)
#
# This software is released under the GNU General Public License version 3,
# which covers the main part of arduino-cli.
# The terms of this license can be found at:
# https://www.gnu.org/licenses/gpl-3.0.en.html
#
# You can be released from the requirements of the above licenses by purchasing
# a commercial license. Buying such a license is mandatory if you want to modify or
# otherwise use the software for commercial activities involving the Arduino
# software without disclosing the source code of your own applications. To purchase
# a commercial license, send an email to license@arduino.cc.
# test if the completion command behaves correctly
def test_completion_no_args(run_command):
result = run_command(["completion"])
assert not result.ok
assert "Error: accepts 1 arg(s), received 0" in result.stderr
assert result.stdout == ""
def test_completion_bash(run_command):
result = run_command(["completion", "bash"])
assert result.ok
assert result.stderr == ""
assert "# bash completion V2 for arduino-cli" in result.stdout
assert "__start_arduino-cli()" in result.stdout
def test_completion_zsh(run_command):
result = run_command(["completion", "zsh"])
assert result.ok
assert result.stderr == ""
assert "#compdef _arduino-cli arduino-cli" in result.stdout
assert "_arduino-cli()" in result.stdout
def test_completion_fish(run_command):
result = run_command(["completion", "fish"])
assert result.ok
assert result.stderr == ""
assert "# fish completion for arduino-cli" in result.stdout
assert "function __arduino_cli_perform_completion" in result.stdout
def test_completion_powershell(run_command):
result = run_command(["completion", "powershell"])
assert result.ok
assert result.stderr == ""
assert "# powershell completion for arduino-cli" in result.stdout
assert "Register-ArgumentCompleter -CommandName 'arduino-cli' -ScriptBlock" in result.stdout
def test_completion_bash_no_desc(run_command):
result = run_command(["completion", "bash", "--no-descriptions"])
assert result.ok
assert result.stderr == ""
assert "# bash completion V2 for arduino-cli" in result.stdout
assert "__start_arduino-cli()" in result.stdout
assert "__completeNoDesc" in result.stdout
def test_completion_zsh_no_desc(run_command):
result = run_command(["completion", "zsh", "--no-descriptions"])
assert result.ok
assert result.stderr == ""
assert "#compdef _arduino-cli arduino-cli" in result.stdout
assert "_arduino-cli()" in result.stdout
assert "__completeNoDesc" in result.stdout
def test_completion_fish_no_desc(run_command):
result = run_command(["completion", "fish", "--no-descriptions"])
assert result.ok
assert result.stderr == ""
assert "# fish completion for arduino-cli" in result.stdout
assert "function __arduino_cli_perform_completion" in result.stdout
assert "__completeNoDesc" in result.stdout
def test_completion_powershell_no_desc(run_command):
result = run_command(["completion", "powershell", "--no-descriptions"])
assert not result.ok
assert result.stdout == ""
assert "Error: command description is not supported by powershell" in result.stderr
# test if the completion suggestions returned are meaningful
# we use the __complete hidden command
# https://github.com/spf13/cobra/blob/master/shell_completions.md#debugging
# test static completions
def test_static_completions(run_command):
result = run_command(
[
"__complete",
"--format",
"",
]
)
assert "json" in result.stdout
result = run_command(
[
"__complete",
"--log-format",
"",
]
)
assert "json" in result.stdout
result = run_command(
[
"__complete",
"--log-level",
"",
]
)
assert "trace" in result.stdout
# here we test if the completions coming from the core are working
def test_config_completion(run_command):
result = run_command(["__complete", "config", "add", ""])
assert "board_manager.additional_urls" in result.stdout
result = run_command(["__complete", "config", "remove", ""])
assert "board_manager.additional_urls" in result.stdout
result = run_command(["__complete", "config", "delete", ""])
assert "board_manager.additional_urls" in result.stdout
result = run_command(["__complete", "config", "set", ""])
assert "board_manager.additional_urls" in result.stdout
# here we test if the completions coming from the libs are working
def test_lib_completion(run_command):
assert run_command(["lib", "update-index"])
result = run_command(["__complete", "lib", "install", ""], hide=True)
assert "WiFi101" in result.stdout
result = run_command(["__complete", "lib", "download", ""], hide=True)
assert "WiFi101" in result.stdout
result = run_command(["__complete", "lib", "uninstall", ""], hide=True)
assert "WiFi101" not in result.stdout # not yet installed
assert run_command(["lib", "install", "WiFi101"])
result = run_command(["__complete", "lib", "uninstall", ""])
assert "WiFi101" in result.stdout
result = run_command(["__complete", "lib", "examples", ""])
assert "WiFi101" in result.stdout
result = run_command(["__complete", "lib", "deps", ""])
assert "WiFi101" in result.stdout
# here we test if the completions coming from the core are working
def test_core_completion(run_command):
assert run_command(["core", "update-index"])
result = run_command(["__complete", "core", "install", ""])
assert "arduino:avr" in result.stdout
result = run_command(["__complete", "core", "download", ""])
assert "arduino:avr" in result.stdout
result = run_command(["__complete", "core", "uninstall", ""])
assert "arduino:avr" not in result.stdout
# we install a core because the provided completions comes from it
assert run_command(["core", "install", "arduino:avr@1.8.3"])
result = run_command(["__complete", "core", "uninstall", ""])
assert "arduino:avr" in result.stdout
result = run_command(["__complete", "board", "details", "-b", ""])
assert "arduino:avr:uno" in result.stdout
result = run_command(["__complete", "burn-bootloader", "-b", ""])
assert "arduino:avr:uno" in result.stdout
result = run_command(["__complete", "compile", "-b", ""])
assert "arduino:avr:uno" in result.stdout
result = run_command(["__complete", "debug", "-b", ""])
assert "arduino:avr:uno" in result.stdout
result = run_command(["__complete", "lib", "examples", "-b", ""])
assert "arduino:avr:uno" in result.stdout
result = run_command(["__complete", "upload", "-b", ""])
assert "arduino:avr:uno" in result.stdout
result = run_command(["__complete", "monitor", "-b", ""])
assert "arduino:avr:uno" in result.stdout
result = run_command(["__complete", "burn-bootloader", "-l", ""])
assert "network" in result.stdout
result = run_command(["__complete", "compile", "-l", ""])
assert "network" in result.stdout
result = run_command(["__complete", "debug", "-l", ""])
assert "network" in result.stdout
result = run_command(["__complete", "upload", "-l", ""])
assert "network" in result.stdout
result = run_command(["__complete", "monitor", "-l", ""])
assert "network" in result.stdout
result = run_command(["__complete", "burn-bootloader", "-P", ""])
assert "atmel_ice" in result.stdout
result = run_command(["__complete", "compile", "-P", ""])
assert "atmel_ice" in result.stdout
result = run_command(["__complete", "debug", "-P", ""])
assert "atmel_ice" in result.stdout
result = run_command(["__complete", "upload", "-P", ""])
assert "atmel_ice" in result.stdout
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment