Run shellcheck on bash completion
This commit is contained in:
@ -4,6 +4,7 @@ import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
@ -23,6 +24,26 @@ func check(t *testing.T, found, expected string) {
|
||||
}
|
||||
}
|
||||
|
||||
func runShellCheck(s string) error {
|
||||
excluded := []string{
|
||||
"SC2034", // PREFIX appears unused. Verify it or export it.
|
||||
}
|
||||
cmd := exec.Command("shellcheck", "-s", "bash", "-", "-e", strings.Join(excluded, ","))
|
||||
cmd.Stderr = os.Stderr
|
||||
cmd.Stdout = os.Stdout
|
||||
|
||||
stdin, err := cmd.StdinPipe()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
go func() {
|
||||
defer stdin.Close()
|
||||
stdin.Write([]byte(s))
|
||||
}()
|
||||
|
||||
return cmd.Run()
|
||||
}
|
||||
|
||||
// World worst custom function, just keep telling you to enter hello!
|
||||
const (
|
||||
bashCompletionFunc = `__custom_func() {
|
||||
@ -107,4 +128,13 @@ func TestBashCompletions(t *testing.T) {
|
||||
check(t, str, `flags_completion+=("__handle_subdirs_in_dir_flag themes")`)
|
||||
|
||||
checkOmit(t, str, cmdDeprecated.Name())
|
||||
|
||||
// if available, run shellcheck against the script
|
||||
if err := exec.Command("which", "shellcheck").Run(); err != nil {
|
||||
return
|
||||
}
|
||||
err := runShellCheck(str)
|
||||
if err != nil {
|
||||
t.Fatalf("shellcheck failed: %v", err)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user