2016-06-04 10:05:13 +08:00
|
|
|
# vim: set ts=4 sw=4 tw=100 et:
|
2014-09-24 07:29:36 +08:00
|
|
|
# Utilities for the test runners
|
|
|
|
|
|
|
|
function die
|
2014-10-28 10:42:19 +08:00
|
|
|
set -q argv[1]; and echo $argv[1] >&2
|
2014-09-24 07:29:36 +08:00
|
|
|
exit 1
|
|
|
|
end
|
|
|
|
|
2021-03-16 01:42:53 +08:00
|
|
|
# $suppress_color is set by `test_driver.sh` (via import of exported variables)
|
2014-10-28 10:42:19 +08:00
|
|
|
function say -V suppress_color
|
2014-09-24 07:29:36 +08:00
|
|
|
set -l color_flags
|
2014-09-24 13:50:28 +08:00
|
|
|
set -l suppress_newline
|
2014-09-24 07:29:36 +08:00
|
|
|
while set -q argv[1]
|
|
|
|
switch $argv[1]
|
|
|
|
case -b -o -u
|
|
|
|
set color_flags $color_flags $argv[1]
|
2014-09-24 13:50:28 +08:00
|
|
|
case -n
|
|
|
|
set suppress_newline 1
|
2014-09-24 07:29:36 +08:00
|
|
|
case --
|
|
|
|
set -e argv[1]
|
|
|
|
break
|
|
|
|
case -\*
|
2014-09-24 13:50:28 +08:00
|
|
|
continue
|
2014-09-24 07:29:36 +08:00
|
|
|
case \*
|
|
|
|
break
|
|
|
|
end
|
|
|
|
set -e argv[1]
|
|
|
|
end
|
|
|
|
|
2014-10-28 10:42:19 +08:00
|
|
|
if not set -q argv[2]
|
|
|
|
echo 'usage: say [flags] color string [string...]' >&2
|
2014-09-24 07:29:36 +08:00
|
|
|
return 1
|
|
|
|
end
|
|
|
|
|
2019-05-21 03:07:37 +08:00
|
|
|
if begin
|
|
|
|
test -n "$suppress_color"; or set_color $color_flags $argv[1]
|
|
|
|
end
|
2014-10-28 10:42:19 +08:00
|
|
|
printf '%s' $argv[2..-1]
|
2016-11-12 11:07:52 +08:00
|
|
|
test -z "$suppress_color"; and set_color normal
|
2014-09-24 13:50:28 +08:00
|
|
|
if test -z "$suppress_newline"
|
|
|
|
echo
|
|
|
|
end
|
2014-09-24 07:29:36 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-09-20 05:24:46 +08:00
|
|
|
# lame timer
|
|
|
|
for program in {g,}date
|
2019-09-22 09:42:55 +08:00
|
|
|
if command -q $program && $program --version 1>/dev/null 2>/dev/null
|
2019-10-19 20:25:03 +08:00
|
|
|
set -g milli $program
|
2020-05-15 13:56:06 +08:00
|
|
|
set -g unit ms
|
2019-09-20 05:24:46 +08:00
|
|
|
break
|
|
|
|
else
|
2020-05-15 13:56:06 +08:00
|
|
|
set -g unit sec
|
2019-09-20 05:24:46 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-09-20 06:06:51 +08:00
|
|
|
function timestamp
|
2019-09-20 05:24:46 +08:00
|
|
|
set -q milli[1]
|
|
|
|
and $milli +%s%3N
|
|
|
|
or date +%s
|
|
|
|
end
|
|
|
|
|
2019-09-20 06:06:51 +08:00
|
|
|
function delta
|
2019-09-20 05:24:46 +08:00
|
|
|
set -q milli[1]
|
|
|
|
and math "( "($milli +%s%3N)" - $argv[1])"
|
2019-10-19 20:25:03 +08:00
|
|
|
or math (date +%s) - $argv[1]
|
2019-09-20 05:24:46 +08:00
|
|
|
end
|