From 802f4987c36730d6b9496c7a96374bfee5b1695e Mon Sep 17 00:00:00 2001 From: Matthew Rothenberg Date: Wed, 15 Oct 2014 12:57:28 -0400 Subject: [PATCH 01/11] set up multi-os testing in travis Requires beta access, thankfully the travis gods have blessed us for the main repo and my fork! This should allow us to make sure scm_breeze operates reliably in both Linux and BSD/Darwin, because there are small shell differences (especially with default tools) that are causing errors I noticed on MacOSX. --- .travis.yml | 12 +++++++++--- test/support/travisci_deps.sh | 14 ++++++++++++++ 2 files changed, 23 insertions(+), 3 deletions(-) create mode 100755 test/support/travisci_deps.sh diff --git a/.travis.yml b/.travis.yml index 3d40388..30f5fa2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,9 @@ -script: ./run_tests.sh -before_script: - - sudo apt-get install zsh +os: + - linux + - osx + +install: + - ./test/support/travisci_deps.sh + +script: + - ./run_tests.sh diff --git a/test/support/travisci_deps.sh b/test/support/travisci_deps.sh new file mode 100755 index 0000000..d4523ee --- /dev/null +++ b/test/support/travisci_deps.sh @@ -0,0 +1,14 @@ +#!/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. +# +# TODO: also perhaps later only on ZSH test box if we split those +if [[ "$TRAVIS_OS_NAME" != "osx" ]]; then + sudo apt-get install zsh +fi From b6fd7ae829e2060a251fbe5cd06c7ab759f92e75 Mon Sep 17 00:00:00 2001 From: Matthew Rothenberg Date: Wed, 15 Oct 2014 14:12:24 -0400 Subject: [PATCH 02/11] split tests up by shell for concurrency More parallelism = faster tests. Also better isolation for changes that might only break on zsh or bash respectively. This is defined via env variable, so someone running locally will have all tests run sequentially as before. --- .travis.yml | 6 ++++++ run_tests.sh | 11 +++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 30f5fa2..7abf0e3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,12 @@ os: - linux - osx +env: + - TEST_SHELLS="zsh bash" + - TEST_SHELLS=bash + - TEST_SHELLS=zsh + - HI=mom + install: - ./test/support/travisci_deps.sh diff --git a/run_tests.sh b/run_tests.sh index fff4438..877f9ed 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 @@ -16,4 +23,4 @@ if [ "$failed" = "true" ]; then else echo "All tests passed!" return 0; -fi \ No newline at end of file +fi From e7c56c7647ea491da3ecd13c80456c6f8b11d76a Mon Sep 17 00:00:00 2001 From: Matthew Rothenberg Date: Wed, 15 Oct 2014 16:36:43 -0400 Subject: [PATCH 03/11] only install zsh on boxes that need it MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit don’t bother on macosx (preinstalled) or if the test matrix for that box isn’t going to be testing in zsh. this should speed up test runs for most cases, and later we can define fast_failure and not have to wait for the longer ones. --- test/support/travisci_deps.sh | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/test/support/travisci_deps.sh b/test/support/travisci_deps.sh index d4523ee..83cc32e 100755 --- a/test/support/travisci_deps.sh +++ b/test/support/travisci_deps.sh @@ -7,8 +7,26 @@ # # 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. -# -# TODO: also perhaps later only on ZSH test box if we split those if [[ "$TRAVIS_OS_NAME" != "osx" ]]; then - sudo apt-get install zsh + + # 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 From f056d28b2eb1f20793119a5c48f75bef7f9954d7 Mon Sep 17 00:00:00 2001 From: Matthew Rothenberg Date: Thu, 16 Oct 2014 11:39:08 -0400 Subject: [PATCH 04/11] remove redundant test envs they were just there when we were making sure the env variable shell selection was working properly in all cases, now that we know it is, they can be removed. --- .travis.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 7abf0e3..f2597de 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,10 +3,8 @@ os: - osx env: - - TEST_SHELLS="zsh bash" - TEST_SHELLS=bash - TEST_SHELLS=zsh - - HI=mom install: - ./test/support/travisci_deps.sh From b395596496373aeb90bbdd9fb3fddcfa7c01cb48 Mon Sep 17 00:00:00 2001 From: Matthew Rothenberg Date: Thu, 16 Oct 2014 12:19:11 -0400 Subject: [PATCH 05/11] dont use grep -P for cross-platform compatibility `grep -P` gives access to the PCRE matching engine, which is nice, however, the version of grep shipped on many BSD systems (including Darwin) does not have this flag. Currently, `grep -P` was being used in the `_includes()` test helper. For cross platform compatibility in tests, do not rely upon this option. Luckily, all existing tests seem to work fine without it already! --- test/lib/git/shell_shortcuts_test.sh | 2 +- test/support/test_helper.sh | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/test/lib/git/shell_shortcuts_test.sh b/test/lib/git/shell_shortcuts_test.sh index 3a6843a..834f03b 100755 --- a/test/lib/git/shell_shortcuts_test.sh +++ b/test/lib/git/shell_shortcuts_test.sh @@ -82,7 +82,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/support/test_helper.sh b/test/support/test_helper.sh index 7407b59..cf211a6 100644 --- a/test/support/test_helper.sh +++ b/test/support/test_helper.sh @@ -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 "$@") } - From b2d86a16b2a0a53c8c0c176909fbdc0ec22ee732 Mon Sep 17 00:00:00 2001 From: Matthew Rothenberg Date: Thu, 16 Oct 2014 15:31:12 -0400 Subject: [PATCH 06/11] use perl instead of sed -r to strip colors in test `sed -r` is not present on some BSD based systems, including MacOSX Darwin. perl is standard pretty much everywhere, so this a more reliable way to test. Since this is only used for tests, any performance differences should not matter significantly. --- test/support/test_helper.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/support/test_helper.sh b/test/support/test_helper.sh index cf211a6..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 From 1cd162434fb72c9050602703a76677707346a649 Mon Sep 17 00:00:00 2001 From: Matthew Rothenberg Date: Thu, 16 Oct 2014 16:10:52 -0400 Subject: [PATCH 07/11] Make sure we have physical path back from mktemp 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. --- test/lib/git/shell_shortcuts_test.sh | 8 ++++++++ test/lib/git/status_shortcuts_test.sh | 1 + 2 files changed, 9 insertions(+) diff --git a/test/lib/git/shell_shortcuts_test.sh b/test/lib/git/shell_shortcuts_test.sh index 834f03b..2ace560 100755 --- a/test/lib/git/shell_shortcuts_test.sh +++ b/test/lib/git/shell_shortcuts_test.sh @@ -71,7 +71,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" diff --git a/test/lib/git/status_shortcuts_test.sh b/test/lib/git/status_shortcuts_test.sh index aa86d2e..818183f 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() { From ae4b93f52f0d3fc17cbe178aaf0683b3b397926d Mon Sep 17 00:00:00 2001 From: Matthew Rothenberg Date: Thu, 16 Oct 2014 16:38:09 -0400 Subject: [PATCH 08/11] declare original location of cmds The previous tests assumed default locations for all commands, however they do not exist in the same place on all *nixes. I encountered this when the test was failing on MacOSX where it was expected hardcoded `/bin/sed` when in fact the code was identifying the correct local expansion of `/usr/bin/sed`. To make this test more robust, it now checks for the original location of all cmds and uses that in its expansion tests for `test_shell_command_wrapping()`. --- test/lib/git/shell_shortcuts_test.sh | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/test/lib/git/shell_shortcuts_test.sh b/test/lib/git/shell_shortcuts_test.sh index 2ace560..1f8954f 100755 --- a/test/lib/git/shell_shortcuts_test.sh +++ b/test/lib/git/shell_shortcuts_test.sh @@ -31,6 +31,14 @@ oneTimeSetUp() { # Test functions function ln() { ln $@; } + + # Before aliasing, get original locations so we can compare them in the test + unalias mv rm sed cat 2>/dev/null + orig_mv=`which mv` + orig_rm=`which rm` + orig_sed=`which sed` + orig_cat=`which cat` + # Test aliases alias mv="nocorrect mv" alias rm="rm --option" @@ -58,11 +66,11 @@ assertAliasEquals(){ #----------------------------------------------------------------------------- test_shell_command_wrapping() { - assertAliasEquals "exec_scmb_expand_args /bin/rm --option" "rm" - assertAliasEquals "exec_scmb_expand_args nocorrect /bin/mv" "mv" - assertAliasEquals "exec_scmb_expand_args /bin/sed" "sed" - assertAliasEquals "exec_scmb_expand_args /bin/cat" "cat" - assertAliasEquals "exec_scmb_expand_args builtin cd" "cd" + assertAliasEquals "exec_scmb_expand_args $orig_rm --option" "rm" + assertAliasEquals "exec_scmb_expand_args nocorrect $orig_mv" "mv" + assertAliasEquals "exec_scmb_expand_args $orig_sed" "sed" + assertAliasEquals "exec_scmb_expand_args $orig_cat" "cat" + assertAliasEquals "exec_scmb_expand_args builtin cd" "cd" assertIncludes "$(declare -f ln)" "ln ()" assertIncludes "$(declare -f ln)" "exec_scmb_expand_args __original_ln" } From c234916b2bdb2d54b4ff7dc7c77e44029ee07c1e Mon Sep 17 00:00:00 2001 From: Matthew Rothenberg Date: Thu, 16 Oct 2014 17:08:29 -0400 Subject: [PATCH 09/11] scripts should exit rather than return MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit some shells are pickier about this. darwin uses a newer version of sh that complains about it. this is the ‘proper’ behavior in either scenario. --- run_tests.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/run_tests.sh b/run_tests.sh index 877f9ed..2d5c061 100755 --- a/run_tests.sh +++ b/run_tests.sh @@ -19,8 +19,8 @@ done if [ "$failed" = "true" ]; then echo "Tests failed!" - return 1; + exit 1; else echo "All tests passed!" - return 0; + exit 0; fi From 9a9b6104e2e87a19854ac42418773a6dd51e0916 Mon Sep 17 00:00:00 2001 From: Matthew Rothenberg Date: Thu, 16 Oct 2014 17:20:49 -0400 Subject: [PATCH 10/11] Compatibility fix for Design Assets Management design.sh uses `readlink -m` to determine canonical path of git dir, which is not available on all *nix systems (including Darwin). Instead, use `pwd -P` to get canonical directory path in a more cross-platform compatible way. This is a change to an actual script rather than just a test, and it should make the Design Assets Management functionality of scm_breeze now function properly on MacOSX. --- lib/design.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/design.sh b/lib/design.sh index 5106247..d7e041a 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 From c6b9c398c89295bb97faebba4e2180fcf0ee31b3 Mon Sep 17 00:00:00 2001 From: Matthew Rothenberg Date: Mon, 20 Oct 2014 15:16:04 -0400 Subject: [PATCH 11/11] temp before_script to debug sort order on travis I tested manually on OSX and linux, but lets make sure the same thing is true on travis-ci builds. --- .travis.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.travis.yml b/.travis.yml index f2597de..d038f60 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,5 +9,8 @@ env: install: - ./test/support/travisci_deps.sh +before_script: + - echo -e "test_repo_11\ntest_repo_1" | sort + script: - ./run_tests.sh