diff --git a/.travis.yml b/.travis.yml index 3d40388..d038f60 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,16 @@ -script: ./run_tests.sh +os: + - linux + - osx + +env: + - TEST_SHELLS=bash + - TEST_SHELLS=zsh + +install: + - ./test/support/travisci_deps.sh + before_script: - - sudo apt-get install zsh + - echo -e "test_repo_11\ntest_repo_1" | sort + +script: + - ./run_tests.sh diff --git a/lib/design.sh b/lib/design.sh index e0e2091..125175e 100644 --- a/lib/design.sh +++ b/lib/design.sh @@ -23,7 +23,7 @@ # Add ignore rule to .git/info/exclude if not already present _design_add_git_exclude(){ - local git_dir="$(cd $1 && readlink -m $(git rev-parse --git-dir))" + local git_dir="$(cd $1 && cd `git rev-parse --git-dir` && pwd -P)" if [ -e "$git_dir/info/exclude" ] && ! $(grep -q "$project_design_dir" "$git_dir/info/exclude"); then echo "$project_design_dir" >> "$git_dir/info/exclude" fi diff --git a/run_tests.sh b/run_tests.sh index 9aebd4c..e25c5eb 100755 --- a/run_tests.sh +++ b/run_tests.sh @@ -3,8 +3,15 @@ failed=false +# allow list of shells to run tests in to be overriden by environment variable +# if empty or null, use defaults +if [ -z "$TEST_SHELLS" ]; then + TEST_SHELLS="bash zsh" +fi + +echo "== Will run all tests with following shells: ${TEST_SHELLS}" for test in $(find test/lib -name *_test.sh); do - for shell in bash zsh; do + for shell in $TEST_SHELLS; do echo "== Running tests with [$shell]: $test" $shell $test || failed=true done diff --git a/test/lib/git/shell_shortcuts_test.sh b/test/lib/git/shell_shortcuts_test.sh index b4664f3..37281d4 100755 --- a/test/lib/git/shell_shortcuts_test.sh +++ b/test/lib/git/shell_shortcuts_test.sh @@ -32,11 +32,15 @@ oneTimeSetUp() { # Test functions function ln() { ln $@; } - # Test aliases + + # Before aliasing, get original locations so we can compare them in the test + unalias mv rm sed cat 2>/dev/null export mv_path="$(which mv)" export rm_path="$(which rm)" export sed_path="$(which sed)" - export cat_pathj="$(which cat)" + export cat_path="$(which cat)" + + # Test aliases alias mv="nocorrect $mv_path" alias rm="$rm_path --option" alias sed="$sed_path" @@ -67,7 +71,7 @@ test_shell_command_wrapping() { assertAliasEquals "exec_scmb_expand_args nocorrect $mv_path" "mv" assertAliasEquals "exec_scmb_expand_args $sed_path" "sed" assertAliasEquals "exec_scmb_expand_args $cat_path" "cat" - assertAliasEquals "exec_scmb_expand_args builtin cd" "cd" + assertAliasEquals "exec_scmb_expand_args builtin cd" "cd" assertIncludes "$(declare -f ln)" "ln ()" assertIncludes "$(declare -f ln)" "exec_scmb_expand_args __original_ln" } @@ -76,7 +80,15 @@ test_ls_with_file_shortcuts() { export git_env_char="e" TEST_DIR=$(mktemp -d -t scm_breeze.XXXXXXXXXX) + + # Darwin actually symlinks /var inside /private, but mktemp reports back the + # logical pathat time of file creation. So make sure we always get the + # full physical path to be absolutely certain when doing comparisons later, + # because thats how the Ruby status_shortcuts.rb script is going to obtain + # them. cd $TEST_DIR + TEST_DIR=$(pwd -P) + touch 'test file' 'test_file' mkdir -p "a [b]" 'a "b"' "a 'b'" touch "a \"b\"/c" @@ -87,7 +99,7 @@ test_ls_with_file_shortcuts() { ls_with_file_shortcuts > $temp_file ls_output=$(<$temp_file strip_colors) - # Compare as fixed strings (F), instead of regex (P) + # Compare as fixed strings (F), instead of normal grep behavior assertIncludes "$ls_output" '[1] a "b"' F assertIncludes "$ls_output" "[2] a 'b'" F assertIncludes "$ls_output" '[3] a [b]' F diff --git a/test/lib/git/status_shortcuts_test.sh b/test/lib/git/status_shortcuts_test.sh index 71eb5d5..d83d9ca 100755 --- a/test/lib/git/status_shortcuts_test.sh +++ b/test/lib/git/status_shortcuts_test.sh @@ -29,6 +29,7 @@ oneTimeSetUp() { export ga_auto_remove="yes" testRepo=$(mktemp -d -t scm_breeze.XXXXXXXXXX) + testRepo=$(cd $testRepo && pwd -P) } oneTimeTearDown() { diff --git a/test/support/test_helper.sh b/test/support/test_helper.sh index 7407b59..ba9e472 100644 --- a/test/support/test_helper.sh +++ b/test/support/test_helper.sh @@ -15,7 +15,7 @@ fi # Strip color codes from a string strip_colors() { - sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g" + perl -pe 's/\e\[[\d;]*m//g' } # Print space separated tab completion options @@ -34,7 +34,7 @@ verboseGitCommands() { #----------------------------------------------------------------------------- _includes() { - if [ -n "$3" ]; then regex="$3"; else regex=P; fi + if [ -n "$3" ]; then regex="$3"; else regex=''; fi if echo "$1" | grep -q$regex "$2"; then echo 0; else echo 1; fi } @@ -46,4 +46,3 @@ assertIncludes() { assertNotIncludes() { assertFalse "'$1' should not have contained '$2'" $(_includes "$@") } - diff --git a/test/support/travisci_deps.sh b/test/support/travisci_deps.sh new file mode 100755 index 0000000..83cc32e --- /dev/null +++ b/test/support/travisci_deps.sh @@ -0,0 +1,32 @@ +#!/usr/bin/env bash +# Installs dependencies for travis-ci environments. + +# Install dependencies, which looks to be just bash & zsh. +# +# Darwin has zsh preinstalled already, so only need to install on Ubuntu. +# +# Note: $TRAVIS_OS_NAME will only be set on text boxes with multi-os enabled, +# so use negation test so it will fail gracefully on normal Travis linux setup. +if [[ "$TRAVIS_OS_NAME" != "osx" ]]; then + + # okay, so we know we're probably on a linux box (or at least not an osx box) + # at this point. do we need to install zsh? let's say the default case is no: + needs_zsh=false + + # check if zsh is listed in the TEST_SHELLS environment variable, set by + # our travis-ci build matrix. + if [[ $TEST_SHELLS =~ zsh ]]; then needs_zsh=true; fi + + # if there is NO $TEST_SHELLS env variable persent (which should never happen, + # but maybe someone has been monkeying with the .travis.yml), run_tests.sh is + # going to fall back onto the default of testing everything, so we need zsh. + if [[ -z "$TEST_SHELLS" ]]; then needs_zsh=true; fi + + # finally, we install zsh if needed! + if $needs_zsh ; then + sudo apt-get install zsh + else + echo "No deps required." + fi + +fi