From f444e320a549f4ab0d8170a1d328cbd7043f3d41 Mon Sep 17 00:00:00 2001 From: Jorge Morante Date: Wed, 27 Nov 2019 13:47:27 +0100 Subject: [PATCH] adapt test suit to travies * run tests in different tmux versions to benefit from travis matrix feature * tmuxomatic version dependant fixes * add retries --- .travis.yml | 14 +++++++-- README.md | 2 +- scripts/health-check.sh | 11 +------ scripts/utils.sh | 13 ++++++++ test/conf/fish.conf | 3 -- test/conf/tmuxomatic.conf | 4 --- test/helpers.sh | 2 -- test/install-tmux-versions.sh | 27 +++++++++++++++++ test/provisioning/ci.sh | 10 +++++++ test/provisioning/ubuntu.sh | 19 +++++------- test/run.sh | 53 ++++++++++++++++++++++++--------- test/specs/basic-yank_spec.sh | 2 -- test/specs/fish-support_spec.sh | 3 +- test/tmuxomatic.sh | 20 +++++++++++-- test/use-tmux.sh | 5 ++++ 15 files changed, 134 insertions(+), 54 deletions(-) delete mode 100644 test/conf/fish.conf delete mode 100644 test/conf/tmuxomatic.conf create mode 100755 test/install-tmux-versions.sh create mode 100755 test/provisioning/ci.sh mode change 100644 => 100755 test/provisioning/ubuntu.sh create mode 100755 test/use-tmux.sh diff --git a/.travis.yml b/.travis.yml index b8539ea..1f81691 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,15 @@ language: generic -install: - - ./test/provisioning/ubuntu.sh +install: ./test/provisioning/ci.sh script: ./test/run.sh within-vm os: linux +cache: /opt +env: + - CI_TMUX_VERSION=2.3 + - CI_TMUX_VERSION=2.4 + - CI_TMUX_VERSION=2.5 + - CI_TMUX_VERSION=2.6 + - CI_TMUX_VERSION=2.7 + - CI_TMUX_VERSION=2.8 + - CI_TMUX_VERSION=2.9 + - CI_TMUX_VERSION=2.9a + - CI_TMUX_VERSION=3.0 diff --git a/README.md b/README.md index 630012d..1b3e31a 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # tmux-fingers -[![CircleCI](https://circleci.com/gh/Morantron/tmux-fingers.svg?style=svg)](https://circleci.com/gh/Morantron/tmux-fingers) +[![Build Status](https://travis-ci.com/Morantron/tmux-fingers.svg?branch=develop)](https://travis-ci.com/Morantron/tmux-fingers) **tmux-fingers**: copy pasting with vimium/vimperator like hints. diff --git a/scripts/health-check.sh b/scripts/health-check.sh index 9b15e20..fd2000e 100755 --- a/scripts/health-check.sh +++ b/scripts/health-check.sh @@ -23,15 +23,6 @@ function is_tmux_ready() { fi } -function version_major() { - echo "$1" | cut -f1 -d. | grep -Eo "[0-9]" -} - -function version_minor() { - echo "$1" | cut -f2 -d. | grep -Eo "[0-9]" -} - - function log_message() { log_messages+=("$1") } @@ -100,7 +91,7 @@ function perform_health_check() { local healthy=1 # BASH_VERSION is a global - local TMUX_VERSION=$(tmux -V | grep -Eio "([0-9]+(\.[0-9]))(?:-rc)?") + local TMUX_VERSION=$(get_tmux_version) local GAWK_VERSION="" if [[ $(program_exists "gawk") = "1" ]]; then diff --git a/scripts/utils.sh b/scripts/utils.sh index e8dec22..2ed36bb 100755 --- a/scripts/utils.sh +++ b/scripts/utils.sh @@ -158,3 +158,16 @@ function program_exists() { echo "0" fi } + +function version_major() { + echo "$1" | cut -f1 -d. | grep -Eo "[0-9]" +} + +function version_minor() { + echo "$1" | cut -f2 -d. | grep -Eo "[0-9]" +} + + +function get_tmux_version() { + echo "$(tmux -V | grep -Eio "([0-9]+(\.[0-9]))(?:-rc)?")" +} diff --git a/test/conf/fish.conf b/test/conf/fish.conf deleted file mode 100644 index 5a92f92..0000000 --- a/test/conf/fish.conf +++ /dev/null @@ -1,3 +0,0 @@ -set -g prefix C-a -set -g @fingers-compact-hints '0' -run /home/vagrant/shared/tmux-fingers.tmux diff --git a/test/conf/tmuxomatic.conf b/test/conf/tmuxomatic.conf deleted file mode 100644 index ea26666..0000000 --- a/test/conf/tmuxomatic.conf +++ /dev/null @@ -1,4 +0,0 @@ -set -g prefix F12 -set -g status off -set-window-option -g force-width 80 -set-window-option -g force-height 24 diff --git a/test/helpers.sh b/test/helpers.sh index 1303a20..4825ca0 100644 --- a/test/helpers.sh +++ b/test/helpers.sh @@ -49,8 +49,6 @@ function begin_with_conf() { } function begin_hook() { - tmuxomatic set-window-option force-width 80 - tmuxomatic set-window-option force-height 24 tmuxomatic__exec "tmux kill-session -t test" } diff --git a/test/install-tmux-versions.sh b/test/install-tmux-versions.sh new file mode 100755 index 0000000..a0d9150 --- /dev/null +++ b/test/install-tmux-versions.sh @@ -0,0 +1,27 @@ +#!/usr/bin/env bash + +if [[ -n "$CI_TMUX_VERSION" ]]; then + VERSIONS=("$CI_TMUX_VERSION") +else + VERSIONS=("2.3" "2.4" "2.5" "2.6" "2.7" "2.8" "2.9" "2.9a" "3.0") +fi + +sudo mkdir -p /opt +sudo chmod a+w /opt + +pushd /tmp + for version in "${VERSIONS[@]}"; + do + if [[ -f "/opt/tmux-${version}" ]]; then + continue + fi + + wget "https://github.com/tmux/tmux/releases/download/${version}/tmux-${version}.tar.gz" + tar pfx "tmux-${version}.tar.gz" -C "/opt/" + + pushd "/opt/tmux-${version}" + ./configure + make + popd + done +popd diff --git a/test/provisioning/ci.sh b/test/provisioning/ci.sh new file mode 100755 index 0000000..dd9f166 --- /dev/null +++ b/test/provisioning/ci.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env bash + +CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +source $CURRENT_DIR/ubuntu.sh + +sudo mkdir -p /home/vagrant +sudo ln -s "$PWD" /home/vagrant/shared + +sudo usermod -a -G travis fishman diff --git a/test/provisioning/ubuntu.sh b/test/provisioning/ubuntu.sh old mode 100644 new mode 100755 index db2c3d7..874dc93 --- a/test/provisioning/ubuntu.sh +++ b/test/provisioning/ubuntu.sh @@ -1,19 +1,14 @@ -#!/bin/sh +#!/usr/bin/env bash + +CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" sudo aptitude update -sudo aptitude install -y fish gawk +sudo aptitude install -y fish gawk xvfb perl -useradd -m -p "$(perl -e "print crypt('fishman','sa');")" -s "/usr/bin/fish" fishman +sudo useradd -m -p "$(perl -e "print crypt('fishman','sa');")" -s "/usr/bin/fish" fishman -wget https://github.com/tmux/tmux/releases/download/2.6/tmux-2.6.tar.gz - -# install tmux from source +# remove system tmux and install tmux dependencies sudo aptitude remove -y tmux sudo aptitude install -y libevent-dev libncurses5-dev -tar xvzf tmux-2.6.tar.gz -cd tmux-2.6/ || echo "Could not find tmux-2.6/ folder" || exit 1 -./configure -make -make install -cd - || exit 1 +$CURRENT_DIR/../install-tmux-versions.sh diff --git a/test/run.sh b/test/run.sh index 908623f..1b57789 100755 --- a/test/run.sh +++ b/test/run.sh @@ -3,32 +3,57 @@ CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" SPEC_OUTPUT_LOG=$CURRENT_DIR/../spec-output.log TEST_LOG=$CURRENT_DIR/../test.log +MAX_RETRIES=5 target=$1 cat /dev/null > $SPEC_OUTPUT_LOG cat /dev/null > $TEST_LOG +if [[ -n "$CI_TMUX_VERSION" ]]; then + VERSIONS=("$CI_TMUX_VERSION") +else + VERSIONS=("2.3" "2.4" "2.5" "2.6" "2.7" "2.8" "2.9" "2.9a" "3.0") +fi + if [[ "$target" == "within-vm" ]]; then stty cols 80 stty rows 24 fail_count=0 - for test_file in $(ls $CURRENT_DIR/specs/*_spec.sh); do - result="* $test_file ..." - sleep 1 - echo "Running $test_file" >> $SPEC_OUTPUT_LOG - $test_file &>> $TEST_LOG + for version in "${VERSIONS[@]}"; do + $CURRENT_DIR/use-tmux.sh "$version" + echo "Running tests in tmux $version" + for test_file in $(ls $CURRENT_DIR/specs/*_spec.sh); do + result="* $test_file ..." + sleep 1 - if [[ $? == 0 ]]; then - result="$result OK" - else - fail_count=$((fail_count + 1)) - result="$result FAIL" - fi + tries=0 + while [[ $tries -lt $MAX_RETRIES ]]; do + echo "Running $test_file" >> $SPEC_OUTPUT_LOG + $test_file &>> $TEST_LOG + success=$? - echo "$result" >> $SPEC_OUTPUT_LOG - echo "$result" + if [[ $success ]]; then + break + fi + done + + if [[ $success ]]; then + result="$result OK" + else + fail_count=$((fail_count + 1)) + result="$result FAIL" + fi + + echo "$result" >> $SPEC_OUTPUT_LOG + echo "$result" + done done + if [[ $fail_count -gt 0 ]]; then + echo "Displaying tmuxomatic logs" + cat $CURRENT_DIR/../tmuxomatic* + fi + exit $fail_count elif [[ -z "$target" ]]; then $CURRENT_DIR/run.sh ubuntu @@ -50,5 +75,5 @@ elif [[ -z "$target" ]]; then else echo "Running tests on $target" vagrant up "$target" &>> /dev/null - vagrant ssh "$target" -c "cd shared && ./test/run.sh within-vm" 2> /dev/null + vagrant ssh "$target" -c "cd shared && xvfb-run ./test/run.sh within-vm" 2> /dev/null fi diff --git a/test/specs/basic-yank_spec.sh b/test/specs/basic-yank_spec.sh index fb5886c..675c05f 100755 --- a/test/specs/basic-yank_spec.sh +++ b/test/specs/basic-yank_spec.sh @@ -1,7 +1,5 @@ #!/usr/bin/env bash -#set -x - CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" source $CURRENT_DIR/../tmuxomatic.sh source $CURRENT_DIR/../helpers.sh diff --git a/test/specs/fish-support_spec.sh b/test/specs/fish-support_spec.sh index bd4a2a3..ebb80cd 100755 --- a/test/specs/fish-support_spec.sh +++ b/test/specs/fish-support_spec.sh @@ -6,7 +6,8 @@ source $CURRENT_DIR/../helpers.sh tmuxomatic__begin begin_hook -tmuxomatic__exec "sudo su fishman" +tmuxomatic__exec "sudo su - fishman" +tmuxomatic__exec "cd /home/vagrant/shared" tmuxomatic__exec "tmux -f /home/vagrant/shared/test/conf/basic.conf new -s test" init_pane_fish tmuxomatic__exec "cat ./test/fixtures/grep-output" diff --git a/test/tmuxomatic.sh b/test/tmuxomatic.sh index 3bcc910..0ea2ca9 100644 --- a/test/tmuxomatic.sh +++ b/test/tmuxomatic.sh @@ -5,6 +5,8 @@ TMUXOMATIC_SOCKET=tmuxomatic TMUXOMATIC_TIMEOUT="10" TMUXOMATIC_EXIT_CODE='' +source $TMUXOMATIC_CURRENT_DIR/../scripts/utils.sh + function tmuxomatic() { TMUX='' tmux -L "$TMUXOMATIC_SOCKET" "$@" } @@ -18,8 +20,20 @@ function tmuxomatic__begin() { tmuxomatic list-sessions &> /dev/null if [[ $? -eq 1 ]]; then - tmuxomatic -f "$TMUXOMATIC_CURRENT_DIR/conf/tmuxomatic.conf" new-session -d -s tmuxomatic - wait + tmuxomatic -f /dev/null new-session -d -s tmuxomatic + + tmuxomatic set -g prefix F12 + tmuxomatic set -g status off + + tmux_version=$(get_tmux_version) + + if [[ $(version_major "$tmux_version") -ge "2" ]] && [[ $(version_minor "$tmux_version") -lt "9" ]]; then + tmuxomatic set-window-option force-width 80 + tmuxomatic set-window-option force-height 24 + else + tmuxomatic resize-window -x 80 -y 24 + fi + tmuxomatic__exec "export TMUX=''" tmuxomatic__exec "clear" fi @@ -76,7 +90,7 @@ function tmuxomatic__expect() { } # TODO ideally specs shouldn't have any sleeps, but life is hard! Since -# circle-ci machine is kind of slow, sleeps need to be longer there. +# ci machines are usually kind of slow, sleeps need to be longer there. # # Ideally tmuxomatic__exec should now when a command has finished by using # "tmux wait", or alert-silence hook, or some tmux sorcery like that. diff --git a/test/use-tmux.sh b/test/use-tmux.sh new file mode 100755 index 0000000..881b2a2 --- /dev/null +++ b/test/use-tmux.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env bash + +version="$1" +sudo rm -rf /usr/local/bin/tmux +sudo ln -s /opt/tmux-${version}/tmux /usr/local/bin/tmux