mirror of
https://github.com/oh-my-fish/oh-my-fish
synced 2024-11-17 09:26:08 +00:00
63fd25dacb
+ 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.
49 lines
1.3 KiB
Fish
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
|