oh-my-fish/plugins/fish-spec/expect.fish
Jorge Bucaran 63fd25dacb ❯❯❯ Complete overhaul of brand new Oh-My-Fish test framework.
+ Add documentation and examples.
+ Add new functions to interact with the framework:
  + spec.eval - eval a function by name and echo its description field
  + spec.functions - prints functions currently in scope that match the key glob
  + spec.log - log a message / test result
  + spec.run - run suite of tests
+ Rename list.erase to erase.
2015-01-14 02:22:07 +09:00

49 lines
1.3 KiB
Fish

# NAME
# expect - assert a list of expected values match an actual value.
#
# SYNOPSIS
# expect <expected>...
# <condition>
# --to-equal <actual> value equals <expected> value
# --to-contain <actual> value exists in <expected> list
# --to-no-contain <actual> value does not exist in <expected> list
# <actual>
#
# EXAMPLE
# import plugins/fish-spec
#
# function describe_my_test
# function it_does_my_task
# set -l result (my_task $data)
# expect $result --to-equal 0
# end
# end
# spec.run
#/
function expect
set -l expected $argv[1..-3]
set -l condition $argv[-2]
set -l actual $argv[-1]
set -l result 0
# Test conditions and save success/fail $status to return later.
switch $condition
case --to-eq\*
test "$expected" = "$actual"
case --to-contain
set actual_text "To contain"
contains -- "$actual" $expected
case --to-not-contain
set actual_text "To not contain"
not contains -- "$actual" $expected
end
set result $status
if [ $result -eq 0 ]
spec.log --ok
else
spec.log --fail red \n"Expected" yellow "$expected" \
red \n(echo $condition | tr "-" " " \
| cut -c 3-) yellow "$actual"
end
return $result
end