From d19c187dccc06adf48d0b461006ca08d61fd392c Mon Sep 17 00:00:00 2001 From: Bruno Sutic Date: Sun, 2 Aug 2015 18:38:44 +0200 Subject: [PATCH] Tests non-existing plugin installation --- tests/expect_failed_plugin_download | 41 +++++++++++++++++++++++++++++ tests/helpers/tpm.sh | 2 +- tests/test_plugin_installation.sh | 25 ++++++++++++++++++ 3 files changed, 67 insertions(+), 1 deletion(-) create mode 100755 tests/expect_failed_plugin_download diff --git a/tests/expect_failed_plugin_download b/tests/expect_failed_plugin_download new file mode 100755 index 0000000..8306347 --- /dev/null +++ b/tests/expect_failed_plugin_download @@ -0,0 +1,41 @@ +#!/usr/bin/env expect + +# disables script output +log_user 0 + +spawn tmux + +# Waiting for tmux to attach. If this is not done, next command, `send` will +# not work properly. +sleep 1 + +# this is tmux prefix + I +send "I" + +# cloning might take a while +set timeout 20 + +expect_after { + timeout { + puts "Plugin installation timeout" + exit 1 + } +} + +expect { + "Installing \"non-existing-plugin\"" { + + expect { + "\"non-existing-plugin\" download fail" { + + expect { + "Done, press ENTER to continue" { + exit + } + } + + } + } + + } +} diff --git a/tests/helpers/tpm.sh b/tests/helpers/tpm.sh index 436330e..1594afb 100644 --- a/tests/helpers/tpm.sh +++ b/tests/helpers/tpm.sh @@ -7,7 +7,7 @@ script_run_helper() { local script="$1" local expected_output="$2" local expected_exit_code="${3:-0}" - $script | + $script 2>&1 | grep "$expected_output" >/dev/null 2>&1 && # grep -q flag quits the script early [ "${PIPESTATUS[0]}" -eq "$expected_exit_code" ] } diff --git a/tests/test_plugin_installation.sh b/tests/test_plugin_installation.sh index ec8cb73..c161746 100755 --- a/tests/test_plugin_installation.sh +++ b/tests/test_plugin_installation.sh @@ -44,6 +44,18 @@ test_plugin_installation_custom_dir_via_tmux_key_binding() { rm -rf "$CUSTOM_PLUGINS_DIR" } +test_non_existing_plugin_installation_via_tmux_key_binding() { + set_tmux_conf_helper <<- HERE + set -g @plugin "tmux-plugins/non-existing-plugin" + run-shell "$TPM_DIR/tpm" + HERE + + "$CURRENT_DIR/expect_failed_plugin_download" || + fail_helper "[key-binding] non existing plugin installation doesn't fail" + + teardown_helper +} + test_multiple_plugins_installation_via_tmux_key_binding() { set_tmux_conf_helper <<- HERE set -g @plugin "tmux-plugins/tmux-example-plugin" @@ -105,6 +117,19 @@ test_plugin_installation_custom_dir_via_script() { rm -rf "$CUSTOM_PLUGINS_DIR" } +test_non_existing_plugin_installation_via_script() { + set_tmux_conf_helper <<- HERE + set -g @plugin "tmux-plugins/non-existing-plugin" + run-shell "$TPM_DIR/tpm" + HERE + + local expected_exit_code=1 + script_run_helper "$TPM_DIR/bin/install_plugins" '"non-existing-plugin" download fail' "$expected_exit_code" || + fail_helper "[script] non existing plugin installation doesn't fail" + + teardown_helper +} + test_multiple_plugins_installation_via_script() { set_tmux_conf_helper <<- HERE set -g @plugin "tmux-plugins/tmux-example-plugin"