Move auto_notify_send tests to their own file
This commit is contained in:
parent
61a838cbcc
commit
e25849a979
2 changed files with 123 additions and 118 deletions
|
@ -2,23 +2,6 @@
|
||||||
|
|
||||||
@setup {
|
@setup {
|
||||||
load "../auto-notify.plugin.zsh"
|
load "../auto-notify.plugin.zsh"
|
||||||
|
|
||||||
function notify-send {
|
|
||||||
echo - "Notification: $@"
|
|
||||||
}
|
|
||||||
|
|
||||||
function uname {
|
|
||||||
echo - "Linux"
|
|
||||||
}
|
|
||||||
|
|
||||||
# Mock date function to return a frozen timestamp
|
|
||||||
function date {
|
|
||||||
if [[ "$1" == +"%s" ]]; then
|
|
||||||
echo - "11100"
|
|
||||||
else
|
|
||||||
date - "$@"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@test 'version exported' {
|
@test 'version exported' {
|
||||||
|
@ -43,104 +26,3 @@
|
||||||
assert '_auto_notify_track' in $preexec_functions
|
assert '_auto_notify_track' in $preexec_functions
|
||||||
assert '_auto_notify_send' in $precmd_functions
|
assert '_auto_notify_send' in $precmd_functions
|
||||||
}
|
}
|
||||||
|
|
||||||
@test 'auto-notify-send does not send notification if tracking not set' {
|
|
||||||
unset AUTO_COMMAND
|
|
||||||
unset AUTO_COMMAND_FULL
|
|
||||||
unset AUTO_COMMAND_START
|
|
||||||
|
|
||||||
run _auto_notify_send
|
|
||||||
|
|
||||||
assert $state equals 0
|
|
||||||
assert "$output" is_empty
|
|
||||||
}
|
|
||||||
|
|
||||||
@test 'auto-notify-send does not send notification for short task' {
|
|
||||||
AUTO_COMMAND="foo bar -r"
|
|
||||||
AUTO_COMMAND_FULL="foo bar -r"
|
|
||||||
AUTO_COMMAND_START=11099
|
|
||||||
run _auto_notify_send
|
|
||||||
|
|
||||||
assert $state equals 0
|
|
||||||
assert "$output" is_empty
|
|
||||||
}
|
|
||||||
|
|
||||||
@test 'auto-notify-send does not send notification for ignored commands' {
|
|
||||||
for command in $AUTO_NOTIFY_IGNORE; do
|
|
||||||
AUTO_COMMAND="somealias"
|
|
||||||
AUTO_COMMAND_FULL="$command"
|
|
||||||
AUTO_COMMAND_START=11000
|
|
||||||
run _auto_notify_send
|
|
||||||
|
|
||||||
assert $state equals 0
|
|
||||||
assert "$output" is_empty
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
@test 'auto-notify-send does not send notification for ignored piped commands' {
|
|
||||||
AUTO_COMMAND="echo hello world | less -r"
|
|
||||||
AUTO_COMMAND_FULL="echo hello world | less -r"
|
|
||||||
AUTO_COMMAND_START=11000
|
|
||||||
run _auto_notify_send
|
|
||||||
|
|
||||||
assert $state equals 0
|
|
||||||
assert "$output" is_empty
|
|
||||||
}
|
|
||||||
|
|
||||||
@test 'auto-notify-send does not send notification for ignored commands with arguments' {
|
|
||||||
for command in $AUTO_NOTIFY_IGNORE; do
|
|
||||||
AUTO_COMMAND="somealias bar -r"
|
|
||||||
AUTO_COMMAND_FULL="$command bar -r"
|
|
||||||
AUTO_COMMAND_START=11000
|
|
||||||
run _auto_notify_send
|
|
||||||
|
|
||||||
assert $state equals 0
|
|
||||||
assert "$output" is_empty
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
@test 'auto-notify-send sends notification on Linux' {
|
|
||||||
AUTO_COMMAND="f bar -r"
|
|
||||||
AUTO_COMMAND_FULL="foo bar -r"
|
|
||||||
AUTO_COMMAND_START=11080
|
|
||||||
run _auto_notify_send
|
|
||||||
|
|
||||||
assert $state equals 0
|
|
||||||
assert "$lines[1]" same_as 'Notification: "f bar -r" has completed'
|
|
||||||
assert "$lines[2]" same_as "(Total time: 20 seconds)"
|
|
||||||
}
|
|
||||||
|
|
||||||
@test 'auto-notify-send sends notification on MacOSX' {
|
|
||||||
AUTO_COMMAND="f bar -r"
|
|
||||||
AUTO_COMMAND_FULL="foo bar -r"
|
|
||||||
AUTO_COMMAND_START=11080
|
|
||||||
|
|
||||||
function uname {
|
|
||||||
echo - "Darwin"
|
|
||||||
}
|
|
||||||
|
|
||||||
function osascript {
|
|
||||||
echo - $@
|
|
||||||
}
|
|
||||||
|
|
||||||
run _auto_notify_send
|
|
||||||
|
|
||||||
assert $state equals 0
|
|
||||||
assert "$lines[1]" same_as '-e display notification "\"f bar -r\" has completed'
|
|
||||||
assert "$lines[2]" same_as '(Total time: 20 seconds)" with title "Command Completed"'
|
|
||||||
}
|
|
||||||
|
|
||||||
@test 'auto-notify-send sends warning on unsupported platform' {
|
|
||||||
AUTO_COMMAND="f bar -r"
|
|
||||||
AUTO_COMMAND_FULL="foo bar -r"
|
|
||||||
AUTO_COMMAND_START=11080
|
|
||||||
|
|
||||||
function uname {
|
|
||||||
echo - "Hal9000"
|
|
||||||
}
|
|
||||||
|
|
||||||
run _auto_notify_send
|
|
||||||
assert $state equals 0
|
|
||||||
assert "$lines[1]" same_as "Unknown platform for sending notifications: Hal9000"
|
|
||||||
assert "$lines[2]" same_as "Please post an issue on gitub.com/MichaelAquilina/zsh-auto-notify/issues/"
|
|
||||||
}
|
|
||||||
|
|
123
tests/test_auto_notify_send.zunit
Normal file
123
tests/test_auto_notify_send.zunit
Normal file
|
@ -0,0 +1,123 @@
|
||||||
|
#!/usr/bin/env zunit
|
||||||
|
|
||||||
|
@setup {
|
||||||
|
load "../auto-notify.plugin.zsh"
|
||||||
|
|
||||||
|
function notify-send {
|
||||||
|
echo - "Notification: $@"
|
||||||
|
}
|
||||||
|
|
||||||
|
function uname {
|
||||||
|
echo - "Linux"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Mock date function to return a frozen timestamp
|
||||||
|
function date {
|
||||||
|
if [[ "$1" == +"%s" ]]; then
|
||||||
|
echo - "11100"
|
||||||
|
else
|
||||||
|
date - "$@"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@test 'auto-notify-send does not send notification if tracking not set' {
|
||||||
|
unset AUTO_COMMAND
|
||||||
|
unset AUTO_COMMAND_FULL
|
||||||
|
unset AUTO_COMMAND_START
|
||||||
|
|
||||||
|
run _auto_notify_send
|
||||||
|
|
||||||
|
assert $state equals 0
|
||||||
|
assert "$output" is_empty
|
||||||
|
}
|
||||||
|
|
||||||
|
@test 'auto-notify-send does not send notification for short task' {
|
||||||
|
AUTO_COMMAND="foo bar -r"
|
||||||
|
AUTO_COMMAND_FULL="foo bar -r"
|
||||||
|
AUTO_COMMAND_START=11099
|
||||||
|
run _auto_notify_send
|
||||||
|
|
||||||
|
assert $state equals 0
|
||||||
|
assert "$output" is_empty
|
||||||
|
}
|
||||||
|
|
||||||
|
@test 'auto-notify-send does not send notification for ignored commands' {
|
||||||
|
for command in $AUTO_NOTIFY_IGNORE; do
|
||||||
|
AUTO_COMMAND="somealias"
|
||||||
|
AUTO_COMMAND_FULL="$command"
|
||||||
|
AUTO_COMMAND_START=11000
|
||||||
|
run _auto_notify_send
|
||||||
|
|
||||||
|
assert $state equals 0
|
||||||
|
assert "$output" is_empty
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
@test 'auto-notify-send does not send notification for ignored piped commands' {
|
||||||
|
AUTO_COMMAND="echo hello world | less -r"
|
||||||
|
AUTO_COMMAND_FULL="echo hello world | less -r"
|
||||||
|
AUTO_COMMAND_START=11000
|
||||||
|
run _auto_notify_send
|
||||||
|
|
||||||
|
assert $state equals 0
|
||||||
|
assert "$output" is_empty
|
||||||
|
}
|
||||||
|
|
||||||
|
@test 'auto-notify-send does not send notification for ignored commands with arguments' {
|
||||||
|
for command in $AUTO_NOTIFY_IGNORE; do
|
||||||
|
AUTO_COMMAND="somealias bar -r"
|
||||||
|
AUTO_COMMAND_FULL="$command bar -r"
|
||||||
|
AUTO_COMMAND_START=11000
|
||||||
|
run _auto_notify_send
|
||||||
|
|
||||||
|
assert $state equals 0
|
||||||
|
assert "$output" is_empty
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
@test 'auto-notify-send sends notification on Linux' {
|
||||||
|
AUTO_COMMAND="f bar -r"
|
||||||
|
AUTO_COMMAND_FULL="foo bar -r"
|
||||||
|
AUTO_COMMAND_START=11080
|
||||||
|
run _auto_notify_send
|
||||||
|
|
||||||
|
assert $state equals 0
|
||||||
|
assert "$lines[1]" same_as 'Notification: "f bar -r" has completed'
|
||||||
|
assert "$lines[2]" same_as "(Total time: 20 seconds)"
|
||||||
|
}
|
||||||
|
|
||||||
|
@test 'auto-notify-send sends notification on MacOSX' {
|
||||||
|
AUTO_COMMAND="f bar -r"
|
||||||
|
AUTO_COMMAND_FULL="foo bar -r"
|
||||||
|
AUTO_COMMAND_START=11080
|
||||||
|
|
||||||
|
function uname {
|
||||||
|
echo - "Darwin"
|
||||||
|
}
|
||||||
|
|
||||||
|
function osascript {
|
||||||
|
echo - $@
|
||||||
|
}
|
||||||
|
|
||||||
|
run _auto_notify_send
|
||||||
|
|
||||||
|
assert $state equals 0
|
||||||
|
assert "$lines[1]" same_as '-e display notification "\"f bar -r\" has completed'
|
||||||
|
assert "$lines[2]" same_as '(Total time: 20 seconds)" with title "Command Completed"'
|
||||||
|
}
|
||||||
|
|
||||||
|
@test 'auto-notify-send sends warning on unsupported platform' {
|
||||||
|
AUTO_COMMAND="f bar -r"
|
||||||
|
AUTO_COMMAND_FULL="foo bar -r"
|
||||||
|
AUTO_COMMAND_START=11080
|
||||||
|
|
||||||
|
function uname {
|
||||||
|
echo - "Hal9000"
|
||||||
|
}
|
||||||
|
|
||||||
|
run _auto_notify_send
|
||||||
|
assert $state equals 0
|
||||||
|
assert "$lines[1]" same_as "Unknown platform for sending notifications: Hal9000"
|
||||||
|
assert "$lines[2]" same_as "Please post an issue on gitub.com/MichaelAquilina/zsh-auto-notify/issues/"
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue