-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
63 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
function unmock -a cmd -d "Destroy an existing mock" | ||
if test (count $argv) -lt 1 | ||
echo " | ||
Usage | ||
\$ unmock <command> | ||
Arguments | ||
command The command you would like to unmock | ||
Examples | ||
\$ unmock git # The original git command can now be used | ||
" | ||
return 0 | ||
end | ||
|
||
functions -e $cmd | ||
set -l mocked_args "_mocked_"$cmd"_args" | ||
functions -e "mocked_"$cmd"_fn_"{$$mocked_args} | ||
set -e $mocked_args | ||
set _mocked (string match -v $cmd $_mocked) | ||
return 0 | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,92 +1,84 @@ | ||
function setup | ||
set root (dirname (status -f)) | ||
source $root/mock.fish | ||
source $root/functions/mock.fish | ||
end | ||
|
||
test "$TESTNAME It should be able to mock with exit success" | ||
test "$TESTNAME - It should be able to mock with exit success" | ||
(mock ls \*; and ls) $status -eq 0 | ||
end | ||
|
||
test "$TESTNAME It should be able to non-wildcard mock with exit success" | ||
test "$TESTNAME - It should be able to non-wildcard mock with exit success" | ||
(mock ls a; and ls a) $status -eq 0 | ||
end | ||
|
||
test "$TESTNAME It should be able to mock with fail status" | ||
test "$TESTNAME - It should be able to mock with fail status" | ||
(mock ls \* 1; and ls) $status -eq 1 | ||
end | ||
|
||
test "$TESTNAME It should be able to non-wildcard mock with fail status" | ||
test "$TESTNAME - It should be able to non-wildcard mock with fail status" | ||
(mock ls a 1; and ls a) $status -eq 1 | ||
end | ||
|
||
test "$TESTNAME It should be able to mock with function body" | ||
test "$TESTNAME - It should be able to mock with function body" | ||
hello = (mock ls \* 0 "echo hello"; and ls ) | ||
end | ||
|
||
test "$TESTNAME It should be able to non-wildcard mock with function body" | ||
test "$TESTNAME - It should be able to non-wildcard mock with function body" | ||
hello = (mock ls a 0 "echo hello"; and ls a ) | ||
end | ||
|
||
test "$TESTNAME It should be able to use argument" | ||
test "$TESTNAME - It should be able to use argument" | ||
"hello joe" = (mock ls \* 0 "echo hello \$args"; and ls joe ) | ||
end | ||
|
||
test "$TESTNAME It should be able to use argument in non-wildcard mock" | ||
test "$TESTNAME - It should be able to use argument in non-wildcard mock" | ||
"hello joe" = (mock ls a 0 "echo hello \$args"; and ls a joe ) | ||
end | ||
|
||
test "$TESTNAME It should be able to use some arguments" | ||
test "$TESTNAME - It should be able to use some arguments" | ||
"hello joe" = (mock ls \* 0 "echo hello \$args[1]"; and ls joe mike ) | ||
end | ||
|
||
test "$TESTNAME It should be able to use some arguments in non-wildcard mock" | ||
test "$TESTNAME - It should be able to use some arguments in non-wildcard mock" | ||
"hello joe" = (mock ls a 0 "echo hello \$args[1]"; and ls a joe mike ) | ||
end | ||
|
||
test "$TESTNAME It should be able to use multiple arguments" | ||
test "$TESTNAME - It should be able to use multiple arguments" | ||
"hello joe and mike" = (mock ls \* 0 "echo hello \$args[1] and \$args[2]"; and ls joe mike ) | ||
end | ||
|
||
test "$TESTNAME It should be able to use multiple arguments in non-wildcard mock" | ||
test "$TESTNAME - It should be able to use multiple arguments in non-wildcard mock" | ||
"hello joe and mike" = (mock ls a 0 "echo hello \$args[1] and \$args[2]"; and ls a joe mike ) | ||
end | ||
|
||
test "$TESTNAME It should be able to use nested functions" | ||
test "$TESTNAME - It should be able to use nested functions" | ||
"1 2 3 4 5" = (mock ls \* 0 "echo (seq 5)"; and ls ) | ||
end | ||
|
||
test "$TESTNAME It should be able to use nested functions in non-wildcard mock" | ||
test "$TESTNAME - It should be able to use nested functions in non-wildcard mock" | ||
"1 2 3 4 5" = (mock ls a 0 "echo (seq 5)"; and ls a ) | ||
end | ||
|
||
test "$TESTNAME It should be able to use nested functions with arguments" | ||
test "$TESTNAME - It should be able to use nested functions with arguments" | ||
"1 2 3 4 5" = (mock ls \* 0 "echo (seq \$args)"; and ls 5) | ||
end | ||
|
||
test "$TESTNAME It should be able to use nested functions in non-wildcard mock with arguments" | ||
test "$TESTNAME - It should be able to use nested functions in non-wildcard mock with arguments" | ||
"1 2 3 4 5" = (mock ls a 0 "echo (seq \$args)"; and ls a 5) | ||
end | ||
|
||
test "$TESTNAME It should not mock blacklisted elements 1" | ||
test "$TESTNAME - It should not mock blacklisted elements 1" | ||
(mock builtin \*) = "The function \"builtin\" is reserved and therefore cannot be mocked." -a $status -eq 1 | ||
end | ||
|
||
test "$TESTNAME It should not mock blacklisted elements 2" | ||
test "$TESTNAME - It should not mock blacklisted elements 2" | ||
(mock functions \*) = "The function \"functions\" is reserved and therefore cannot be mocked." -a $status -eq 1 | ||
end | ||
|
||
test "$TESTNAME It should not mock blacklisted elements 3" | ||
test "$TESTNAME - It should not mock blacklisted elements 3" | ||
(mock eval \*) = "The function \"eval\" is reserved and therefore cannot be mocked." -a $status -eq 1 | ||
end | ||
|
||
test "$TESTNAME It should not mock blacklisted elements 4" | ||
test "$TESTNAME - It should not mock blacklisted elements 4" | ||
(mock "[" \*) = "The function \"[\" is reserved and therefore cannot be mocked." -a $status -eq 1 | ||
end | ||
|
||
test "$TESTNAME Unmock previously created mock" | ||
"hello joe" = (mock echo \* 0 "echo fail"; and unmock echo; and echo "hello joe") | ||
end | ||
|
||
test "$TESTNAME Unmock previously created mock with non-wildstar" | ||
"hi" = (mock echo hi 0 "echo fail"; and unmock echo; and echo hi) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
function setup | ||
set root (dirname (status -f)) | ||
source $root/functions/mock.fish | ||
source $root/functions/unmock.fish | ||
end | ||
|
||
test "$TESTNAME - It should unmock a previously created mock" | ||
"hello joe" = (mock echo \* 0 "echo fail"; and unmock echo; and echo "hello joe") | ||
end | ||
|
||
test "$TESTNAME - It should unmock a previously created mock with non-wildcard" | ||
"hi" = (mock echo hi 0 "echo fail"; and unmock echo; and echo hi) | ||
end |