From ae4b93f52f0d3fc17cbe178aaf0683b3b397926d Mon Sep 17 00:00:00 2001 From: Matthew Rothenberg Date: Thu, 16 Oct 2014 16:38:09 -0400 Subject: [PATCH] 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" }