test/plugin: `shellcheck`
parent
5f11a0d3a2
commit
61247a1b76
|
|
@ -8,37 +8,39 @@ function local_setup_file() {
|
|||
}
|
||||
|
||||
@test 'plugins base: ips()' {
|
||||
declare -r localhost='127.0.0.1'
|
||||
readonly localhost='127.0.0.1'
|
||||
run ips
|
||||
assert_success
|
||||
assert_line $localhost
|
||||
assert_line "$localhost"
|
||||
}
|
||||
|
||||
@test 'plugins base: myip()' {
|
||||
local mask_ip
|
||||
run myip
|
||||
assert_success
|
||||
declare -r mask_ip=$(echo $output | tr -s '[0-9]' '?')
|
||||
[[ $mask_ip == 'Your public IP is:'*'?.?.?.?'* ]]
|
||||
shopt -s extglob
|
||||
mask_ip="${output//+([[:digit:]]|[[:digit:]][[:digit:]]|[[:digit:]][[:digit:]][[:digit:]])/?}" #$(echo "$output" | tr -s '0-9' '?')
|
||||
[[ $mask_ip == 'Your public IP is: ?.?.?.? ' ]]
|
||||
}
|
||||
|
||||
@test 'plugins base: pickfrom()' {
|
||||
stub_file="${BATS_TEST_TMPDIR}/stub_file"
|
||||
printf "l1\nl2\nl3" > $stub_file
|
||||
run pickfrom $stub_file
|
||||
stub_file="${BATS_TEST_TMPDIR?}/stub_file"
|
||||
printf "l1\nl2\nl3" > "$stub_file"
|
||||
run pickfrom "$stub_file"
|
||||
assert_success
|
||||
[[ $output == l? ]]
|
||||
}
|
||||
|
||||
@test 'plugins base: mkcd()' {
|
||||
cd "${BATS_TEST_TMPDIR}"
|
||||
cd "${BATS_TEST_TMPDIR?}"
|
||||
declare -r dir_name="-dir_with_dash"
|
||||
|
||||
# Make sure that the directory does not exist prior to the test
|
||||
rm -rf "${BATS_TEST_TMPDIR}/${dir_name}"
|
||||
rm -rf "${BATS_TEST_TMPDIR:?}/${dir_name}"
|
||||
|
||||
run mkcd "${dir_name}"
|
||||
assert_success
|
||||
assert_dir_exist "${BATS_TEST_TMPDIR}/${dir_name}"
|
||||
assert_dir_exist "${BATS_TEST_TMPDIR?}/${dir_name}"
|
||||
|
||||
mkcd "${dir_name}"
|
||||
assert_equal "${PWD}" "${BATS_TEST_TMPDIR//\/\///}/${dir_name}"
|
||||
|
|
@ -46,20 +48,20 @@ function local_setup_file() {
|
|||
|
||||
@test 'plugins base: lsgrep()' {
|
||||
for i in 1 2 3; do mkdir -p "${BASH_IT}/${i}"; done
|
||||
cd $BASH_IT
|
||||
cd "${BASH_IT?}"
|
||||
run lsgrep 2
|
||||
assert_success
|
||||
assert_equal $output 2
|
||||
assert_equal "$output" 2
|
||||
}
|
||||
|
||||
@test 'plugins base: buf()' {
|
||||
declare -r file="${BATS_TEST_TMPDIR}/file"
|
||||
touch $file
|
||||
declare -r file="${BATS_TEST_TMPDIR?}/file"
|
||||
touch "$file"
|
||||
|
||||
# Take one timestamp before running the `buf` function
|
||||
declare -r stamp1=$(date +%Y%m%d_%H%M%S)
|
||||
|
||||
run buf $file
|
||||
run buf "$file"
|
||||
|
||||
# Take another timestamp after running `buf`.
|
||||
declare -r stamp2=$(date +%Y%m%d_%H%M%S)
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
# shellcheck shell=bats
|
||||
# shellcheck disable=SC2034
|
||||
|
||||
load "${MAIN_BASH_IT_DIR?}/test/test_helper.bash"
|
||||
|
||||
|
|
@ -8,8 +9,8 @@ function local_setup_file() {
|
|||
}
|
||||
|
||||
@test "plugins cmd-returned-notify: notify after elapsed time" {
|
||||
export NOTIFY_IF_COMMAND_RETURNS_AFTER=0
|
||||
export COMMAND_DURATION_START_SECONDS="${EPOCHREALTIME:-$SECONDS}"
|
||||
NOTIFY_IF_COMMAND_RETURNS_AFTER=0
|
||||
COMMAND_DURATION_START_SECONDS="${EPOCHREALTIME:-$SECONDS}"
|
||||
sleep 1
|
||||
run precmd_return_notification
|
||||
assert_success
|
||||
|
|
@ -17,8 +18,8 @@ function local_setup_file() {
|
|||
}
|
||||
|
||||
@test "plugins cmd-returned-notify: do not notify before elapsed time" {
|
||||
export NOTIFY_IF_COMMAND_RETURNS_AFTER=10
|
||||
export COMMAND_DURATION_START_SECONDS="${EPOCHREALTIME:-$SECONDS}"
|
||||
NOTIFY_IF_COMMAND_RETURNS_AFTER=10
|
||||
COMMAND_DURATION_START_SECONDS="${EPOCHREALTIME:-$SECONDS}"
|
||||
sleep 1
|
||||
run precmd_return_notification
|
||||
assert_success
|
||||
|
|
@ -26,13 +27,13 @@ function local_setup_file() {
|
|||
}
|
||||
|
||||
@test "lib command_duration: preexec no output" {
|
||||
export COMMAND_DURATION_START_SECONDS=
|
||||
COMMAND_DURATION_START_SECONDS=
|
||||
run _command_duration_pre_exec
|
||||
assert_success
|
||||
assert_output ""
|
||||
}
|
||||
@test "lib command_duration: preexec set COMMAND_DURATION_START_SECONDS" {
|
||||
export COMMAND_DURATION_START_SECONDS=
|
||||
COMMAND_DURATION_START_SECONDS=
|
||||
assert_equal "${COMMAND_DURATION_START_SECONDS}" ""
|
||||
NOW="${EPOCHREALTIME:-$SECONDS}"
|
||||
_command_duration_pre_exec
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
# shellcheck shell=bats
|
||||
# shellcheck disable=SC2034
|
||||
|
||||
load "${MAIN_BASH_IT_DIR?}/test/test_helper.bash"
|
||||
|
||||
|
|
@ -21,7 +22,7 @@ function setup_go_path()
|
|||
|
||||
@test 'ensure _bash-it-gopath-pathmunge is defined' {
|
||||
{ _command_exists go && go version &>/dev/null; } || skip 'golang not found'
|
||||
load ../../plugins/available/go.plugin
|
||||
load "${BASH_IT?}/plugins/available/go.plugin.bash"
|
||||
run type -t _bash-it-gopath-pathmunge
|
||||
assert_line 'function'
|
||||
}
|
||||
|
|
@ -29,39 +30,39 @@ function setup_go_path()
|
|||
@test 'plugins go: single entry in GOPATH' {
|
||||
{ _command_exists go && go version &>/dev/null; } || skip 'golang not found'
|
||||
setup_go_path "$BASH_IT/test/fixtures/go/gopath"
|
||||
load ../../plugins/available/go.plugin
|
||||
assert_equal "$(cut -d':' -f1 <<<$PATH)" "$BASH_IT/test/fixtures/go/gopath/bin"
|
||||
load "${BASH_IT?}/plugins/available/go.plugin.bash"
|
||||
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'
|
||||
setup_go_path "$BASH_IT/test/fixtures/go/go path"
|
||||
load ../../plugins/available/go.plugin
|
||||
assert_equal "$(cut -d':' -f1 <<<$PATH)" "$BASH_IT/test/fixtures/go/go path/bin"
|
||||
load "${BASH_IT?}/plugins/available/go.plugin.bash"
|
||||
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'
|
||||
setup_go_path "$BASH_IT/test/fixtures/go/go\ path"
|
||||
load ../../plugins/available/go.plugin
|
||||
assert_equal "$(cut -d':' -f1 <<<$PATH)" "$BASH_IT/test/fixtures/go/go\ path/bin"
|
||||
load "${BASH_IT?}/plugins/available/go.plugin.bash"
|
||||
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'
|
||||
setup_go_path "$BASH_IT/test/fixtures/go/gopath"
|
||||
setup_go_path "$BASH_IT/test/fixtures/go/gopath2"
|
||||
load ../../plugins/available/go.plugin
|
||||
assert_equal "$(cut -d':' -f1,2 <<<$PATH)" "$BASH_IT/test/fixtures/go/gopath2/bin:$BASH_IT/test/fixtures/go/gopath/bin"
|
||||
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"
|
||||
}
|
||||
|
||||
@test 'plugins go: multiple entries in GOPATH, with space' {
|
||||
{ _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 ../../plugins/available/go.plugin
|
||||
assert_equal "$(cut -d':' -f1,2 <<<$PATH)" "$BASH_IT/test/fixtures/go/go path/bin:$BASH_IT/test/fixtures/go/gopath/bin"
|
||||
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"
|
||||
}
|
||||
|
||||
@test 'plugins go: multiple entries in GOPATH, with escaped space' {
|
||||
|
|
@ -69,6 +70,6 @@ function setup_go_path()
|
|||
{ _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 ../../plugins/available/go.plugin
|
||||
assert_equal "$(cut -d':' -f1,2 <<<$PATH)" "$BASH_IT/test/fixtures/go/go\ path/bin:$BASH_IT/test/fixtures/go/gopath/bin"
|
||||
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"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ function local_setup_file() {
|
|||
}
|
||||
|
||||
@test "plugins ruby: PATH includes ~/.gem/ruby/bin" {
|
||||
local last_path_entry
|
||||
if ! type ruby >/dev/null; then
|
||||
skip 'ruby not installed'
|
||||
fi
|
||||
|
|
@ -26,6 +27,6 @@ function local_setup_file() {
|
|||
assert_success
|
||||
load "${BASH_IT?}/plugins/available/ruby.plugin.bash"
|
||||
|
||||
local last_path_entry="$(tail -1 <<<"${PATH//:/$'\n'}")"
|
||||
last_path_entry="$(tail -1 <<<"${PATH//:/$'\n'}")"
|
||||
[[ "${last_path_entry}" == "$(ruby -e 'print Gem.user_dir')/bin" ]]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
# shellcheck shell=bats
|
||||
# shellcheck disable=SC2034
|
||||
|
||||
load "${MAIN_BASH_IT_DIR?}/test/test_helper.bash"
|
||||
|
||||
|
|
@ -8,28 +9,28 @@ function local_setup_file() {
|
|||
}
|
||||
|
||||
@test "plugins xterm: shorten command output" {
|
||||
export SHORT_TERM_LINE=true
|
||||
SHORT_TERM_LINE=true
|
||||
run _short-command "${BASH_IT}/test/fixtures/plugin/xterm/files"/*
|
||||
assert_success
|
||||
assert_output "${BASH_IT}/test/fixtures/plugin/xterm/files/arg0"
|
||||
}
|
||||
|
||||
@test "plugins xterm: full command output" {
|
||||
export SHORT_TERM_LINE=false
|
||||
SHORT_TERM_LINE=false
|
||||
run _short-command "${BASH_IT}/test/fixtures/plugin/xterm/files"/*
|
||||
assert_success
|
||||
assert_output "$(echo "${BASH_IT}/test/fixtures/plugin/xterm/files"/*)"
|
||||
}
|
||||
|
||||
@test "plugins xterm: shorten dirname output" {
|
||||
export SHORT_TERM_LINE=true
|
||||
SHORT_TERM_LINE=true
|
||||
run _short-dirname
|
||||
assert_success
|
||||
assert_output "$(basename "${PWD}")"
|
||||
}
|
||||
|
||||
@test "plugins xterm: full dirname output" {
|
||||
export SHORT_TERM_LINE=false
|
||||
SHORT_TERM_LINE=false
|
||||
run _short-dirname
|
||||
assert_success
|
||||
assert_output "${PWD}"
|
||||
|
|
|
|||
Loading…
Reference in New Issue