From 41117d1b45acf5185346c6914f2b40a3246f94a3 Mon Sep 17 00:00:00 2001 From: Michael Aquilina Date: Mon, 15 Jul 2019 17:04:56 +0100 Subject: [PATCH] Add test for MacOSX notifications --- auto-notify.plugin.zsh | 3 ++- tests/test_auto_notify.zunit | 30 +++++++++++++++++++++++++----- 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/auto-notify.plugin.zsh b/auto-notify.plugin.zsh index be2622c..fe6d809 100644 --- a/auto-notify.plugin.zsh +++ b/auto-notify.plugin.zsh @@ -23,7 +23,7 @@ function _auto_notify_message() { text="$(echo -e "\"$command\" has completed\n(Total time: $elapsed seconds)")" platform="$(uname)" - if [[ "$platform" = "Linux" ]]; then + if [[ "$platform" == "Linux" ]]; then notify-send "$text" elif [[ "$platform" == "Darwin" ]]; then osascript -e "display notification \"$text\" with title \"Command Completed\"" @@ -75,4 +75,5 @@ function enable_auto_notify() { } autoload -Uz add-zsh-hook + enable_auto_notify diff --git a/tests/test_auto_notify.zunit b/tests/test_auto_notify.zunit index ba5e34a..8d6d1c3 100644 --- a/tests/test_auto_notify.zunit +++ b/tests/test_auto_notify.zunit @@ -4,19 +4,19 @@ load "../auto-notify.plugin.zsh" function notify-send { - echo "Notification: $@" + echo - "Notification: $@" } function uname { - echo "Linux" + echo - "Linux" } # Mock date function to return a frozen timestamp function date { if [[ "$1" == +"%s" ]]; then - echo "11100" + echo - "11100" else - date "$@" + date - "$@" fi } } @@ -85,13 +85,33 @@ 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" + echo - "Hal9000" } run _auto_notify_send