From 73b47b13835442e68192a04e25edbe0c1216cb61 Mon Sep 17 00:00:00 2001 From: Michael Aquilina Date: Sun, 14 Jul 2019 11:39:36 +0100 Subject: [PATCH] Add tests for _auto_notify_send --- auto-notify.plugin.zsh | 2 +- tests/test_auto_notify.zunit | 43 ++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/auto-notify.plugin.zsh b/auto-notify.plugin.zsh index 1b7f87e..eb53703 100644 --- a/auto-notify.plugin.zsh +++ b/auto-notify.plugin.zsh @@ -12,7 +12,7 @@ function _auto_notify_message() { local command="$1" local elapsed="$2" # Run using echo -e in order to make sure notify-send picks up new line - echo -e "'$command' has completed\n(Total time: $elapsed seconds)" + echo -e "\"$command\" has completed\n(Total time: $elapsed seconds)" } function _is_auto_notify_ignored() { diff --git a/tests/test_auto_notify.zunit b/tests/test_auto_notify.zunit index a3dfbcc..20687e3 100644 --- a/tests/test_auto_notify.zunit +++ b/tests/test_auto_notify.zunit @@ -2,6 +2,19 @@ @setup { load "../auto-notify.plugin.zsh" + + function notify-send { + echo "Notification: $@" + } + + # Mock date function to return a frozen timestamp + function date { + if [[ "$1" == +"%s" ]]; then + echo "11100" + else + date "$@" + fi + } } @test 'version exported' { @@ -12,3 +25,33 @@ assert '_auto_notify_track' in $preexec_functions assert '_auto_notify_send' in $precmd_functions } + +@test 'auto-notify-send does not send notification for short task' { + AUTO_COMMAND="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="$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' { + AUTO_COMMAND="foo bar -r" + AUTO_COMMAND_START=11080 + run _auto_notify_send + + assert $state equals 0 + assert "$lines[1]" same_as 'Notification: "foo bar -r" has completed' + assert "$lines[2]" same_as "(Total time: 20 seconds)" +}