tide/functions/_tide_sub_test.fish

99 lines
2.5 KiB
Fish
Raw Normal View History

function _tide_sub_test
argparse 'h/help' 'v/verbose' 'a/all' 'i/install' -- $argv
2020-05-10 01:38:07 +03:00
if set -q _flag_help
_help
return
2020-05-05 00:22:08 +03:00
end
if set -q _flag_install
# Install fisher and fishtape for testing
2020-07-14 17:47:15 +03:00
curl git.io/fisher --create-dirs -sLo $__fish_config_dir/functions/fisher.fish
fisher add jorgebucaran/fishtape
return
end
if not functions -q fishtape
set -l b (set_color -o)
set -l n (set_color normal)
printf '%s' $b'fishtape'$n' must be installed to to run Tide\'s test suite. You can install it with'$b' tide test -i'$n
return
end
set -lx TERM xterm # Necessary for testing purposes, ensures color codes are printed
2020-07-11 06:07:00 +03:00
set -l testsDir "$_tide_dir/tests"
2020-05-06 19:42:52 +03:00
2020-05-19 06:03:25 +03:00
set -l pending '/tmp/tide_test'
set -l failed '/tmp/tide_test_failed'
set -l passed '/tmp/tide_test_passed'
2020-05-10 01:38:07 +03:00
2020-07-01 03:34:57 +03:00
set -l returnStatement 0
2020-05-10 01:38:07 +03:00
if set -q _flag_all
set argv (basename -s '.fish' $testsDir/*)
end
for test in $argv
fishtape "$testsDir/$test.fish" >$pending
if test $status -eq 0
if set -q _flag_verbose
cat $pending >>$passed
else
2020-07-12 16:42:49 +03:00
printf '%s\n' "(✔) $test" >>$passed
2020-05-10 01:38:07 +03:00
end
else
cat $pending >>$failed
end
2020-05-06 19:42:52 +03:00
end
2020-05-10 01:38:07 +03:00
if test -e $failed
2020-05-20 00:10:19 +03:00
printf '%s\n' '--------FAILED--------'
2020-05-10 01:38:07 +03:00
cat $failed
rm $failed
2020-07-01 03:34:57 +03:00
set returnStatement 1
2020-05-10 01:38:07 +03:00
end
2020-07-11 06:07:00 +03:00
if test -e $passed
printf '%s\n' '--------PASSED--------'
cat $passed
rm $passed
end
2020-07-01 03:34:57 +03:00
2020-05-10 01:38:07 +03:00
if test -e $pending
rm $pending
end
2020-07-01 03:34:57 +03:00
return $returnStatement
2020-05-10 01:38:07 +03:00
end
function _help
set -l b (set_color -o)
set -l n (set_color normal)
2020-05-20 20:39:44 +03:00
set -l g (set_color $_tide_color_green)
2020-05-10 01:38:07 +03:00
set -l optionList \
'v or --verbose' \
'a or --all' \
'h or --help' \
'i or --install'
2020-05-10 01:38:07 +03:00
set -l descriptionList \
'display test output even if passed' \
'run all available tests' \
'print this help message' \
'install fisher and fishtape test dependencies'
2020-05-10 01:38:07 +03:00
printf '%s\n' 'Usage: '$g'tide test '$n'[options] '$b'[TESTS...]'$n
2020-05-20 00:10:19 +03:00
printf '%s\n'
printf '%s\n' 'Options:'
printf '%s\n'
2020-05-10 01:38:07 +03:00
for option in $optionList
2020-05-20 00:10:19 +03:00
printf '%s' ' -'$option
printf '%b' '\r'
_tide_cursor_right 20
2020-05-10 01:38:07 +03:00
set -l descriptionIndex (contains -i $option $optionList)
2020-05-20 00:10:19 +03:00
printf '%s\n' $descriptionList[$descriptionIndex]
2020-05-10 01:38:07 +03:00
end
2020-05-05 00:22:08 +03:00
end