Skip to content

Commit

Permalink
lib/command_duration: tests & whitespace
Browse files Browse the repository at this point in the history
  • Loading branch information
gaelicWizard committed Feb 13, 2022
1 parent 9917cb1 commit 9726068
Showing 1 changed file with 24 additions and 33 deletions.
57 changes: 24 additions & 33 deletions test/plugins/cmd-returned-notify.plugin.bats
Original file line number Diff line number Diff line change
Expand Up @@ -9,43 +9,34 @@ load ../../lib/command_duration
load ../../plugins/available/cmd-returned-notify.plugin

@test "plugins cmd-returned-notify: notify after elapsed time" {
export NOTIFY_IF_COMMAND_RETURNS_AFTER=0
export COMMAND_DURATION_START_SECONDS="${EPOCHREALTIME:-$SECONDS}"
sleep 1
run precmd_return_notification
assert_success
assert_output $'\a'
export NOTIFY_IF_COMMAND_RETURNS_AFTER=0
export COMMAND_DURATION_START_SECONDS="${EPOCHREALTIME:-$SECONDS}"
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 COMMAND_DURATION_START_SECONDS="${EPOCHREALTIME:-$SECONDS}"
sleep 1
run precmd_return_notification
assert_success
assert_output $''
export NOTIFY_IF_COMMAND_RETURNS_AFTER=10
export COMMAND_DURATION_START_SECONDS="${EPOCHREALTIME:-$SECONDS}"
sleep 1
run precmd_return_notification
assert_success
assert_output $''
}

@test "plugins cmd-returned-notify: preexec no output" {
export COMMAND_DURATION_START_SECONDS=
run _command_duration_pre_exec
assert_success
assert_output ""
@test "lib command_duration: preexec no output" {
export COMMAND_DURATION_START_SECONDS=
run _command_duration_pre_exec
assert_success
assert_output ""
}

@test "plugins cmd-returned-notify: preexec no output env set" {
skip "wut"
export COMMAND_DURATION_START_SECONDS="${EPOCHREALTIME:-$SECONDS}"
run _command_duration_pre_exec
assert_failure
assert_output ""
}

@test "plugins cmd-returned-notify: preexec set COMMAND_DURATION_START_SECONDS" {
export COMMAND_DURATION_START_SECONDS=
assert_equal "${COMMAND_DURATION_START_SECONDS}" ""
NOW="${EPOCHREALTIME:-$SECONDS}"
_command_duration_pre_exec
# We need to make sure to account for nanoseconds...
assert_equal "${COMMAND_DURATION_START_SECONDS%.*}" "${NOW%.*}"
@test "lib command_duration: preexec set COMMAND_DURATION_START_SECONDS" {
export COMMAND_DURATION_START_SECONDS=
assert_equal "${COMMAND_DURATION_START_SECONDS}" ""
NOW="${EPOCHREALTIME:-$SECONDS}"
_command_duration_pre_exec
# We need to make sure to account for nanoseconds...
assert_equal "${COMMAND_DURATION_START_SECONDS%.*}" "${NOW%.*}"
}

0 comments on commit 9726068

Please sign in to comment.