* plugins/base: code style improvements Quote variables, use $@ and $array[@] instead of $*, typeset some integers, remove unneccesasary binary invocation, use shell features when possible, remove `eval`, &c. * plugins/base: conditional function definitions Instead of functions failing when required tools aren't installed, just don't define the function. Alsö, don't redefine del() if it already exists. * plugins/base: rewrite `usage()` Reimplement disk usage function using Bash syntax and simpler layout, without having to invoke an external binary. * plugins/base: revamp `quiet()` New implementation that is even quieter. * plugins/base: `myip()` * plugins/base: `pickfrom()` * plugins/base: `passgen()` Fix `passgen()` to not need `tr`, remove one subshell, and eliminate a useless `echo`. * plugins/base: `mkcd()` * plugins/base: `mkiso()` * plugins/base: remove `banish-cookies()` Adobe Flash is gone with the wind. Alsö, this would be something someone would do *once* and shouldn't be a function... * plugins/base: `lsgrep` is SC2010 The `lsgrep()` function is *itself* explicitly forbidden by `shellcheck` rule SC2010. Alsö, s/`$*`/`$@` * plugins/base: `mkiso()` Expressly handle unbound parameters. * plugins/base: remove `command_exists` * plugin/base: lint SC2154 && SC2144 Newly undisabled `shellcheck` rules * plugin/base: import libs for tests * plugin/base: `shfmt` Apply `shfmt` using current project settings. My apologies to future `git blame` hunters. ♥
78 lines
2.1 KiB
Bash
Executable File
78 lines
2.1 KiB
Bash
Executable File
#!/usr/bin/env bats
|
|
|
|
load ../test_helper
|
|
load "${BASH_IT}/vendor/github.com/erichs/composure/composure.sh"
|
|
load ../../lib/log
|
|
load ../../lib/helpers
|
|
load ../../plugins/available/base.plugin
|
|
|
|
@test 'plugins base: ips()' {
|
|
if [[ $CI ]]; then
|
|
skip 'ifconfig probably requires sudo on TravisCI'
|
|
fi
|
|
|
|
declare -r localhost='127.0.0.1'
|
|
run ips
|
|
assert_success
|
|
assert_line $localhost
|
|
}
|
|
|
|
@test 'plugins base: myip()' {
|
|
run myip
|
|
assert_success
|
|
declare -r mask_ip=$(echo $output | tr -s '[0-9]' '?')
|
|
[[ $mask_ip == 'Your public IP is: ?.?.?.?' ]]
|
|
}
|
|
|
|
@test 'plugins base: pickfrom()' {
|
|
stub_file="${BASH_IT_ROOT}/stub_file"
|
|
printf "l1\nl2\nl3" > $stub_file
|
|
run pickfrom $stub_file
|
|
assert_success
|
|
[[ $output == l? ]]
|
|
}
|
|
|
|
@test 'plugins base: mkcd()' {
|
|
cd "${BASH_IT_ROOT}"
|
|
declare -r dir_name="-dir_with_dash"
|
|
|
|
# Make sure that the directory does not exist prior to the test
|
|
rm -rf "${BASH_IT_ROOT}/${dir_name}"
|
|
|
|
mkcd "${dir_name}"
|
|
assert_success
|
|
assert_dir_exist "${BASH_IT_ROOT}/${dir_name}"
|
|
assert_equal "${PWD}" "${BASH_IT_ROOT}/${dir_name}"
|
|
}
|
|
|
|
@test 'plugins base: lsgrep()' {
|
|
for i in 1 2 3; do mkdir -p "${BASH_IT_TEST_DIR}/${i}"; done
|
|
cd $BASH_IT_TEST_DIR
|
|
run lsgrep 2
|
|
assert_success
|
|
assert_equal $output 2
|
|
}
|
|
|
|
@test 'plugins base: buf()' {
|
|
declare -r file="${BASH_IT_ROOT}/file"
|
|
touch $file
|
|
|
|
# Take one timestamp before running the `buf` function
|
|
declare -r stamp1=$(date +%Y%m%d_%H%M%S)
|
|
|
|
run buf $file
|
|
|
|
# Take another timestamp after running `buf`.
|
|
declare -r stamp2=$(date +%Y%m%d_%H%M%S)
|
|
|
|
# Verify that the backup file ends with one of the two timestamps.
|
|
# This is done to avoid race conditions where buf is run close to the end
|
|
# of a second, in which case the second timestamp might be in the next second,
|
|
# causing the test to fail.
|
|
# By using `or` for the two checks, we can verify that one of the two files is present.
|
|
# In most cases, it's going to have the same timestamp anyway.
|
|
# We can't use `assert_file_exist` here, since it only checks for a single file name.
|
|
assert [ -e "${file}_${stamp1}" \
|
|
-o -e "${file}_${stamp2}" ]
|
|
}
|