test: `shfmt`

My apologies to future `git blame` hunters ♥
pull/2106/head
John D Pell 2022-03-04 14:21:24 -08:00
parent 810c52f91a
commit d37505b636
20 changed files with 1688 additions and 1695 deletions

View File

@ -20,7 +20,6 @@ repos:
- id: git-check # Configure in .gitattributes
- id: shellcheck
- id: shfmt
exclude: ".bats$"
- repo: https://github.com/Lucas-C/pre-commit-hooks
rev: v1.1.7
hooks:

View File

@ -35,7 +35,7 @@ function __check_completion() {
fi
# Word index of the last word
COMP_CWORD=$(( ${#COMP_WORDS[@]} - 1 ))
COMP_CWORD=$((${#COMP_WORDS[@]} - 1))
# Run the Bash-it completion function
_bash-it

View File

@ -534,8 +534,7 @@ function __migrate_all_components() {
one_type="${2:-}"
priority="${3:-}"
for f in "${BASH_IT}/$subdirectory/available/"*.bash
do
for f in "${BASH_IT}/$subdirectory/available/"*.bash; do
to_enable=$(basename "$f")
if [[ -z "$priority" ]]; then
ln -s "../available/$to_enable" "${BASH_IT}/${subdirectory}/enabled/$to_enable"

View File

@ -43,7 +43,6 @@ function local_setup_file() {
assert_output "ERROR: default: test test test"
}
@test "lib log: basic debug logging with BASH_IT_LOG_LEVEL_ERROR" {
BASH_IT_LOG_LEVEL=${BASH_IT_LOG_LEVEL_ERROR?}
run _log_debug "test test test"

View File

@ -23,12 +23,10 @@ function local_setup() {
assert_success
assert_line -n 0 ' aliases: git gitsvn '
assert_line -n 1 -p ' plugins:'
for plugin in "autojump" "git" "gitstatus" "git-subrepo" "jgitflow" "jump"
do
for plugin in "autojump" "git" "gitstatus" "git-subrepo" "jgitflow" "jump"; do
assert_line -n 1 -p "$plugin"
done
for completion in "git" "git_flow" "git_flow_avh" "github-cli"
do
for completion in "git" "git_flow" "git_flow_avh" "github-cli"; do
assert_line -n 2 -p "$completion"
done
}

View File

@ -200,12 +200,11 @@ function setup_upower {
function upower {
case $1 in
'-e'|'--enumerate')
'-e' | '--enumerate')
printf '%s\n' "$BAT0" "/org/freedesktop/UPower/devices/mouse_hid_${RANDOM}_battery"
;;
'-i'|'--show-info')
if [[ $2 == "$BAT0" ]]
then
'-i' | '--show-info')
if [[ $2 == "$BAT0" ]]; then
printf "voltage: 12.191 V\n time to full: 57.3 minutes\n percentage: %s\n capacity: 84.6964" "${percent}"
else
false

View File

@ -7,8 +7,7 @@ function local_setup_file() {
setup_libs "helpers"
}
function setup_go_path()
{
function setup_go_path() {
local go_path="$1"
# Make sure that the requested GO folder is available
@ -21,55 +20,55 @@ function setup_go_path()
# We test `go version` in each test to account for users with goenv and no system go.
@test 'ensure _bash-it-gopath-pathmunge is defined' {
{ _command_exists go && go version &>/dev/null; } || skip 'golang not found'
{ _command_exists go && go version &> /dev/null; } || skip 'golang not found'
load "${BASH_IT?}/plugins/available/go.plugin.bash"
run type -t _bash-it-gopath-pathmunge
assert_line 'function'
}
@test 'plugins go: single entry in GOPATH' {
{ _command_exists go && go version &>/dev/null; } || skip 'golang not found'
{ _command_exists go && go version &> /dev/null; } || skip 'golang not found'
setup_go_path "$BASH_IT/test/fixtures/go/gopath"
load "${BASH_IT?}/plugins/available/go.plugin.bash"
assert_equal "$(cut -d':' -f1 <<<"$PATH")" "$BASH_IT/test/fixtures/go/gopath/bin"
assert_equal "$(cut -d':' -f1 <<< "$PATH")" "$BASH_IT/test/fixtures/go/gopath/bin"
}
@test 'plugins go: single entry in GOPATH, with space' {
{ _command_exists go && go version &>/dev/null; } || skip 'golang not found'
{ _command_exists go && go version &> /dev/null; } || skip 'golang not found'
setup_go_path "$BASH_IT/test/fixtures/go/go path"
load "${BASH_IT?}/plugins/available/go.plugin.bash"
assert_equal "$(cut -d':' -f1 <<<"$PATH")" "$BASH_IT/test/fixtures/go/go path/bin"
assert_equal "$(cut -d':' -f1 <<< "$PATH")" "$BASH_IT/test/fixtures/go/go path/bin"
}
@test 'plugins go: single entry in GOPATH, with escaped space' {
skip 'huh?'
{ _command_exists go && go version &>/dev/null; } || skip 'golang not found'
{ _command_exists go && go version &> /dev/null; } || skip 'golang not found'
setup_go_path "$BASH_IT/test/fixtures/go/go\ path"
load "${BASH_IT?}/plugins/available/go.plugin.bash"
assert_equal "$(cut -d':' -f1 <<<"$PATH")" "$BASH_IT/test/fixtures/go/go\ path/bin"
assert_equal "$(cut -d':' -f1 <<< "$PATH")" "$BASH_IT/test/fixtures/go/go\ path/bin"
}
@test 'plugins go: multiple entries in GOPATH' {
{ _command_exists go && go version &>/dev/null; } || skip 'golang not found'
{ _command_exists go && go version &> /dev/null; } || skip 'golang not found'
setup_go_path "$BASH_IT/test/fixtures/go/gopath"
setup_go_path "$BASH_IT/test/fixtures/go/gopath2"
load "${BASH_IT?}/plugins/available/go.plugin.bash"
assert_equal "$(cut -d':' -f1,2 <<<"$PATH")" "$BASH_IT/test/fixtures/go/gopath2/bin:$BASH_IT/test/fixtures/go/gopath/bin"
assert_equal "$(cut -d':' -f1,2 <<< "$PATH")" "$BASH_IT/test/fixtures/go/gopath2/bin:$BASH_IT/test/fixtures/go/gopath/bin"
}
@test 'plugins go: multiple entries in GOPATH, with space' {
{ _command_exists go && go version &>/dev/null; } || skip 'golang not found'
{ _command_exists go && go version &> /dev/null; } || skip 'golang not found'
setup_go_path "$BASH_IT/test/fixtures/go/gopath"
setup_go_path "$BASH_IT/test/fixtures/go/go path"
load "${BASH_IT?}/plugins/available/go.plugin.bash"
assert_equal "$(cut -d':' -f1,2 <<<"$PATH")" "$BASH_IT/test/fixtures/go/go path/bin:$BASH_IT/test/fixtures/go/gopath/bin"
assert_equal "$(cut -d':' -f1,2 <<< "$PATH")" "$BASH_IT/test/fixtures/go/go path/bin:$BASH_IT/test/fixtures/go/gopath/bin"
}
@test 'plugins go: multiple entries in GOPATH, with escaped space' {
skip 'huh?'
{ _command_exists go && go version &>/dev/null; } || skip 'golang not found'
{ _command_exists go && go version &> /dev/null; } || skip 'golang not found'
setup_go_path "$BASH_IT/test/fixtures/go/gopath"
setup_go_path "$BASH_IT/test/fixtures/go/go path"
load "${BASH_IT?}/plugins/available/go.plugin.bash"
assert_equal "$(cut -d':' -f1,2 <<<"$PATH")" "$BASH_IT/test/fixtures/go/go\ path/bin:$BASH_IT/test/fixtures/go/gopath/bin"
assert_equal "$(cut -d':' -f1,2 <<< "$PATH")" "$BASH_IT/test/fixtures/go/go\ path/bin:$BASH_IT/test/fixtures/go/gopath/bin"
}

View File

@ -17,7 +17,7 @@ function local_setup_file() {
@test "plugins ruby: PATH includes ~/.gem/ruby/bin" {
local last_path_entry
if ! type ruby >/dev/null; then
if ! type ruby > /dev/null; then
skip 'ruby not installed'
fi
@ -27,6 +27,6 @@ function local_setup_file() {
assert_success
load "${BASH_IT?}/plugins/available/ruby.plugin.bash"
last_path_entry="$(tail -1 <<<"${PATH//:/$'\n'}")"
last_path_entry="$(tail -1 <<< "${PATH//:/$'\n'}")"
[[ "${last_path_entry}" == "$(ruby -e 'print Gem.user_dir')/bin" ]]
}