mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-26 12:53:13 +00:00
add more alias unit tests
A recent regression to the `alias` command points out the need for more unit tests of its behavior. I also decided to use it as an opportunity to normalize the output of just `alias` to list aliases.
This commit is contained in:
parent
98449fec51
commit
f2c8e73891
4 changed files with 17 additions and 5 deletions
|
@ -17,9 +17,11 @@ function alias --description 'Creates a function wrapping a command'
|
||||||
if not set -q argv[1]
|
if not set -q argv[1]
|
||||||
# Print the known aliases.
|
# Print the known aliases.
|
||||||
for func in (functions -n)
|
for func in (functions -n)
|
||||||
set -l output (functions $func | string match -r -- "function .* --description '(alias .*)'" | string split \n)
|
set -l output (functions $func | string match -r -- "^function .* --description 'alias (.*)'")
|
||||||
set -q output[2]
|
if set -q output[2]
|
||||||
and echo $output[2]
|
set output (string replace -r '^'$func'[= ]' '' -- $output[2])
|
||||||
|
echo alias $func (string escape -- $output[1])
|
||||||
|
end
|
||||||
end
|
end
|
||||||
return 0
|
return 0
|
||||||
else if not set -q argv[2]
|
else if not set -q argv[2]
|
||||||
|
|
|
@ -5,3 +5,10 @@ function foo
|
||||||
end
|
end
|
||||||
alias my_alias "foo; and echo foo ran"
|
alias my_alias "foo; and echo foo ran"
|
||||||
my_alias
|
my_alias
|
||||||
|
|
||||||
|
alias a-2='echo "hello there"'
|
||||||
|
|
||||||
|
echo '# bare `alias` should list the aliases we have created and nothing else'
|
||||||
|
# We have to exclude two aliases because they're an artifact of the unit test
|
||||||
|
# framework and we can't predict the definition.
|
||||||
|
alias | grep -Ev '^alias (fish_indent|fish_key_reader) '
|
||||||
|
|
|
@ -1,2 +1,5 @@
|
||||||
ran foo
|
ran foo
|
||||||
foo ran
|
foo ran
|
||||||
|
# bare `alias` should list the aliases we have created and nothing else
|
||||||
|
alias a-2 'echo "hello there"'
|
||||||
|
alias my_alias 'foo; and echo foo ran'
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#
|
#
|
||||||
#Test aliases, loops, conditionals and some basic elements
|
#Test function, loops, conditionals and some basic elements
|
||||||
#
|
#
|
||||||
|
|
||||||
for i in 1 2 #Comment on same line as command
|
for i in 1 2 #Comment on same line as command
|
||||||
|
@ -30,7 +30,7 @@ for i in \
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
# Simple alias tests
|
# Simple function tests
|
||||||
|
|
||||||
function foo
|
function foo
|
||||||
echo >../test/temp/fish_foo.txt $argv
|
echo >../test/temp/fish_foo.txt $argv
|
||||||
|
|
Loading…
Reference in a new issue