From f2c8e738917915f81014963a677a1f8d61823cb8 Mon Sep 17 00:00:00 2001 From: Kurtis Rader Date: Sat, 15 Jul 2017 17:36:36 -0700 Subject: [PATCH] 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. --- share/functions/alias.fish | 8 +++++--- tests/alias.in | 7 +++++++ tests/alias.out | 3 +++ tests/test1.in | 4 ++-- 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/share/functions/alias.fish b/share/functions/alias.fish index 318009f14..51c6055a9 100644 --- a/share/functions/alias.fish +++ b/share/functions/alias.fish @@ -17,9 +17,11 @@ function alias --description 'Creates a function wrapping a command' if not set -q argv[1] # Print the known aliases. for func in (functions -n) - set -l output (functions $func | string match -r -- "function .* --description '(alias .*)'" | string split \n) - set -q output[2] - and echo $output[2] + set -l output (functions $func | string match -r -- "^function .* --description 'alias (.*)'") + if set -q output[2] + set output (string replace -r '^'$func'[= ]' '' -- $output[2]) + echo alias $func (string escape -- $output[1]) + end end return 0 else if not set -q argv[2] diff --git a/tests/alias.in b/tests/alias.in index b3423b56f..6276a5f96 100644 --- a/tests/alias.in +++ b/tests/alias.in @@ -5,3 +5,10 @@ function foo end alias my_alias "foo; and echo foo ran" 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) ' diff --git a/tests/alias.out b/tests/alias.out index b07ca34b6..5da9852d3 100644 --- a/tests/alias.out +++ b/tests/alias.out @@ -1,2 +1,5 @@ ran foo 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' diff --git a/tests/test1.in b/tests/test1.in index 86f7999c9..47ff18809 100644 --- a/tests/test1.in +++ b/tests/test1.in @@ -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 @@ -30,7 +30,7 @@ for i in \ end -# Simple alias tests +# Simple function tests function foo echo >../test/temp/fish_foo.txt $argv