[zsh] fix missing history
This commit is contained in:
@@ -10,7 +10,12 @@
|
|||||||
export scmbDir="$(cd -P "$(dirname "$0")" && pwd)/../../.."
|
export scmbDir="$(cd -P "$(dirname "$0")" && pwd)/../../.."
|
||||||
|
|
||||||
# Zsh compatibility
|
# Zsh compatibility
|
||||||
if [ -n "${ZSH_VERSION:-}" ]; then shell="zsh"; SHUNIT_PARENT=$0; setopt shwordsplit; fi
|
if [ -n "${ZSH_VERSION:-}" ]; then
|
||||||
|
shell="zsh"
|
||||||
|
SHUNIT_PARENT=$0
|
||||||
|
setopt shwordsplit
|
||||||
|
setopt append_history
|
||||||
|
fi
|
||||||
|
|
||||||
# Load test helpers
|
# Load test helpers
|
||||||
source "$scmbDir/test/support/test_helper.sh"
|
source "$scmbDir/test/support/test_helper.sh"
|
||||||
@@ -19,7 +24,6 @@ source "$scmbDir/test/support/test_helper.sh"
|
|||||||
source "$scmbDir/lib/scm_breeze.sh"
|
source "$scmbDir/lib/scm_breeze.sh"
|
||||||
source "$scmbDir/lib/git/status_shortcuts.sh"
|
source "$scmbDir/lib/git/status_shortcuts.sh"
|
||||||
|
|
||||||
|
|
||||||
# Setup and tear down
|
# Setup and tear down
|
||||||
#-----------------------------------------------------------------------------
|
#-----------------------------------------------------------------------------
|
||||||
oneTimeSetUp() {
|
oneTimeSetUp() {
|
||||||
@@ -43,7 +47,6 @@ setupTestRepo() {
|
|||||||
git init >/dev/null
|
git init >/dev/null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#-----------------------------------------------------------------------------
|
#-----------------------------------------------------------------------------
|
||||||
# Unit tests
|
# Unit tests
|
||||||
#-----------------------------------------------------------------------------
|
#-----------------------------------------------------------------------------
|
||||||
@@ -52,19 +55,37 @@ test_scmb_expand_args() {
|
|||||||
local e1="one" e2="two" e3="three" e4="four" e5="five" e6="six" e7='$dollar' e8='two words'
|
local e1="one" e2="two" e3="three" e4="four" e5="five" e6="six" e7='$dollar' e8='two words'
|
||||||
local error="Args not expanded correctly"
|
local error="Args not expanded correctly"
|
||||||
assertEquals "$error" 'one three six' \
|
assertEquals "$error" 'one three six' \
|
||||||
"$(eval args="$(scmb_expand_args 1 3 6)"; token_quote "${args[@]}")"
|
"$(
|
||||||
|
eval args="$(scmb_expand_args 1 3 6)"
|
||||||
|
token_quote "${args[@]}"
|
||||||
|
)"
|
||||||
assertEquals "$error" 'one two three five' \
|
assertEquals "$error" 'one two three five' \
|
||||||
"$(eval args="$(scmb_expand_args 1-3 5)"; token_quote "${args[@]}")"
|
"$(
|
||||||
|
eval args="$(scmb_expand_args 1-3 5)"
|
||||||
|
token_quote "${args[@]}"
|
||||||
|
)"
|
||||||
assertEquals "$error" '\$dollar two three four one' \
|
assertEquals "$error" '\$dollar two three four one' \
|
||||||
"$(eval args="$(scmb_expand_args 7 2-4 1)"; token_quote "${args[@]}")"
|
"$(
|
||||||
|
eval args="$(scmb_expand_args 7 2-4 1)"
|
||||||
|
token_quote "${args[@]}"
|
||||||
|
)"
|
||||||
|
|
||||||
# Test that any args with spaces remain quoted
|
# Test that any args with spaces remain quoted
|
||||||
assertEquals "$error" '-m Test\ Commit\ Message one' \
|
assertEquals "$error" '-m Test\ Commit\ Message one' \
|
||||||
"$(eval args="$(scmb_expand_args -m "Test Commit Message" 1)"; token_quote "${args[@]}")"
|
"$(
|
||||||
|
eval args="$(scmb_expand_args -m "Test Commit Message" 1)"
|
||||||
|
token_quote "${args[@]}"
|
||||||
|
)"
|
||||||
assertEquals "$error" '-ma Test\ Commit\ Message Unquoted' \
|
assertEquals "$error" '-ma Test\ Commit\ Message Unquoted' \
|
||||||
"$(eval args="$(scmb_expand_args -ma "Test Commit Message" "Unquoted")"; token_quote "${args[@]}")"
|
"$(
|
||||||
|
eval args="$(scmb_expand_args -ma "Test Commit Message" "Unquoted")"
|
||||||
|
token_quote "${args[@]}"
|
||||||
|
)"
|
||||||
assertEquals "$error" '\$dollar one two\ words' \
|
assertEquals "$error" '\$dollar one two\ words' \
|
||||||
"$(eval args="$(scmb_expand_args 7 1-1 8)"; token_quote "${args[@]}")"
|
"$(
|
||||||
|
eval args="$(scmb_expand_args 7 1-1 8)"
|
||||||
|
token_quote "${args[@]}"
|
||||||
|
)"
|
||||||
|
|
||||||
# Keep this code for use when minimum versions of {ba,z}sh can be increased.
|
# Keep this code for use when minimum versions of {ba,z}sh can be increased.
|
||||||
# See token_quote() source and https://github.com/scmbreeze/scm_breeze/issues/260
|
# See token_quote() source and https://github.com/scmbreeze/scm_breeze/issues/260
|
||||||
@@ -89,14 +110,23 @@ test_scmb_expand_args() {
|
|||||||
test_exec_scmb_expand_args() {
|
test_exec_scmb_expand_args() {
|
||||||
local e1="one" e2="a b c" e3='$dollar' e4="single'quote" e5='double"quote' e6='a(){:;};a&'
|
local e1="one" e2="a b c" e3='$dollar' e4="single'quote" e5='double"quote' e6='a(){:;};a&'
|
||||||
assertEquals "literals with spaces not preserved" 'foo bar\ baz' \
|
assertEquals "literals with spaces not preserved" 'foo bar\ baz' \
|
||||||
"$(eval args="$(scmb_expand_args foo 'bar baz')"; token_quote "${args[@]}")"
|
"$(
|
||||||
|
eval args="$(scmb_expand_args foo 'bar baz')"
|
||||||
|
token_quote "${args[@]}"
|
||||||
|
)"
|
||||||
assertEquals "variables with spaces not preserved" 'one a\ b\ c' \
|
assertEquals "variables with spaces not preserved" 'one a\ b\ c' \
|
||||||
"$(eval args="$(scmb_expand_args 1-2)"; token_quote "${args[@]}")"
|
"$(
|
||||||
|
eval args="$(scmb_expand_args 1-2)"
|
||||||
|
token_quote "${args[@]}"
|
||||||
|
)"
|
||||||
# Expecting text: '$dollar' "single'quote" 'double"quote'
|
# Expecting text: '$dollar' "single'quote" 'double"quote'
|
||||||
# Generate quoted expected string with: token_quote "$(cat)" then copy/paste, ^D
|
# Generate quoted expected string with: token_quote "$(cat)" then copy/paste, ^D
|
||||||
assertEquals "special characters are preserved" \
|
assertEquals "special characters are preserved" \
|
||||||
'\$dollar single\'\''quote double\"quote a\(\)\{:\;\}\;a\&' \
|
'\$dollar single\'\''quote double\"quote a\(\)\{:\;\}\;a\&' \
|
||||||
"$(eval args="$(scmb_expand_args 3-6)"; token_quote "${args[@]}")"
|
"$(
|
||||||
|
eval args="$(scmb_expand_args 3-6)"
|
||||||
|
token_quote "${args[@]}"
|
||||||
|
)"
|
||||||
|
|
||||||
# Keep this code for use when minimum versions of {ba,z}sh can be increased.
|
# Keep this code for use when minimum versions of {ba,z}sh can be increased.
|
||||||
# See token_quote() source and https://github.com/scmbreeze/scm_breeze/issues/260
|
# See token_quote() source and https://github.com/scmbreeze/scm_breeze/issues/260
|
||||||
@@ -202,7 +232,6 @@ test_git_status_produces_relative_paths() {
|
|||||||
assertIncludes "$git_status" "../../../dir2/testfile" || return
|
assertIncludes "$git_status" "../../../dir2/testfile" || return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
test_git_status_shortcuts_merge_conflicts() {
|
test_git_status_shortcuts_merge_conflicts() {
|
||||||
setupTestRepo
|
setupTestRepo
|
||||||
|
|
||||||
@@ -247,7 +276,6 @@ test_git_status_shortcuts_merge_conflicts() {
|
|||||||
assertIncludes "$git_status" "added by us: *\[[0-9]*\] *renamed_file_on_master" || return
|
assertIncludes "$git_status" "added by us: *\[[0-9]*\] *renamed_file_on_master" || return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
test_git_status_shortcuts_max_changes() {
|
test_git_status_shortcuts_max_changes() {
|
||||||
setupTestRepo
|
setupTestRepo
|
||||||
|
|
||||||
@@ -269,7 +297,6 @@ test_git_status_shortcuts_max_changes() {
|
|||||||
export gs_max_changes="20"
|
export gs_max_changes="20"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
test_git_add_shortcuts() {
|
test_git_add_shortcuts() {
|
||||||
setupTestRepo
|
setupTestRepo
|
||||||
|
|
||||||
@@ -294,6 +321,15 @@ test_git_commit_prompt() {
|
|||||||
export HISTFILESIZE=1000
|
export HISTFILESIZE=1000
|
||||||
export HISTSIZE=1000
|
export HISTSIZE=1000
|
||||||
|
|
||||||
|
if [[ $shell == "zsh" ]]; then
|
||||||
|
export SAVEHIST=1000
|
||||||
|
zsh_appendhistory=$( (setopt | grep -q appendhistory) && echo "true")
|
||||||
|
if [ "$zsh_appendhistory" != "true" ]; then
|
||||||
|
setopt appendhistory
|
||||||
|
trap "unsetopt appendhistory" EXIT
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
touch a b c d
|
touch a b c d
|
||||||
git add . >/dev/null
|
git add . >/dev/null
|
||||||
|
|
||||||
@@ -309,6 +345,8 @@ test_git_commit_prompt() {
|
|||||||
|
|
||||||
# Test that history was appended correctly.
|
# Test that history was appended correctly.
|
||||||
if [[ $shell == "zsh" ]]; then
|
if [[ $shell == "zsh" ]]; then
|
||||||
|
setopt
|
||||||
|
cat $HISTFILE
|
||||||
test_history="$(history)"
|
test_history="$(history)"
|
||||||
else
|
else
|
||||||
# Need to load history from $HISTFILE
|
# Need to load history from $HISTFILE
|
||||||
@@ -324,9 +362,10 @@ test_git_commit_prompt_with_append() {
|
|||||||
commit_msg="Updating README, no build please"
|
commit_msg="Updating README, no build please"
|
||||||
|
|
||||||
# Create temporary history file
|
# Create temporary history file
|
||||||
HISTFILE=$(mktemp -t scm_breeze.XXXXXXXXXX)
|
export HISTFILE=$(mktemp -t scm_breeze.XXXXXXXXXX)
|
||||||
HISTFILESIZE=1000
|
export HISTFILESIZE=1000
|
||||||
HISTSIZE=1000
|
export HISTSIZE=1000
|
||||||
|
export SAVEHIST=1000
|
||||||
|
|
||||||
touch a b c
|
touch a b c
|
||||||
git add . >/dev/null
|
git add . >/dev/null
|
||||||
@@ -365,7 +404,5 @@ test_adding_files_with_spaces() {
|
|||||||
assertIncludes "$git_status" "new file: \[1\] \"$test_file"
|
assertIncludes "$git_status" "new file: \[1\] \"$test_file"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# load and run shUnit2
|
# load and run shUnit2
|
||||||
source "$scmbDir/test/support/shunit2"
|
source "$scmbDir/test/support/shunit2"
|
||||||
|
|||||||
Reference in New Issue
Block a user