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