From 707aa1111b80104a90840a6963a4af8cde16de97 Mon Sep 17 00:00:00 2001 From: Javier Lopez Date: Wed, 27 May 2015 15:17:13 -0500 Subject: [PATCH] new handlers on update phase --- scripts/update_plugin.sh | 74 +++++++++++---- scripts/update_plugin_prompt.sh | 4 +- ..._successful_update_of_all_plugins_extended | 91 +++++++++++++++++++ tests/test_plugin_update_extended.sh | 37 ++++++++ 4 files changed, 188 insertions(+), 18 deletions(-) create mode 100755 tests/expect_successful_update_of_all_plugins_extended create mode 100755 tests/test_plugin_update_extended.sh diff --git a/scripts/update_plugin.sh b/scripts/update_plugin.sh index 8504606..3369f75 100755 --- a/scripts/update_plugin.sh +++ b/scripts/update_plugin.sh @@ -16,36 +16,78 @@ cancel() { exit 0 } -pull_changes() { - local plugin="$1" - local plugin_path=$(shared_plugin_path "$plugin") - cd $plugin_path && - GIT_TERMINAL_PROMPT=0 git pull && - GIT_TERMINAL_PROMPT=0 git submodule update --init --recursive +update_plugin_git() { + local plugin; plugin="$1" + local branch; branch=":${1##*:}" + local plugin_path; plugin_path=$(shared_plugin_path "$plugin") + plugin="${1%$branch}" + #update only makes sense when no specific branch/revision is set + if [ "${branch}" = ":${1}" ]; then + cd "$plugin_path" && + GIT_TERMINAL_PROMPT="0" git pull && + GIT_TERMINAL_PROMPT="0" git submodule update --init --recursive + fi +} + +update_plugin_web() { + local plugin; plugin="$1" + local plugin_name; plugin_name="$(shared_plugin_name "$plugin")" + local plugin_path; plugin_path=$(shared_plugin_path "$plugin") + (cd "$plugin_path" && rm -rf "${plugin_name}" && + (wget --no-check-certificate "${plugin}" || curl -k -s -O "${plugin}")) +} + +update_plugin_local() { + local plugin; plugin="$1" + local plugin_name; plugin_name="$(shared_plugin_name "$plugin")" + local plugin_path; plugin_path=$(shared_plugin_path "$plugin") + cd "$plugin_path" && rm -rf "${plugin_name}" && cp -r "${plugin}" . } update() { - local plugin="$1" - echo_message "Updating \"$plugin\"" - $(pull_changes "$plugin" > /dev/null 2>&1) && - echo_message " \"$plugin\" update success" || - echo_message " \"$plugin\" update fail" + local plugin; plugin="$1" + local plugin_name; plugin_name="$(shared_plugin_name "$plugin")" + echo_message "Updating \"$plugin_name\"" + + local handler; handler="${1%%:*}:" + plugin="${1#$handler}" + + case "${handler}" in + ''|*/*) case "${1}" in + /*|~*|\$*) update_plugin_local "${1}" ;; + *) update_plugin_git "${1}" ;; + esac ;; + gh*|github*|git@github.com*) update_plugin_git "${plugin}" ;; + git:) update_plugin_git "${plugin}" ;; + file:) update_plugin_local "${plugin#//}" ;; + http:|ftp:) update_plugin_web "${1}" ;; + https:) + case "${1}" in + *github.com/*) update_plugin_git "${plugin#//github.com/}";; + *) update_plugin_web "${1}";; + esac ;; + *) set_false ;; + esac + + [ "${?}" = "0" ] && + echo_message " \"$plugin_name\" update success" || + echo_message " \"$plugin_name\" update fail" } update_all() { - local plugins="$(shared_get_tpm_plugins_list)" + local plugins plugin; plugins="$(shared_get_tpm_plugins_list)" for plugin in $plugins; do - local plugin_name="$(shared_plugin_name "$plugin")" + local plugin_name; plugin_name="$(shared_plugin_name "$plugin")" # updating only installed plugins if plugin_already_installed "$plugin_name"; then - update "$plugin_name" + update "$plugin" fi done } handle_plugin_update() { - local arg="$1" + local arg; arg="$1" if empty "$arg"; then cancel @@ -65,7 +107,7 @@ handle_plugin_update() { } main() { - local arg="$1" + local arg; arg="$1" shared_set_tpm_path_constant handle_plugin_update "$arg" reload_tmux_environment diff --git a/scripts/update_plugin_prompt.sh b/scripts/update_plugin_prompt.sh index 4f26951..d0a3e92 100755 --- a/scripts/update_plugin_prompt.sh +++ b/scripts/update_plugin_prompt.sh @@ -9,14 +9,14 @@ CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" source "$CURRENT_DIR/shared_functions.sh" display_plugin_update_list() { - local plugins="$(shared_get_tpm_plugins_list)" + local plugins plugin; plugins="$(shared_get_tpm_plugins_list)" echo_message "Installed plugins:" echo_message "" for plugin in $plugins; do # displaying only installed plugins if plugin_already_installed "$plugin"; then - local plugin_name="$(shared_plugin_name "$plugin")" + local plugin_name; plugin_name="$(shared_plugin_name "$plugin")" echo_message " $plugin_name" fi done diff --git a/tests/expect_successful_update_of_all_plugins_extended b/tests/expect_successful_update_of_all_plugins_extended new file mode 100755 index 0000000..f354da8 --- /dev/null +++ b/tests/expect_successful_update_of_all_plugins_extended @@ -0,0 +1,91 @@ +#!/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 + U +send "U" + +set timeout 15 + +expect { + "Installed plugins" { +expect { + "\"tmux-example-plugin\"" { +expect { + "\"tmux-online-status\"" { +expect { + "\"tmux-battery\"" { +expect { + "\"tmux-sidebar\"" { +expect { + "\"tmux-sensible\"" { +expect { + "\"sha1sum.txt\"" { +expect { + "\"meta-micro\"" { +expect { + "\"readme.txt\"" { +expect { + "\"run-tests-within-vm\"" { +expect { + "\"all\" - updates all plugins" { + expect { "ENTER - cancels" } + }}}}}}}}}}}}}}}}}}}}} + + timeout { + puts "Plugin update prompt timeout"; + exit 1 + } +} + +send "all\r" + +expect { + "Updating all plugins!" { +expect { + "Updating \"tmux-example-plugin\"" { +expect { + "\"tmux-example-plugin\" update success" { +expect { + "Updating \"tmux-online-status\"" { +expect { + "\"tmux-online-status\" update success" { +expect { + "Updating \"tmux-battery\"" { +expect { + "\"tmux-battery\" update success" { +expect { + "Updating \"tmux-sidebar\"" { +expect { + "\"tmux-sidebar\" update success" { +expect { + "Updating \"sha1sum.txt\"" { +expect { + "\"sha1sum.txt\" update success" { +expect { + "Updating \"meta-micro\"" { +expect { + "\"meta-micro\" update success" { +expect { + "Updating \"readme.txt\"" { +expect { + "\"readme.txt\" update success" { +expect { + "Updating \"run-tests-within-vm\"" { +expect { + "\"run-tests-within-vm\" update success" { + expect { "Done, press ENTER to continue." { exit 0 } } + }}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}} + + timeout { + puts "Update all plugins timeout"; + exit 1 + } +} diff --git a/tests/test_plugin_update_extended.sh b/tests/test_plugin_update_extended.sh new file mode 100755 index 0000000..bfbc3aa --- /dev/null +++ b/tests/test_plugin_update_extended.sh @@ -0,0 +1,37 @@ +#!/usr/bin/env bash + +CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +source "$CURRENT_DIR"/helpers.sh + +test_plugin_installation() { + set_tmux_conf_helper <<- HERE + set -g @tpm_plugins " \ + tmux-plugins/tmux-example-plugin \ + gh:tmux-plugins/tmux-online-status \ + github:tmux-plugins/tmux-battery \ + github:tmux-plugins/tmux-sidebar:master \ + https://github.com/tmux-plugins/tmux-sensible:3ea5b \ + http://ovh.net/files/sha1sum.txt \ + git://git.openembedded.org/meta-micro \ + ftp://ftp.microsoft.com/developr/readme.txt \ + file://$PWD/tests/run-tests-within-vm" + run-shell "$PWD/tpm" + HERE + + # opens tmux and install plugins, test results with `expect` + "$CURRENT_DIR"/expect_successful_plugin_download_extended || + fail_helper "Tmux plugin installation phase in update fails" + + # opens tmux and update plugins, test results with `expect` + "$CURRENT_DIR"/expect_successful_update_of_all_plugins || + fail_helper "Tmux 'update all plugins' fails" + + teardown_helper +} + +main() { + test_plugin_installation + exit_value_helper +} +main