Fully fixed up ll escaping, added lots of tests
This commit is contained in:
@@ -13,7 +13,7 @@ export scmbDir="$( cd -P "$( dirname "$0" )" && pwd )/../../.."
|
||||
if [ -n "${ZSH_VERSION:-}" ]; then shell="zsh"; SHUNIT_PARENT=$0; setopt shwordsplit; fi
|
||||
|
||||
# Load test helpers
|
||||
source "$scmbDir/test/support/test_helper"
|
||||
source "$scmbDir/test/support/test_helper.sh"
|
||||
|
||||
# Load functions to test
|
||||
source "$scmbDir/lib/scm_breeze.sh"
|
||||
|
||||
@@ -11,31 +11,29 @@ export scmbDir="$( cd -P "$( dirname "$0" )" && pwd )/../../.."
|
||||
|
||||
# Zsh compatibility
|
||||
if [ -n "${ZSH_VERSION:-}" ]; then
|
||||
shell="zsh"
|
||||
SHUNIT_PARENT=$0
|
||||
setopt shwordsplit
|
||||
shell="zsh"; SHUNIT_PARENT=$0; setopt shwordsplit
|
||||
else
|
||||
# Bash needs this option so that 'alias' works in a non-interactive shell
|
||||
shopt -s expand_aliases
|
||||
fi
|
||||
|
||||
# Load test helpers
|
||||
source "$scmbDir/test/support/test_helper"
|
||||
source "$scmbDir/test/support/test_helper.sh"
|
||||
|
||||
# Setup
|
||||
#-----------------------------------------------------------------------------
|
||||
oneTimeSetUp() {
|
||||
export shell_command_wrapping_enabled="true"
|
||||
export scmb_wrapped_shell_commands="not_found cat rm cp mv ln ls cd sed"
|
||||
export scmb_wrapped_shell_commands="not_found cat rm cp mv ln cd sed"
|
||||
|
||||
# Test functions
|
||||
function ls() { ls $@; }
|
||||
function ln() { ln $@; }
|
||||
# Test aliases
|
||||
alias mv="nocorrect mv"
|
||||
alias rm="rm --option"
|
||||
alias sed="sed"
|
||||
# Test already wrapped commands
|
||||
alias ln="exec_scmb_expand_args /bin/ln"
|
||||
alias cat="exec_scmb_expand_args /bin/cat"
|
||||
|
||||
# Run shortcut wrapping
|
||||
source "$scmbDir/lib/git/shell_shortcuts.sh"
|
||||
@@ -62,11 +60,37 @@ test_shell_command_wrapping() {
|
||||
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 __original_ls" "ls"
|
||||
assertAliasEquals "exec_scmb_expand_args /bin/ln" "ln"
|
||||
assertAliasEquals "exec_scmb_expand_args __original_ln" "ln"
|
||||
}
|
||||
|
||||
test_ls_with_file_shortcuts() {
|
||||
export git_env_char="e"
|
||||
|
||||
TEST_DIR=$(mktemp -d -t scm_breeze.XXXXXXXXXX)
|
||||
cd $TEST_DIR
|
||||
touch 'test file' 'test_file'
|
||||
mkdir -p "a [b]" 'a "b"' "a 'b'"
|
||||
|
||||
# Run command in shell, load output from temp file into variable
|
||||
# (This is needed so that env variables are exported in the current shell)
|
||||
temp_file=$(mktemp -t scm_breeze.XXXXXXXXXX)
|
||||
ls_with_file_shortcuts > $temp_file
|
||||
ls_output=$(<$temp_file strip_colors)
|
||||
|
||||
# Compare as fixed strings (F), instead of regex (P)
|
||||
assertIncludes "$ls_output" '[1] a "b"' F
|
||||
assertIncludes "$ls_output" "[2] a 'b'" F
|
||||
assertIncludes "$ls_output" '[3] a [b]' F
|
||||
assertIncludes "$ls_output" '[4] test file' F
|
||||
assertIncludes "$ls_output" '[5] test_file' F
|
||||
|
||||
# Test filenames with single or double quotes escaped
|
||||
assertEquals "$TEST_DIR/a \\\"b\\\"" "$e1"
|
||||
assertEquals "$TEST_DIR/a \\'b\\'" "$e2"
|
||||
assertEquals "$TEST_DIR/a [b]" "$e3"
|
||||
assertEquals "$TEST_DIR/test file" "$e4"
|
||||
assertEquals "$TEST_DIR/test_file" "$e5"
|
||||
}
|
||||
|
||||
# load and run shUnit2
|
||||
source "$scmbDir/test/support/shunit2"
|
||||
|
||||
@@ -13,7 +13,7 @@ export scmbDir="$( cd -P "$( dirname "$0" )" && pwd )/../../.."
|
||||
if [ -n "${ZSH_VERSION:-}" ]; then shell="zsh"; SHUNIT_PARENT=$0; setopt shwordsplit; fi
|
||||
|
||||
# Load test helpers
|
||||
source "$scmbDir/test/support/test_helper"
|
||||
source "$scmbDir/test/support/test_helper.sh"
|
||||
|
||||
# Load functions to test
|
||||
source "$scmbDir/lib/scm_breeze.sh"
|
||||
@@ -95,6 +95,7 @@ test_git_status_shortcuts() {
|
||||
assertNotIncludes "$git_status3" "Untracked files"
|
||||
|
||||
# Run command in shell, load output from temp file into variable
|
||||
# (This is needed so that env variables are exported in the current shell)
|
||||
temp_file=$(mktemp -t scm_breeze.XXXXXXXXXX)
|
||||
git_status_shortcuts > $temp_file
|
||||
git_status=$(<$temp_file strip_colors)
|
||||
|
||||
Reference in New Issue
Block a user