From 1bf087faa37ffcf458da9a3f29d4ea7e9eff5820 Mon Sep 17 00:00:00 2001 From: Jim Myhrberg Date: Sat, 24 May 2014 11:01:23 +0100 Subject: [PATCH 01/30] Basic setup for tests Based on the test setup of stub.sh: https://github.com/jimeh/stub.sh --- .gitignore | 2 ++ .travis.yml | 4 ++++ Makefile | 37 +++++++++++++++++++++++++++++++++++++ test.sh | 34 ++++++++++++++++++++++++++++++++++ test/test-helper.sh | 8 ++++++++ 5 files changed, 85 insertions(+) create mode 100644 .gitignore create mode 100644 .travis.yml create mode 100644 Makefile create mode 100755 test.sh create mode 100644 test/test-helper.sh diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..71ab7b8 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +test/assert.sh +test/stub.sh \ No newline at end of file diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..5b02332 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,4 @@ +language: bash +script: make test +before_install: + - sudo apt-get install bc \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..90104af --- /dev/null +++ b/Makefile @@ -0,0 +1,37 @@ +test: prepare + ./test.sh + +prepare: test/assert.sh test/stub.sh + +test/assert.sh: + test -f "test/assert.sh" || ( \ + echo "fetching test/assert.sh..." && \ + curl -s -L -o test/assert.sh \ + https://raw.github.com/lehmannro/assert.sh/v1.0.2/assert.sh \ + ) + +update-assert.sh: remove-assert.sh test/assert.sh + +remove-assert.sh: + test -f "test/assert.sh" && \ + rm "test/assert.sh" && \ + echo "removed test/assert.sh" + +test/stub.sh: + test -f "test/stub.sh" || ( \ + echo "fetching test/stub.sh..." && \ + curl -s -L -o test/stub.sh \ + https://raw.github.com/jimeh/stub.sh/v0.3.0/stub.sh \ + ) + +update-stub.sh: remove-stub.sh test/stub.sh + +remove-stub.sh: + test -f "test/stub.sh" && \ + rm "test/stub.sh" && \ + echo "removed test/stub.sh" + +.SILENT: +.PHONY: test prepare \ + test/assert.sh update-assert.sh remove-assert.sh \ + test/stub.sh update-stub.sh remove-stub.sh diff --git a/test.sh b/test.sh new file mode 100755 index 0000000..656e3ac --- /dev/null +++ b/test.sh @@ -0,0 +1,34 @@ +#! /usr/bin/env bash + +resolve_link() { + $(type -p greadlink readlink | head -1) $1 +} + +abs_dirname() { + local cwd="$(pwd)" + local path="$1" + + while [ -n "$path" ]; do + cd "${path%/*}" + local name="${path##*/}" + path="$(resolve_link "$name" || true)" + done + + pwd + cd "$cwd" +} + + +testdir="$(abs_dirname "$0")/test" +testfiles="$(find "$testdir" -name "*-test.sh")" + +RET=0 +for testfile in $testfiles; do + echo "" + echo "running: ${testfile/#$(dirname "$testdir")\//}" + cd "$(dirname "$testfile")" + "$testfile" + if [ "$?" != "0" ]; then RET=1; fi +done +echo "" +exit $RET diff --git a/test/test-helper.sh b/test/test-helper.sh new file mode 100644 index 0000000..30fbcd9 --- /dev/null +++ b/test/test-helper.sh @@ -0,0 +1,8 @@ +[ -n "$TEST_DEBUG" ] && set -x + +# Set testroot variable. +testroot="$(dirname "$BASH_SOURCE")" + +# Include assert.sh and stub.sh libraries. +source "${testroot}/assert.sh" +source "${testroot}/stub.sh" From 279e68f7c5943ec9d1557c06fbe83fd23112cec4 Mon Sep 17 00:00:00 2001 From: Jim Myhrberg Date: Sat, 24 May 2014 11:13:45 +0100 Subject: [PATCH 02/30] Add tests for lib/env.sh --- test/lib/env-test.sh | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100755 test/lib/env-test.sh diff --git a/test/lib/env-test.sh b/test/lib/env-test.sh new file mode 100755 index 0000000..a445044 --- /dev/null +++ b/test/lib/env-test.sh @@ -0,0 +1,33 @@ +#! /usr/bin/env bash +source "../test-helper.sh" + +# +# env.sh tests. +# + +# Setup +TMUXIFIER="/path/to/tmuxifier" +unset TMUXIFIER_LAYOUT_PATH + +# When TMUXIFIER_LAYOUT_PATH is not set. +source "../../lib/env.sh" +assert 'echo $TMUXIFIER_LAYOUT_PATH' "${TMUXIFIER}/layouts" + +# When TMUXIFIER_LAYOUT_PATH is set and has a trailing slash. +TMUXIFIER_LAYOUT_PATH="/path/to/layouts/" +source "../../lib/env.sh" +assert 'echo $TMUXIFIER_LAYOUT_PATH' "/path/to/layouts" +unset TMUXIFIER_LAYOUT_PATH + +# When TMUXIFIER_LAYOUT_PATH is set and does not have a trailing slash. +TMUXIFIER_LAYOUT_PATH="/path/to/layouts" +source "../../lib/env.sh" +assert 'echo $TMUXIFIER_LAYOUT_PATH' "/path/to/layouts" +unset TMUXIFIER_LAYOUT_PATH + + +# Teardown +unset TMUXIFIER + +# End of tests. +assert_end "env.sh" From c927126cb382c282e1b305205ad68037e1f8920a Mon Sep 17 00:00:00 2001 From: Jim Myhrberg Date: Sat, 24 May 2014 11:22:45 +0100 Subject: [PATCH 03/30] Improve global test setup in test-helper.sh --- test/lib/env-test.sh | 7 ------- test/test-helper.sh | 9 +++++++++ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/test/lib/env-test.sh b/test/lib/env-test.sh index a445044..a1766ad 100755 --- a/test/lib/env-test.sh +++ b/test/lib/env-test.sh @@ -5,10 +5,6 @@ source "../test-helper.sh" # env.sh tests. # -# Setup -TMUXIFIER="/path/to/tmuxifier" -unset TMUXIFIER_LAYOUT_PATH - # When TMUXIFIER_LAYOUT_PATH is not set. source "../../lib/env.sh" assert 'echo $TMUXIFIER_LAYOUT_PATH' "${TMUXIFIER}/layouts" @@ -26,8 +22,5 @@ assert 'echo $TMUXIFIER_LAYOUT_PATH' "/path/to/layouts" unset TMUXIFIER_LAYOUT_PATH -# Teardown -unset TMUXIFIER - # End of tests. assert_end "env.sh" diff --git a/test/test-helper.sh b/test/test-helper.sh index 30fbcd9..0b37170 100644 --- a/test/test-helper.sh +++ b/test/test-helper.sh @@ -3,6 +3,15 @@ # Set testroot variable. testroot="$(dirname "$BASH_SOURCE")" +# Set TMUXIFIER environment variable +TMUXIFIER="$(dirname "$testroot")" + +# Unset various Tmuxifier environment variables to prevent a local install of +# Tmuxifier interfering with tests. +unset TMUXIFIER_LAYOUT_PATH +unset TMUXIFIER_TMUX_OPTS +unset TMUXIFIER_NO_COMPLETE + # Include assert.sh and stub.sh libraries. source "${testroot}/assert.sh" source "${testroot}/stub.sh" From a700770757999f7e5c8efdea82d8dd1c179090f3 Mon Sep 17 00:00:00 2001 From: Jim Myhrberg Date: Sat, 24 May 2014 11:38:04 +0100 Subject: [PATCH 04/30] Fix path related test setup issue --- test/test-helper.sh | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/test/test-helper.sh b/test/test-helper.sh index 0b37170..4f12dfd 100644 --- a/test/test-helper.sh +++ b/test/test-helper.sh @@ -1,10 +1,28 @@ [ -n "$TEST_DEBUG" ] && set -x +resolve_link() { + $(type -p greadlink readlink | head -1) $1 +} + +abs_dirname() { + local cwd="$(pwd)" + local path="$1" + + while [ -n "$path" ]; do + cd "${path%/*}" + local name="${path##*/}" + path="$(resolve_link "$name" || true)" + done + + pwd + cd "$cwd" +} + # Set testroot variable. -testroot="$(dirname "$BASH_SOURCE")" +testroot="$(abs_dirname "$BASH_SOURCE")" # Set TMUXIFIER environment variable -TMUXIFIER="$(dirname "$testroot")" +TMUXIFIER="$(abs_dirname "$testroot/../..")" # Unset various Tmuxifier environment variables to prevent a local install of # Tmuxifier interfering with tests. From 1fb80660b8381439bc14793d92981f6e6a7c2220 Mon Sep 17 00:00:00 2001 From: Jim Myhrberg Date: Sat, 24 May 2014 11:38:48 +0100 Subject: [PATCH 05/30] Add tests for lib/runtime.sh --- test/lib/runtime-test.sh | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100755 test/lib/runtime-test.sh diff --git a/test/lib/runtime-test.sh b/test/lib/runtime-test.sh new file mode 100755 index 0000000..a32ac7b --- /dev/null +++ b/test/lib/runtime-test.sh @@ -0,0 +1,23 @@ +#! /usr/bin/env bash +source "../test-helper.sh" + +# +# runtime.sh tests. +# + +source "../../lib/runtime.sh" + +# We assume env.sh has been sourced if $TMUXIFIER_LAYOUT_PATH has been set. +assert 'echo $TMUXIFIER_LAYOUT_PATH' "${TMUXIFIER}/layouts" + +# We ensure $session_root is set to $HOME by default. +assert 'echo $session_root' "$HOME" + +# We assume layout-helpers.sh has been sourced if a few of them are available. +for helper in new_window split_v split_h select_window select_pane; do + assert "type $helper | head -1" "$helper is a function" +done + + +# End of tests. +assert_end "runtime.sh" From e5ffdc6f161fc9616efc760a144c017bfc4bdc78 Mon Sep 17 00:00:00 2001 From: Jim Myhrberg Date: Sat, 24 May 2014 11:46:48 +0100 Subject: [PATCH 06/30] A few further tweaks to how path handling in tests --- test/lib/env-test.sh | 13 ++++++++++--- test/lib/runtime-test.sh | 2 +- test/test-helper.sh | 5 ++++- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/test/lib/env-test.sh b/test/lib/env-test.sh index a1766ad..0caf1c0 100755 --- a/test/lib/env-test.sh +++ b/test/lib/env-test.sh @@ -5,22 +5,29 @@ source "../test-helper.sh" # env.sh tests. # +# Setup. +realTMUXIFIER="$TMUXIFIER" +TMUXIFER="/path/to/tmuxifier" + # When TMUXIFIER_LAYOUT_PATH is not set. -source "../../lib/env.sh" +source "${root}/lib/env.sh" assert 'echo $TMUXIFIER_LAYOUT_PATH' "${TMUXIFIER}/layouts" # When TMUXIFIER_LAYOUT_PATH is set and has a trailing slash. TMUXIFIER_LAYOUT_PATH="/path/to/layouts/" -source "../../lib/env.sh" +source "${root}/lib/env.sh" assert 'echo $TMUXIFIER_LAYOUT_PATH' "/path/to/layouts" unset TMUXIFIER_LAYOUT_PATH # When TMUXIFIER_LAYOUT_PATH is set and does not have a trailing slash. TMUXIFIER_LAYOUT_PATH="/path/to/layouts" -source "../../lib/env.sh" +source "${root}/lib/env.sh" assert 'echo $TMUXIFIER_LAYOUT_PATH' "/path/to/layouts" unset TMUXIFIER_LAYOUT_PATH +# Tear down. +TMUXIFER="$realTMUXIFIER" +unset realTMUXIFIER # End of tests. assert_end "env.sh" diff --git a/test/lib/runtime-test.sh b/test/lib/runtime-test.sh index a32ac7b..06d5a68 100755 --- a/test/lib/runtime-test.sh +++ b/test/lib/runtime-test.sh @@ -5,7 +5,7 @@ source "../test-helper.sh" # runtime.sh tests. # -source "../../lib/runtime.sh" +source "${root}/lib/runtime.sh" # We assume env.sh has been sourced if $TMUXIFIER_LAYOUT_PATH has been set. assert 'echo $TMUXIFIER_LAYOUT_PATH' "${TMUXIFIER}/layouts" diff --git a/test/test-helper.sh b/test/test-helper.sh index 4f12dfd..39d09e6 100644 --- a/test/test-helper.sh +++ b/test/test-helper.sh @@ -21,8 +21,11 @@ abs_dirname() { # Set testroot variable. testroot="$(abs_dirname "$BASH_SOURCE")" +# Set root variable. +root="$(abs_dirname "$testroot/../..")" + # Set TMUXIFIER environment variable -TMUXIFIER="$(abs_dirname "$testroot/../..")" +TMUXIFIER="$root" # Unset various Tmuxifier environment variables to prevent a local install of # Tmuxifier interfering with tests. From 54f6f890bb74929f918f19c44d636311e9456eb9 Mon Sep 17 00:00:00 2001 From: Jim Myhrberg Date: Sat, 24 May 2014 14:56:10 +0100 Subject: [PATCH 07/30] Add tests for lib/util.sh --- test/lib/util-test.sh | 58 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100755 test/lib/util-test.sh diff --git a/test/lib/util-test.sh b/test/lib/util-test.sh new file mode 100755 index 0000000..df6cc08 --- /dev/null +++ b/test/lib/util-test.sh @@ -0,0 +1,58 @@ +#! /usr/bin/env bash +source "../test-helper.sh" +source "${root}/lib/util.sh" + +# +# calling-help() tests. +# + +# Returns 0 when "--help" is part of passed arguments. +assert_raises 'calling-help --help' 0 +assert_raises 'calling-help foo --help' 0 +assert_raises 'calling-help --help bar' 0 +assert_raises 'calling-help foo --help bar' 0 + +# Returns 0 when "-h" is part of passed arguments. +assert_raises 'calling-help -h' 0 +assert_raises 'calling-help foo -h' 0 +assert_raises 'calling-help -h bar' 0 +assert_raises 'calling-help foo -h bar' 0 + +# Returns 1 when neither "--help" or "-h" is not part of passed arguments. +assert_raises 'calling-help' 1 +assert_raises 'calling-help foo' 1 +assert_raises 'calling-help foo bar' 1 + +# Returns 1 when "--help" is part of passed arguments, but not free-standing. +assert_raises 'calling-help --help-me' 1 +assert_raises 'calling-help foo--help' 1 + +# Returns 1 when "-h" is part of passed arguments, but not free-standing. +assert_raises 'calling-help -hj' 1 +assert_raises 'calling-help welcome-home' 1 + +# End of tests. +assert_end "calling-help()" + + +# +# calling-complete() tests. +# + +# Returns 0 when "--complete" is part of passed arguments. +assert_raises 'calling-complete --complete' 0 +assert_raises 'calling-complete foo --complete' 0 +assert_raises 'calling-complete --complete bar' 0 +assert_raises 'calling-complete foo --complete bar' 0 + +# Returns 1 when "--complete" is not part of passed arguments. +assert_raises 'calling-complete' 1 +assert_raises 'calling-complete foo' 1 +assert_raises 'calling-complete foo bar' 1 + +# Returns 1 when "--complete" is part of passed arguments, but not free-standing. +assert_raises 'calling-complete --complete-me' 1 +assert_raises 'calling-complete foo--complete' 1 + +# End of tests. +assert_end "calling-complete()" From 5602bf650ecd0ee87333264764af4fcf4c46e3ef Mon Sep 17 00:00:00 2001 From: Jim Myhrberg Date: Sun, 25 May 2014 01:24:30 +0100 Subject: [PATCH 08/30] Add basic tests for tmuxifier-tmux --- test/libexec/tmuxifier-tmux-test.sh | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100755 test/libexec/tmuxifier-tmux-test.sh diff --git a/test/libexec/tmuxifier-tmux-test.sh b/test/libexec/tmuxifier-tmux-test.sh new file mode 100755 index 0000000..0ac6f79 --- /dev/null +++ b/test/libexec/tmuxifier-tmux-test.sh @@ -0,0 +1,28 @@ +#! /usr/bin/env bash +source "../test-helper.sh" +source "${root}/lib/util.sh" + +# +# tmuxifier-tmux tests. +# + +# Setup. +libexec="${root}/libexec" +realTMUX="$TMUX" +unset TMUX +export TMUXIFIER_TMUX_OPTS="-L tmuxifier-tests" +tmux $TMUXIFIER_TMUX_OPTS new -d -s foobar +tmux $TMUXIFIER_TMUX_OPTS new -d -s dude + +# Passes all arguments to Tmux. +assert "${libexec}/tmuxifier-tmux list-sessions -F \"#{session_id}: #S\"" \ + "\$1: dude\n\$0: foobar" + +# Tear down. +tmux $TMUXIFIER_TMUX_OPTS kill-server +unset TMUXIFIER_TMUX_OPTS +TMUX="$realTMUX" +unset realTMUX + +# End of tests. +assert_end "tmuxifier-tmux" From 41218e307278b205df3989a5d968daa982412138 Mon Sep 17 00:00:00 2001 From: Jim Myhrberg Date: Sun, 25 May 2014 01:24:49 +0100 Subject: [PATCH 09/30] Colorize part of test output --- test.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test.sh b/test.sh index 656e3ac..d7da71f 100755 --- a/test.sh +++ b/test.sh @@ -25,7 +25,8 @@ testfiles="$(find "$testdir" -name "*-test.sh")" RET=0 for testfile in $testfiles; do echo "" - echo "running: ${testfile/#$(dirname "$testdir")\//}" + echo -en "\033[0;35mrunning: " + echo -e "\033[0;36m${testfile/#$(dirname "$testdir")\//}\033[0m" cd "$(dirname "$testfile")" "$testfile" if [ "$?" != "0" ]; then RET=1; fi From 359f1a9a94c6b9f9507b78d0680bd22a170c438f Mon Sep 17 00:00:00 2001 From: Jim Myhrberg Date: Sun, 25 May 2014 01:32:07 +0100 Subject: [PATCH 10/30] Use tput instead of hard-coded color codes --- test.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test.sh b/test.sh index d7da71f..f9ae4f1 100755 --- a/test.sh +++ b/test.sh @@ -25,8 +25,8 @@ testfiles="$(find "$testdir" -name "*-test.sh")" RET=0 for testfile in $testfiles; do echo "" - echo -en "\033[0;35mrunning: " - echo -e "\033[0;36m${testfile/#$(dirname "$testdir")\//}\033[0m" + echo -en "$(tput setaf 5)running: " + echo -e "$(tput setaf 6)${testfile/#$(dirname "$testdir")\//}$(tput sgr0)" cd "$(dirname "$testfile")" "$testfile" if [ "$?" != "0" ]; then RET=1; fi From 57b4f303f26f659f9f7e5d58bd99d62fe53731c1 Mon Sep 17 00:00:00 2001 From: Jim Myhrberg Date: Sun, 25 May 2014 01:32:27 +0100 Subject: [PATCH 11/30] Install tmux on travis-ci.org --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 5b02332..c3b53bb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,4 @@ language: bash script: make test before_install: - - sudo apt-get install bc \ No newline at end of file + - sudo apt-get install bc tmux \ No newline at end of file From ed52353bba68ee7df5c541ce5c04bb8b0a861eb7 Mon Sep 17 00:00:00 2001 From: Jim Myhrberg Date: Sun, 25 May 2014 01:39:28 +0100 Subject: [PATCH 12/30] Attempt to get tmux 1.8 on Travis-CI boxes --- .travis.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index c3b53bb..6430cac 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,6 @@ language: bash script: make test before_install: - - sudo apt-get install bc tmux \ No newline at end of file + - sudo add-apt-repository -y ppa:kalakris/tmux + - sudo apt-get update + - sudo apt-get install -y bc tmux \ No newline at end of file From 0d0106e7bafc8cc760c62c0b8d4147cccf18c282 Mon Sep 17 00:00:00 2001 From: Jim Myhrberg Date: Sun, 25 May 2014 02:05:01 +0100 Subject: [PATCH 13/30] Attempt to run travis-ci tests against multiple versions of tmux --- .travis.yml | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 6430cac..ac0d3fa 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,16 @@ -language: bash +language: c script: make test +env: + - TMUX_VERSION="1.6" + - TMUX_VERSION="1.7" + - TMUX_VERSION="1.8" + - TMUX_VERSION="1.9a" before_install: - - sudo add-apt-repository -y ppa:kalakris/tmux - sudo apt-get update - - sudo apt-get install -y bc tmux \ No newline at end of file + - sudo apt-get install -y build-essential libevent-dev libncurses5-dev + - wget http://downloads.sourceforge.net/tmux/tmux-${TMUX_VERSION}.tar.gz + - tar -zxf tmux-${TMUX_VERSION}.tar.gz + - cd tmux-${TMUX_VERSION} + - ./configure && make && sudo make install + - cd .. + - sudo apt-get install -y bc \ No newline at end of file From a875b63033a061f8afb2f8d3c7675837a67d2a3d Mon Sep 17 00:00:00 2001 From: Jim Myhrberg Date: Sun, 25 May 2014 02:38:05 +0100 Subject: [PATCH 14/30] Attempt to fix test failing with Tmux 1.6 and 1.7 --- test/libexec/tmuxifier-tmux-test.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/libexec/tmuxifier-tmux-test.sh b/test/libexec/tmuxifier-tmux-test.sh index 0ac6f79..b634184 100755 --- a/test/libexec/tmuxifier-tmux-test.sh +++ b/test/libexec/tmuxifier-tmux-test.sh @@ -15,8 +15,8 @@ tmux $TMUXIFIER_TMUX_OPTS new -d -s foobar tmux $TMUXIFIER_TMUX_OPTS new -d -s dude # Passes all arguments to Tmux. -assert "${libexec}/tmuxifier-tmux list-sessions -F \"#{session_id}: #S\"" \ - "\$1: dude\n\$0: foobar" +assert "${libexec}/tmuxifier-tmux list-sessions -F \"- #{session_name}\"" \ + "- dude\n- foobar" # Tear down. tmux $TMUXIFIER_TMUX_OPTS kill-server From 396120cf531c383ecbf3c7fc5b511df49e0b681b Mon Sep 17 00:00:00 2001 From: Jim Myhrberg Date: Sun, 25 May 2014 02:41:54 +0100 Subject: [PATCH 15/30] Add slight speed improvements for Travis-CI --- .travis.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index ac0d3fa..0cd9f49 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,4 @@ language: c -script: make test env: - TMUX_VERSION="1.6" - TMUX_VERSION="1.7" @@ -7,10 +6,10 @@ env: - TMUX_VERSION="1.9a" before_install: - sudo apt-get update - - sudo apt-get install -y build-essential libevent-dev libncurses5-dev + - sudo apt-get install -y bc build-essential libevent-dev libncurses5-dev - wget http://downloads.sourceforge.net/tmux/tmux-${TMUX_VERSION}.tar.gz - tar -zxf tmux-${TMUX_VERSION}.tar.gz - cd tmux-${TMUX_VERSION} - ./configure && make && sudo make install - cd .. - - sudo apt-get install -y bc \ No newline at end of file +script: make test From 6e634ecba9b3c947d63c631843c843c9281f0386 Mon Sep 17 00:00:00 2001 From: Jim Myhrberg Date: Mon, 26 May 2014 11:28:16 +0100 Subject: [PATCH 16/30] Update stub.sh --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 90104af..23aa059 100644 --- a/Makefile +++ b/Makefile @@ -21,7 +21,7 @@ test/stub.sh: test -f "test/stub.sh" || ( \ echo "fetching test/stub.sh..." && \ curl -s -L -o test/stub.sh \ - https://raw.github.com/jimeh/stub.sh/v0.3.0/stub.sh \ + https://raw.github.com/jimeh/stub.sh/v1.0.1/stub.sh \ ) update-stub.sh: remove-stub.sh test/stub.sh From 47219d2d402663aa844d6d044f3cff0a7e24ebd2 Mon Sep 17 00:00:00 2001 From: Jim Myhrberg Date: Mon, 26 May 2014 11:28:28 +0100 Subject: [PATCH 17/30] Improve test environment for individual test files --- test/libexec/tmuxifier-tmux-test.sh | 4 ---- test/test-helper.sh | 4 ++++ 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/test/libexec/tmuxifier-tmux-test.sh b/test/libexec/tmuxifier-tmux-test.sh index b634184..fa54e00 100755 --- a/test/libexec/tmuxifier-tmux-test.sh +++ b/test/libexec/tmuxifier-tmux-test.sh @@ -8,8 +8,6 @@ source "${root}/lib/util.sh" # Setup. libexec="${root}/libexec" -realTMUX="$TMUX" -unset TMUX export TMUXIFIER_TMUX_OPTS="-L tmuxifier-tests" tmux $TMUXIFIER_TMUX_OPTS new -d -s foobar tmux $TMUXIFIER_TMUX_OPTS new -d -s dude @@ -21,8 +19,6 @@ assert "${libexec}/tmuxifier-tmux list-sessions -F \"- #{session_name}\"" \ # Tear down. tmux $TMUXIFIER_TMUX_OPTS kill-server unset TMUXIFIER_TMUX_OPTS -TMUX="$realTMUX" -unset realTMUX # End of tests. assert_end "tmuxifier-tmux" diff --git a/test/test-helper.sh b/test/test-helper.sh index 39d09e6..773c18a 100644 --- a/test/test-helper.sh +++ b/test/test-helper.sh @@ -27,6 +27,10 @@ root="$(abs_dirname "$testroot/../..")" # Set TMUXIFIER environment variable TMUXIFIER="$root" +# Unset TMUX environment variable, tests assume they're not running within +# Tmux. +unset TMUX + # Unset various Tmuxifier environment variables to prevent a local install of # Tmuxifier interfering with tests. unset TMUXIFIER_LAYOUT_PATH From f977850ea950fedab922349ab25e9565d01c1453 Mon Sep 17 00:00:00 2001 From: Jim Myhrberg Date: Mon, 26 May 2014 11:34:53 +0100 Subject: [PATCH 18/30] Add tests for __expand_path layout helper --- test/lib/layout-helpers/__expand_path-test.sh | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100755 test/lib/layout-helpers/__expand_path-test.sh diff --git a/test/lib/layout-helpers/__expand_path-test.sh b/test/lib/layout-helpers/__expand_path-test.sh new file mode 100755 index 0000000..f94069f --- /dev/null +++ b/test/lib/layout-helpers/__expand_path-test.sh @@ -0,0 +1,27 @@ +#! /usr/bin/env bash +source "../../test-helper.sh" +source "${root}/lib/layout-helpers.sh" + +# +# __expand_path() tests. +# + +# Setup. +realHOME="$HOME" +HOME="/home/test-user" + +# When given a path containing "~", it expands "~" to "$HOME". +assert '__expand_path "~/Foo/Bar"' "${HOME}/Foo/Bar" + +# When given a path without "~", it returns path as is. +assert '__expand_path "/path/to/file"' "/path/to/file" + +# When given a path containing spaces, it returns path correctly. +assert '__expand_path "~/Path To/File"' "${HOME}/Path To/File" + +# Tear down. +HOME="$realHOME" +unset realHOME + +# End of tests. +assert_end "__expand_path()" From 3aa151b86570f371af4354ede4d51dbfdc63a536 Mon Sep 17 00:00:00 2001 From: Jim Myhrberg Date: Mon, 26 May 2014 11:35:10 +0100 Subject: [PATCH 19/30] Add tests for __go_to_session layout helper --- .../layout-helpers/__go_to_session-test.sh | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100755 test/lib/layout-helpers/__go_to_session-test.sh diff --git a/test/lib/layout-helpers/__go_to_session-test.sh b/test/lib/layout-helpers/__go_to_session-test.sh new file mode 100755 index 0000000..84e4a89 --- /dev/null +++ b/test/lib/layout-helpers/__go_to_session-test.sh @@ -0,0 +1,32 @@ +#! /usr/bin/env bash +source "../../test-helper.sh" +source "${root}/lib/layout-helpers.sh" + +# +# __go_to_session() tests. +# + +# Setup. +session="tmuxifier-test-session" + +# When TMUX is not set, attach to $session. +stub tmuxifier-tmux +__go_to_session +assert_raises \ + "stub_called_with tmuxifier-tmux -u attach-session -t \"${session}:\"" 0 +restore tmuxifier-tmux + +# When TMUX is set, switch to $session. +TMUX="/tmp/tmux-501/default,1203,0" +stub tmuxifier-tmux +__go_to_session +assert_raises \ + "stub_called_with tmuxifier-tmux -u switch-client -t \"${session}:\"" 0 +restore tmuxifier-tmux +unset TMUX + +# Tear down. +unset session + +# End of tests. +assert_end "__go_to_session()" From 36add2263716cb282158d4587863b042d0c2c0e2 Mon Sep 17 00:00:00 2001 From: Jim Myhrberg Date: Mon, 26 May 2014 13:52:55 +0100 Subject: [PATCH 20/30] Use test-runner.sh instead of homegrown test.sh --- .gitignore | 3 +- Makefile | 38 ++++++++++++++----- test.sh | 35 ----------------- test/lib/{env-test.sh => env.test.sh} | 0 ...and_path-test.sh => __expand_path.test.sh} | 0 ...ession-test.sh => __go_to_session.test.sh} | 0 test/lib/{runtime-test.sh => runtime.test.sh} | 0 test/lib/{util-test.sh => util.test.sh} | 0 ...er-tmux-test.sh => tmuxifier-tmux.test.sh} | 0 9 files changed, 30 insertions(+), 46 deletions(-) delete mode 100755 test.sh rename test/lib/{env-test.sh => env.test.sh} (100%) rename test/lib/layout-helpers/{__expand_path-test.sh => __expand_path.test.sh} (100%) rename test/lib/layout-helpers/{__go_to_session-test.sh => __go_to_session.test.sh} (100%) rename test/lib/{runtime-test.sh => runtime.test.sh} (100%) rename test/lib/{util-test.sh => util.test.sh} (100%) rename test/libexec/{tmuxifier-tmux-test.sh => tmuxifier-tmux.test.sh} (100%) diff --git a/.gitignore b/.gitignore index 71ab7b8..6946830 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ +test-runner.sh test/assert.sh -test/stub.sh \ No newline at end of file +test/stub.sh diff --git a/Makefile b/Makefile index 23aa059..8fc5798 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,24 @@ -test: prepare - ./test.sh +test: bootstrap + ./test-runner.sh -prepare: test/assert.sh test/stub.sh +bootstrap: test-runner.sh test/assert.sh test/stub.sh + +clean: remove-test-runner.sh remove-assert.sh remove-stub.sh + +test-runner.sh: + test -f "test-runner.sh" || \ + echo "fetching test-runner.sh..." && \ + curl -s -L -o test-runner.sh \ + https://github.com/jimeh/test-runner.sh/raw/v0.1.0/test-runner.sh && \ + chmod +x test-runner.sh + +remove-test-runner.sh: + ( \ + test -f "test-runner.sh" && rm "test-runner.sh" && \ + echo "removed test-runner.sh"\ + ) || exit 0 + +update-test-runner.sh: remove-test-runner.sh test-runner.sh test/assert.sh: test -f "test/assert.sh" || ( \ @@ -10,13 +27,13 @@ test/assert.sh: https://raw.github.com/lehmannro/assert.sh/v1.0.2/assert.sh \ ) -update-assert.sh: remove-assert.sh test/assert.sh - remove-assert.sh: test -f "test/assert.sh" && \ rm "test/assert.sh" && \ echo "removed test/assert.sh" +update-assert.sh: remove-assert.sh test/assert.sh + test/stub.sh: test -f "test/stub.sh" || ( \ echo "fetching test/stub.sh..." && \ @@ -24,14 +41,15 @@ test/stub.sh: https://raw.github.com/jimeh/stub.sh/v1.0.1/stub.sh \ ) -update-stub.sh: remove-stub.sh test/stub.sh - remove-stub.sh: test -f "test/stub.sh" && \ rm "test/stub.sh" && \ echo "removed test/stub.sh" +update-stub.sh: remove-stub.sh test/stub.sh + .SILENT: -.PHONY: test prepare \ - test/assert.sh update-assert.sh remove-assert.sh \ - test/stub.sh update-stub.sh remove-stub.sh +.PHONY: test bootstrap clean \ + test-runner.sh remove-test-runner.sh update-test-runner.sh \ + test/assert.sh remove-assert.sh update-assert.sh \ + test/stub.sh remove-stub.sh update-stub.sh diff --git a/test.sh b/test.sh deleted file mode 100755 index f9ae4f1..0000000 --- a/test.sh +++ /dev/null @@ -1,35 +0,0 @@ -#! /usr/bin/env bash - -resolve_link() { - $(type -p greadlink readlink | head -1) $1 -} - -abs_dirname() { - local cwd="$(pwd)" - local path="$1" - - while [ -n "$path" ]; do - cd "${path%/*}" - local name="${path##*/}" - path="$(resolve_link "$name" || true)" - done - - pwd - cd "$cwd" -} - - -testdir="$(abs_dirname "$0")/test" -testfiles="$(find "$testdir" -name "*-test.sh")" - -RET=0 -for testfile in $testfiles; do - echo "" - echo -en "$(tput setaf 5)running: " - echo -e "$(tput setaf 6)${testfile/#$(dirname "$testdir")\//}$(tput sgr0)" - cd "$(dirname "$testfile")" - "$testfile" - if [ "$?" != "0" ]; then RET=1; fi -done -echo "" -exit $RET diff --git a/test/lib/env-test.sh b/test/lib/env.test.sh similarity index 100% rename from test/lib/env-test.sh rename to test/lib/env.test.sh diff --git a/test/lib/layout-helpers/__expand_path-test.sh b/test/lib/layout-helpers/__expand_path.test.sh similarity index 100% rename from test/lib/layout-helpers/__expand_path-test.sh rename to test/lib/layout-helpers/__expand_path.test.sh diff --git a/test/lib/layout-helpers/__go_to_session-test.sh b/test/lib/layout-helpers/__go_to_session.test.sh similarity index 100% rename from test/lib/layout-helpers/__go_to_session-test.sh rename to test/lib/layout-helpers/__go_to_session.test.sh diff --git a/test/lib/runtime-test.sh b/test/lib/runtime.test.sh similarity index 100% rename from test/lib/runtime-test.sh rename to test/lib/runtime.test.sh diff --git a/test/lib/util-test.sh b/test/lib/util.test.sh similarity index 100% rename from test/lib/util-test.sh rename to test/lib/util.test.sh diff --git a/test/libexec/tmuxifier-tmux-test.sh b/test/libexec/tmuxifier-tmux.test.sh similarity index 100% rename from test/libexec/tmuxifier-tmux-test.sh rename to test/libexec/tmuxifier-tmux.test.sh From 7e63149c2636b335138e6d6be1b8f40f5eb9546b Mon Sep 17 00:00:00 2001 From: Jim Myhrberg Date: Mon, 26 May 2014 20:20:39 +0100 Subject: [PATCH 21/30] Add tests for tmux layout helper --- test/lib/layout-helpers/tmux.test.sh | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100755 test/lib/layout-helpers/tmux.test.sh diff --git a/test/lib/layout-helpers/tmux.test.sh b/test/lib/layout-helpers/tmux.test.sh new file mode 100755 index 0000000..2803b22 --- /dev/null +++ b/test/lib/layout-helpers/tmux.test.sh @@ -0,0 +1,20 @@ +#! /usr/bin/env bash +source "../../test-helper.sh" +source "${root}/lib/layout-helpers.sh" + +# +# tmux() tests. +# + +# Passes all arguments to tmuxifier-tmux. +stub tmuxifier-tmux +tmux -V +tmux --help +tmux new -s dude +assert_raises "stub_called_with tmuxifier-tmux -V" 0 +assert_raises "stub_called_with tmuxifier-tmux --help" 0 +assert_raises "stub_called_with tmuxifier-tmux new -s dude" 0 +restore tmuxifier-tmux + +# End of tests. +assert_end "tmux()" From 8a06ad149e473c142afec045f06ad9297ae12791 Mon Sep 17 00:00:00 2001 From: Jim Myhrberg Date: Tue, 3 Jun 2014 20:01:31 +0100 Subject: [PATCH 22/30] Update test-runner.sh to v0.2.0 --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 8fc5798..69b9fc9 100644 --- a/Makefile +++ b/Makefile @@ -9,7 +9,7 @@ test-runner.sh: test -f "test-runner.sh" || \ echo "fetching test-runner.sh..." && \ curl -s -L -o test-runner.sh \ - https://github.com/jimeh/test-runner.sh/raw/v0.1.0/test-runner.sh && \ + https://github.com/jimeh/test-runner.sh/raw/v0.2.0/test-runner.sh && \ chmod +x test-runner.sh remove-test-runner.sh: From 636e92b1183394772240f68f3fa61adbe0dc67d4 Mon Sep 17 00:00:00 2001 From: Jim Myhrberg Date: Tue, 3 Jun 2014 20:01:47 +0100 Subject: [PATCH 23/30] Add tests for __go_to_window_or_session_path layout helper --- .../__go_to_window_or_session_path.test.sh | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100755 test/lib/layout-helpers/__go_to_window_or_session_path.test.sh diff --git a/test/lib/layout-helpers/__go_to_window_or_session_path.test.sh b/test/lib/layout-helpers/__go_to_window_or_session_path.test.sh new file mode 100755 index 0000000..4d6542f --- /dev/null +++ b/test/lib/layout-helpers/__go_to_window_or_session_path.test.sh @@ -0,0 +1,49 @@ +#! /usr/bin/env bash +source "../../test-helper.sh" +source "${root}/lib/layout-helpers.sh" + +# +# __go_to_window_or_session_path() tests. +# + +# When neither $window_root or $session_root are set, does nothing. +stub run_cmd +__go_to_window_or_session_path +assert "stub_called_times run_cmd" "0" +restore run_cmd + + +# When only $window_root is set, runs cd to $window_root path. +stub run_cmd +window_root="/tmp" +__go_to_window_or_session_path +assert 'stub_called_with_times run_cmd cd \"/tmp\"' "1" +assert 'stub_called_with_times run_cmd clear' "1" +unset window_root +restore run_cmd + + +# When only $session_root is set, runs cd to $session_root path. +stub run_cmd +session_root="/usr" +__go_to_window_or_session_path +assert 'stub_called_with_times run_cmd cd \"/usr\"' "1" +assert 'stub_called_with_times run_cmd clear' "1" +unset session_root +restore run_cmd + + +# When $window_root and $session_root are set, runs cd to $window_root path. +stub run_cmd +window_root="/tmp" +session_root="/usr" +__go_to_window_or_session_path +assert 'stub_called_with_times run_cmd cd \"/tmp\"' "1" +assert 'stub_called_with_times run_cmd clear' "1" +unset window_root +unset session_root +restore run_cmd + + +# End of tests. +assert_end "__go_to_window_or_session_path()" From 94b9559bfad2d1ffcaa6681845a0115ded457845 Mon Sep 17 00:00:00 2001 From: Jim Myhrberg Date: Tue, 3 Jun 2014 20:31:19 +0100 Subject: [PATCH 24/30] Use full tmux command names rather than aliases --- test/libexec/tmuxifier-tmux.test.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/libexec/tmuxifier-tmux.test.sh b/test/libexec/tmuxifier-tmux.test.sh index fa54e00..0ed39df 100755 --- a/test/libexec/tmuxifier-tmux.test.sh +++ b/test/libexec/tmuxifier-tmux.test.sh @@ -9,8 +9,8 @@ source "${root}/lib/util.sh" # Setup. libexec="${root}/libexec" export TMUXIFIER_TMUX_OPTS="-L tmuxifier-tests" -tmux $TMUXIFIER_TMUX_OPTS new -d -s foobar -tmux $TMUXIFIER_TMUX_OPTS new -d -s dude +tmux $TMUXIFIER_TMUX_OPTS new-session -d -s foobar +tmux $TMUXIFIER_TMUX_OPTS new-session -d -s dude # Passes all arguments to Tmux. assert "${libexec}/tmuxifier-tmux list-sessions -F \"- #{session_name}\"" \ From 1b0b3b8ba857211560bd3bc2122530127a589e39 Mon Sep 17 00:00:00 2001 From: Jim Myhrberg Date: Tue, 3 Jun 2014 20:31:41 +0100 Subject: [PATCH 25/30] Add tests for __get_first_window_index layout helper --- .../__get_first_window_index.test.sh | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100755 test/lib/layout-helpers/__get_first_window_index.test.sh diff --git a/test/lib/layout-helpers/__get_first_window_index.test.sh b/test/lib/layout-helpers/__get_first_window_index.test.sh new file mode 100755 index 0000000..ef34372 --- /dev/null +++ b/test/lib/layout-helpers/__get_first_window_index.test.sh @@ -0,0 +1,40 @@ +#! /usr/bin/env bash +source "../../test-helper.sh" +source "${root}/lib/layout-helpers.sh" + +# +# __get_first_window_index() tests. +# + +# Setup. +libexec="${root}/libexec" +export TMUXIFIER_TMUX_OPTS="-L tmuxifier-tests" +session="test" + + +# When first window has a index of 0. +tmux $TMUXIFIER_TMUX_OPTS new-session -d -s $session +assert "__get_first_window_index" "0" +tmux $TMUXIFIER_TMUX_OPTS kill-server + +# When first window has a index of 1. +tmux $TMUXIFIER_TMUX_OPTS new-session -d -s $session +tmux $TMUXIFIER_TMUX_OPTS new-window -t "$session:1" +tmux $TMUXIFIER_TMUX_OPTS kill-window -t "$session:0" +assert "__get_first_window_index" "1" +tmux $TMUXIFIER_TMUX_OPTS kill-server + +# When first window has a index of 2. +tmux $TMUXIFIER_TMUX_OPTS new-session -d -s $session +tmux $TMUXIFIER_TMUX_OPTS new-window -t "$session:2" +tmux $TMUXIFIER_TMUX_OPTS kill-window -t "$session:0" +assert "__get_first_window_index" "2" +tmux $TMUXIFIER_TMUX_OPTS kill-server + + +# Tear down. +unset TMUXIFIER_TMUX_OPTS +unset session + +# End of tests. +assert_end "__get_first_window_index()" From 87d767d1c521f2e7429f42959580846cd8b6ddba Mon Sep 17 00:00:00 2001 From: Jim Myhrberg Date: Tue, 3 Jun 2014 23:17:24 +0100 Subject: [PATCH 26/30] Fix issue with PATH in test environment --- test/test-helper.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/test-helper.sh b/test/test-helper.sh index 773c18a..db512ea 100644 --- a/test/test-helper.sh +++ b/test/test-helper.sh @@ -24,9 +24,12 @@ testroot="$(abs_dirname "$BASH_SOURCE")" # Set root variable. root="$(abs_dirname "$testroot/../..")" -# Set TMUXIFIER environment variable +# Set TMUXIFIER environment variable. TMUXIFIER="$root" +# Setup PATH environment variable. +PATH="$root/bin:$root/libexec:$PATH" + # Unset TMUX environment variable, tests assume they're not running within # Tmux. unset TMUX From d47838ca1ffe66cb4a26796213d4273b09b7b4e3 Mon Sep 17 00:00:00 2001 From: Jim Myhrberg Date: Wed, 4 Jun 2014 00:07:23 +0100 Subject: [PATCH 27/30] Add and use test helpers to create/kill test-specific tmux sessions --- .../__get_first_window_index.test.sh | 30 +++++++------------ test/libexec/tmuxifier-tmux.test.sh | 8 ++--- test/test-helper.sh | 29 ++++++++++++++++++ 3 files changed, 42 insertions(+), 25 deletions(-) diff --git a/test/lib/layout-helpers/__get_first_window_index.test.sh b/test/lib/layout-helpers/__get_first_window_index.test.sh index ef34372..c08dfd4 100755 --- a/test/lib/layout-helpers/__get_first_window_index.test.sh +++ b/test/lib/layout-helpers/__get_first_window_index.test.sh @@ -6,35 +6,25 @@ source "${root}/lib/layout-helpers.sh" # __get_first_window_index() tests. # -# Setup. -libexec="${root}/libexec" -export TMUXIFIER_TMUX_OPTS="-L tmuxifier-tests" -session="test" - - # When first window has a index of 0. -tmux $TMUXIFIER_TMUX_OPTS new-session -d -s $session +create-test-session assert "__get_first_window_index" "0" -tmux $TMUXIFIER_TMUX_OPTS kill-server +kill-test-session # When first window has a index of 1. -tmux $TMUXIFIER_TMUX_OPTS new-session -d -s $session -tmux $TMUXIFIER_TMUX_OPTS new-window -t "$session:1" -tmux $TMUXIFIER_TMUX_OPTS kill-window -t "$session:0" +create-test-session +test-socket-tmux new-window -t "$session:1" +test-socket-tmux kill-window -t "$session:0" assert "__get_first_window_index" "1" -tmux $TMUXIFIER_TMUX_OPTS kill-server +kill-test-session # When first window has a index of 2. -tmux $TMUXIFIER_TMUX_OPTS new-session -d -s $session -tmux $TMUXIFIER_TMUX_OPTS new-window -t "$session:2" -tmux $TMUXIFIER_TMUX_OPTS kill-window -t "$session:0" +create-test-session +test-socket-tmux new-window -t "$session:2" +test-socket-tmux kill-window -t "$session:0" assert "__get_first_window_index" "2" -tmux $TMUXIFIER_TMUX_OPTS kill-server +kill-test-session -# Tear down. -unset TMUXIFIER_TMUX_OPTS -unset session - # End of tests. assert_end "__get_first_window_index()" diff --git a/test/libexec/tmuxifier-tmux.test.sh b/test/libexec/tmuxifier-tmux.test.sh index 0ed39df..9716360 100755 --- a/test/libexec/tmuxifier-tmux.test.sh +++ b/test/libexec/tmuxifier-tmux.test.sh @@ -8,17 +8,15 @@ source "${root}/lib/util.sh" # Setup. libexec="${root}/libexec" -export TMUXIFIER_TMUX_OPTS="-L tmuxifier-tests" -tmux $TMUXIFIER_TMUX_OPTS new-session -d -s foobar -tmux $TMUXIFIER_TMUX_OPTS new-session -d -s dude +test-socket-tmux new-session -d -s foobar +test-socket-tmux new-session -d -s dude # Passes all arguments to Tmux. assert "${libexec}/tmuxifier-tmux list-sessions -F \"- #{session_name}\"" \ "- dude\n- foobar" # Tear down. -tmux $TMUXIFIER_TMUX_OPTS kill-server -unset TMUXIFIER_TMUX_OPTS +kill-test-server # End of tests. assert_end "tmuxifier-tmux" diff --git a/test/test-helper.sh b/test/test-helper.sh index db512ea..3d37985 100644 --- a/test/test-helper.sh +++ b/test/test-helper.sh @@ -18,6 +18,9 @@ abs_dirname() { cd "$cwd" } +# Find and store path to Tmux binary. +TMUX_BIN="$(command -v tmux)" + # Set testroot variable. testroot="$(abs_dirname "$BASH_SOURCE")" @@ -43,3 +46,29 @@ unset TMUXIFIER_NO_COMPLETE # Include assert.sh and stub.sh libraries. source "${testroot}/assert.sh" source "${testroot}/stub.sh" + + +test-socket-tmux() { + export TMUXIFIER_TMUX_OPTS="-L tmuxifier-tests" + "$TMUX_BIN" $TMUXIFIER_TMUX_OPTS $@ +} + +create-test-session() { + session="$1" + if [ -z "$session" ]; then session="test"; fi + + test-socket-tmux new-session -d -s "$session" +} + +kill-test-session() { + local target="$1" + if [ -z "$target" ]; then target="$session"; fi + + test-socket-tmux kill-session -t "$target" +} + +kill-test-server() { + test-socket-tmux kill-server + unset TMUXIFIER_TMUX_OPTS + unset session +} From d8b8dff61f355d55b63476e55316fbe4363ab765 Mon Sep 17 00:00:00 2001 From: Jim Myhrberg Date: Wed, 4 Jun 2014 00:36:33 +0100 Subject: [PATCH 28/30] Add tests for new_window layout helper --- test/lib/layout-helpers/new_window.test.sh | 47 ++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100755 test/lib/layout-helpers/new_window.test.sh diff --git a/test/lib/layout-helpers/new_window.test.sh b/test/lib/layout-helpers/new_window.test.sh new file mode 100755 index 0000000..2507f43 --- /dev/null +++ b/test/lib/layout-helpers/new_window.test.sh @@ -0,0 +1,47 @@ +#! /usr/bin/env bash +source "../../test-helper.sh" +source "${root}/lib/layout-helpers.sh" + +# +# new_window() tests. +# + +# When called without arguments, creates new window. +create-test-session +stub __go_to_window_or_session_path +assert "test-socket-tmux list-windows | wc -l | awk '{print \$1}'" "1" +new_window +assert "test-socket-tmux list-windows | wc -l | awk '{print \$1}'" "2" +assert "stub_called_times __go_to_window_or_session_path" "1" +restore __go_to_window_or_session_path +kill-test-session + +# When called with name argument, creates new window with specified name. +create-test-session +stub __go_to_window_or_session_path +assert "test-socket-tmux list-windows | wc -l | awk '{print \$1}'" "1" +assert "test-socket-tmux list-windows | grep yippieezzz | wc -l | awk '{print \$1}'" "0" +new_window "yippieezzz" +assert "test-socket-tmux list-windows | wc -l | awk '{print \$1}'" "2" +assert "test-socket-tmux list-windows | grep yippieezzz | wc -l | awk '{print \$1}'" "1" +restore __go_to_window_or_session_path +kill-test-session + +# When called with name and command argument, creates new window with +# specified name and executes given command. +rm "/tmp/tmuxifier-new_window-test" &> /dev/null +create-test-session +stub __go_to_window_or_session_path +assert "test-socket-tmux list-windows | wc -l | awk '{print \$1}'" "1" +assert "test-socket-tmux list-windows | grep foobardoo | wc -l | awk '{print \$1}'" "0" +new_window "foobardoo" "touch /tmp/tmuxifier-new_window-test; bash" +assert "test-socket-tmux list-windows | wc -l | awk '{print \$1}'" "2" +assert "test-socket-tmux list-windows | grep foobardoo | wc -l | awk '{print \$1}'" "1" +assert_raises 'test -f "/tmp/tmuxifier-new_window-test"' 0 +restore __go_to_window_or_session_path +kill-test-session +rm "/tmp/tmuxifier-new_window-test" &> /dev/null + + +# End of tests. +assert_end "new_window()" From 77ccb5d532a49c4c1d9aab6eb457d0e7d7543fc5 Mon Sep 17 00:00:00 2001 From: Jim Myhrberg Date: Mon, 21 Jul 2014 16:13:16 +0100 Subject: [PATCH 29/30] Clean up test a bit --- test/lib/layout-helpers/new_window.test.sh | 20 ++++++++++---------- test/test-helper.sh | 13 +++++++++++++ 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/test/lib/layout-helpers/new_window.test.sh b/test/lib/layout-helpers/new_window.test.sh index 2507f43..5b162b7 100755 --- a/test/lib/layout-helpers/new_window.test.sh +++ b/test/lib/layout-helpers/new_window.test.sh @@ -9,9 +9,9 @@ source "${root}/lib/layout-helpers.sh" # When called without arguments, creates new window. create-test-session stub __go_to_window_or_session_path -assert "test-socket-tmux list-windows | wc -l | awk '{print \$1}'" "1" +assert "test-socket-window-count" "1" new_window -assert "test-socket-tmux list-windows | wc -l | awk '{print \$1}'" "2" +assert "test-socket-window-count" "2" assert "stub_called_times __go_to_window_or_session_path" "1" restore __go_to_window_or_session_path kill-test-session @@ -19,11 +19,10 @@ kill-test-session # When called with name argument, creates new window with specified name. create-test-session stub __go_to_window_or_session_path -assert "test-socket-tmux list-windows | wc -l | awk '{print \$1}'" "1" -assert "test-socket-tmux list-windows | grep yippieezzz | wc -l | awk '{print \$1}'" "0" +assert "test-socket-window-count yippieezzz" "0" new_window "yippieezzz" -assert "test-socket-tmux list-windows | wc -l | awk '{print \$1}'" "2" -assert "test-socket-tmux list-windows | grep yippieezzz | wc -l | awk '{print \$1}'" "1" +assert "test-socket-window-count" "2" +assert "test-socket-window-count yippieezzz" "1" restore __go_to_window_or_session_path kill-test-session @@ -32,16 +31,17 @@ kill-test-session rm "/tmp/tmuxifier-new_window-test" &> /dev/null create-test-session stub __go_to_window_or_session_path -assert "test-socket-tmux list-windows | wc -l | awk '{print \$1}'" "1" -assert "test-socket-tmux list-windows | grep foobardoo | wc -l | awk '{print \$1}'" "0" new_window "foobardoo" "touch /tmp/tmuxifier-new_window-test; bash" -assert "test-socket-tmux list-windows | wc -l | awk '{print \$1}'" "2" -assert "test-socket-tmux list-windows | grep foobardoo | wc -l | awk '{print \$1}'" "1" +assert "test-socket-window-count" "2" +assert "test-socket-window-count foobardoo" "1" assert_raises 'test -f "/tmp/tmuxifier-new_window-test"' 0 restore __go_to_window_or_session_path kill-test-session rm "/tmp/tmuxifier-new_window-test" &> /dev/null +# Tear down. +kill-test-server + # End of tests. assert_end "new_window()" diff --git a/test/test-helper.sh b/test/test-helper.sh index 3d37985..ed081be 100644 --- a/test/test-helper.sh +++ b/test/test-helper.sh @@ -48,6 +48,10 @@ source "${testroot}/assert.sh" source "${testroot}/stub.sh" +# +# Test Helpers +# + test-socket-tmux() { export TMUXIFIER_TMUX_OPTS="-L tmuxifier-tests" "$TMUX_BIN" $TMUXIFIER_TMUX_OPTS $@ @@ -72,3 +76,12 @@ kill-test-server() { unset TMUXIFIER_TMUX_OPTS unset session } + +test-socket-window-count() { + local list="$(test-socket-tmux list-windows)" + if [ -n "$1" ]; then + echo "$list" | grep $1 | wc -l | awk '{print $1}' + else + echo "$list" | wc -l | awk '{print $1}' + fi +} From 6a1e9e4de743da3018a8482e7bafc594a54fa883 Mon Sep 17 00:00:00 2001 From: Jim Myhrberg Date: Thu, 21 Aug 2014 01:54:05 +0100 Subject: [PATCH 30/30] Cleanup Makefile a bit --- Makefile | 47 +++++++++++++++++++++-------------------------- 1 file changed, 21 insertions(+), 26 deletions(-) diff --git a/Makefile b/Makefile index 69b9fc9..8a83c37 100644 --- a/Makefile +++ b/Makefile @@ -2,54 +2,49 @@ test: bootstrap ./test-runner.sh bootstrap: test-runner.sh test/assert.sh test/stub.sh - -clean: remove-test-runner.sh remove-assert.sh remove-stub.sh +clean: remove_test-runner.sh remove_test/assert.sh remove_test/stub.sh +update: update_test-runner.sh update_test/assert.sh update_test/stub.sh test-runner.sh: - test -f "test-runner.sh" || \ - echo "fetching test-runner.sh..." && \ - curl -s -L -o test-runner.sh \ - https://github.com/jimeh/test-runner.sh/raw/v0.2.0/test-runner.sh && \ - chmod +x test-runner.sh + echo "fetching test-runner.sh..." && \ + curl -s -L -o test-runner.sh \ + https://github.com/jimeh/test-runner.sh/raw/v0.2.0/test-runner.sh && \ + chmod +x test-runner.sh -remove-test-runner.sh: +remove_test-runner.sh: ( \ test -f "test-runner.sh" && rm "test-runner.sh" && \ echo "removed test-runner.sh"\ ) || exit 0 -update-test-runner.sh: remove-test-runner.sh test-runner.sh +update_test-runner.sh: remove_test-runner.sh test-runner.sh test/assert.sh: - test -f "test/assert.sh" || ( \ - echo "fetching test/assert.sh..." && \ - curl -s -L -o test/assert.sh \ - https://raw.github.com/lehmannro/assert.sh/v1.0.2/assert.sh \ - ) + echo "fetching test/assert.sh..." && \ + curl -s -L -o test/assert.sh \ + https://raw.github.com/lehmannro/assert.sh/v1.0.2/assert.sh -remove-assert.sh: +remove_test/assert.sh: test -f "test/assert.sh" && \ rm "test/assert.sh" && \ echo "removed test/assert.sh" -update-assert.sh: remove-assert.sh test/assert.sh +update_test/assert.sh: remove_test/assert.sh test/assert.sh test/stub.sh: - test -f "test/stub.sh" || ( \ - echo "fetching test/stub.sh..." && \ - curl -s -L -o test/stub.sh \ - https://raw.github.com/jimeh/stub.sh/v1.0.1/stub.sh \ - ) + echo "fetching test/stub.sh..." && \ + curl -s -L -o test/stub.sh \ + https://raw.github.com/jimeh/stub.sh/v1.0.1/stub.sh -remove-stub.sh: +remove_test/stub.sh: test -f "test/stub.sh" && \ rm "test/stub.sh" && \ echo "removed test/stub.sh" -update-stub.sh: remove-stub.sh test/stub.sh +update_test/stub.sh: remove_test/stub.sh test/stub.sh .SILENT: .PHONY: test bootstrap clean \ - test-runner.sh remove-test-runner.sh update-test-runner.sh \ - test/assert.sh remove-assert.sh update-assert.sh \ - test/stub.sh remove-stub.sh update-stub.sh + remove_test-runner.sh update_test-runner.sh \ + remove_test/assert.sh update_test/assert.sh \ + remove_test/stub.sh update_test/stub.sh