49 lines
1.3 KiB
Bash
49 lines
1.3 KiB
Bash
# shellcheck shell=bats
|
|
|
|
load "${MAIN_BASH_IT_DIR?}/test/test_helper.bash"
|
|
|
|
function local_setup_file() {
|
|
setup_libs "preexec" #"command_duration"
|
|
load "${BASH_IT?}/plugins/available/cmd-returned-notify.plugin.bash"
|
|
}
|
|
|
|
@test "plugins cmd-returned-notify: notify after elapsed time" {
|
|
export NOTIFY_IF_COMMAND_RETURNS_AFTER=0
|
|
export LAST_COMMAND_TIME=$(date +%s)
|
|
sleep 1
|
|
run precmd_return_notification
|
|
assert_success
|
|
assert_output $'\a'
|
|
}
|
|
|
|
@test "plugins cmd-returned-notify: do not notify before elapsed time" {
|
|
export NOTIFY_IF_COMMAND_RETURNS_AFTER=10
|
|
export LAST_COMMAND_TIME=$(date +%s)
|
|
sleep 1
|
|
run precmd_return_notification
|
|
assert_success
|
|
assert_output $''
|
|
}
|
|
|
|
@test "plugins cmd-returned-notify: preexec no output" {
|
|
export LAST_COMMAND_TIME=
|
|
run preexec_return_notification
|
|
assert_success
|
|
assert_output ""
|
|
}
|
|
|
|
@test "plugins cmd-returned-notify: preexec no output env set" {
|
|
export LAST_COMMAND_TIME=$(date +%s)
|
|
run preexec_return_notification
|
|
assert_failure
|
|
assert_output ""
|
|
}
|
|
|
|
@test "plugins cmd-returned-notify: preexec set LAST_COMMAND_TIME" {
|
|
export LAST_COMMAND_TIME=
|
|
assert_equal "${LAST_COMMAND_TIME}" ""
|
|
NOW=$(date +%s)
|
|
preexec_return_notification
|
|
assert_equal "${LAST_COMMAND_TIME}" "${NOW}"
|
|
}
|