tide/functions/_tide_sub_test.fish

72 lines
2.0 KiB
Fish
Raw Normal View History

function _tide_sub_test
2020-08-11 19:57:49 +03:00
argparse 'h/help' 'v/verbose' 'a/all' 'i/install' 'c-CI' -- $argv
2020-05-10 01:38:07 +03:00
if set -q _flag_help
_tide_test_help
2020-09-23 23:56:08 +03:00
return 0
else if set -q _flag_install
2020-11-04 22:05:41 +03:00
# Install fisher, spout, and clownfish for testing
fisher install IlanCosman/spout IlanCosman/clownfish
2020-09-23 23:56:08 +03:00
return 0
2020-11-25 03:39:25 +03:00
else if not functions --query spout mock
set -l b (set_color -o; or echo)
set -l n (set_color normal; or echo)
2020-09-24 02:45:37 +03:00
printf '%s\n' $b'spout'$n' and'$b' clownfish'$n' must be installed to to run Tide\'s test suite. You can install them with'$b' tide test -i'$n
2020-09-23 23:56:08 +03:00
return 1
end
2020-11-25 01:44:46 +03:00
set -lx TERM xterm # 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
set -q _flag_all && set argv (basename -s '.fish' $testsDir/*.fish)
set -q _flag_CI && set -a argv 'CI/'(basename -s '.fish' $testsDir/CI/*.fish)
2020-05-10 01:38:07 +03:00
2020-07-23 21:33:51 +03:00
if test (count $argv) -lt 1
_tide_test_help
return 1
end
2020-08-11 01:11:02 +03:00
sudo --validate # Cache sudo credentials
2020-05-10 01:38:07 +03:00
2020-11-25 03:39:25 +03:00
set -l pending (mktemp -u)
set -l failed (mktemp -u)
set -l passed (mktemp -u)
2020-08-11 01:11:02 +03:00
for test in $argv
2020-09-13 08:46:32 +03:00
if spout "$testsDir/$test.fish" >$pending
2020-05-10 01:38:07 +03:00
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-07-11 06:07:00 +03:00
if test -e $passed
printf '%s\n' '--------PASSED--------'
cat $passed
rm $passed
end
2020-08-11 01:11:02 +03:00
if test -e $failed
printf '%s\n' '--------FAILED--------'
cat $failed
rm $failed
2020-07-01 03:34:57 +03:00
2020-08-11 01:11:02 +03:00
return 1
2020-05-10 01:38:07 +03:00
end
end
function _tide_test_help
2020-11-25 01:44:46 +03:00
printf '%s\n' \
'Usage: tide test [options] [tests]' \
'' \
'Options:' \
' -v or --verbose print test output even if passed' \
' -a or --all run all available tests' \
' -h or --help print this help message' \
' -i or --install install testing dependencies' \
' --CI run tests designed for CI'
2020-05-05 00:22:08 +03:00
end