Skip to content

Commit

Permalink
driver: Handle aliases that begin with a '+'
Browse files Browse the repository at this point in the history
Merge remote-tracking branch 'upstream/pr/395'

* upstream/pr/395:
  tests: Add a regression test for issue #392 (aliases beginning with a '+' are lost).
  tests: Move some code in preparation for next commit. No functional change.
  driver: Don't undefine aliases that begin with a '+', to workaround an upstream bug.
  • Loading branch information
danielshahaf committed Dec 3, 2016
2 parents 8d5afe4 + 5efd062 commit b8fa1b9
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 15 deletions.
38 changes: 25 additions & 13 deletions tests/test-highlighting.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,33 @@
exit 2
}

# Set up results_filter
local results_filter
if [[ $QUIET == y ]]; then
if type -w perl >/dev/null; then
results_filter=${0:A:h}/tap-filter
else
echo >&2 "Bail out! quiet mode not supported: perl not found"; exit 2
fi
else
results_filter=cat
fi
[[ -n $results_filter ]] || { echo >&2 "Bail out! BUG setting \$results_filter"; exit 2 }

# Load the main script.
# While here, test that it doesn't eat aliases.
print > >($results_filter | ${0:A:h}/tap-colorizer.zsh) -r -- "# global (driver) tests"
print > >($results_filter | ${0:A:h}/tap-colorizer.zsh) -r -- "1..1"
alias -- +plus=plus
alias -- _other=other
original_alias_dash_L_output="$(alias -L)"
. ${0:h:h}/zsh-syntax-highlighting.zsh
if [[ $original_alias_dash_L_output == $(alias -L) ]]; then
print -r -- "ok 1 # 'alias -- +foo=bar' is preserved"
else
print -r -- "not ok 1 # 'alias -- +foo=bar' is preserved"
exit 1
fi > >($results_filter | ${0:A:h}/tap-colorizer.zsh)

# Overwrite _zsh_highlight_add_highlight so we get the key itself instead of the style
_zsh_highlight_add_highlight()
Expand Down Expand Up @@ -157,19 +182,6 @@ run_test() {
}
}

# Set up results_filter
local results_filter
if [[ $QUIET == y ]]; then
if type -w perl >/dev/null; then
results_filter=${0:A:h}/tap-filter
else
echo >&2 "Bail out! quiet mode not supported: perl not found"; exit 2
fi
else
results_filter=cat
fi
[[ -n $results_filter ]] || { echo >&2 "Bail out! BUG setting \$results_filter"; exit 2 }

# Process each test data file in test data directory.
integer something_failed=0
ZSH_HIGHLIGHT_STYLES=()
Expand Down
8 changes: 6 additions & 2 deletions zsh-syntax-highlighting.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,12 @@
# -------------------------------------------------------------------------------------------------

# First of all, ensure predictable parsing.
zsh_highlight__aliases=`builtin alias -L`
builtin unalias -m '*'
zsh_highlight__aliases=`builtin alias -Lm '[^+]*'`
# In zsh <= 5.2, `alias -L` emits aliases that begin with a plus sign ('alias -- +foo=42')
# them without a '--' guard, so they don't round trip.
#
# Hence, we exclude them from unaliasing:
builtin unalias -m '[^+]*'

# Set $0 to the expected value, regardless of functionargzero.
0=${(%):-%N}
Expand Down

0 comments on commit b8fa1b9

Please sign in to comment.