tests: add a lame gdate-based ms-precision timer if installed

I got tired of seeing ' ... ok (0 sec)' so now with GNU date/gdate
installed there is millisecond output shown. One can get rough
nanoseconds from gdate.
This commit is contained in:
Aaron Gyes 2019-09-19 14:24:46 -07:00
parent 2b7b70a64f
commit 5c06e68115
2 changed files with 29 additions and 6 deletions

View File

@ -34,12 +34,12 @@ function test_in_file
set -l base (basename $file .in) set -l base (basename $file .in)
echo -n "Testing file $file ... " echo -n "Testing file $file ... "
set starttime (date +%s) set starttime (timestamp)
../test/root/bin/fish <$file >$base.tmp.out 2>$base.tmp.err ../test/root/bin/fish <$file >$base.tmp.out 2>$base.tmp.err
set -l exit_status $status set -l exit_status $status
set -l res ok set -l res ok
set test_duration (math (date +%s) - $starttime) set test_duration (delta $starttime)
diff $base.tmp.out $base.out >/dev/null diff $base.tmp.out $base.out >/dev/null
set -l out_status $status set -l out_status $status
@ -47,7 +47,7 @@ function test_in_file
set -l err_status $status set -l err_status $status
if test $out_status -eq 0 -a $err_status -eq 0 -a $exit_status -eq 0 if test $out_status -eq 0 -a $err_status -eq 0 -a $exit_status -eq 0
say green "ok ($test_duration sec)" say green "ok ($test_duration $unit)"
# clean up tmp files # clean up tmp files
rm -f $base.tmp.{err,out} rm -f $base.tmp.{err,out}
return 0 return 0
@ -74,13 +74,13 @@ set -g python (__fish_anypython)
function test_littlecheck_file function test_littlecheck_file
set -l file $argv[1] set -l file $argv[1]
echo -n "Testing file $file ... " echo -n "Testing file $file ... "
set starttime (date +%s) set starttime (timestamp)
$python ../littlecheck.py -s fish=../test/root/bin/fish $file $python ../littlecheck.py -s fish=../test/root/bin/fish $file
set -l exit_status $status set -l exit_status $status
set -l res ok set -l res ok
set test_duration (math (date +%s) - $starttime) set test_duration (delta $starttime)
if test $exit_status -eq 0 if test $exit_status -eq 0
say green "ok ($test_duration sec)" say green "ok ($test_duration $unit)"
end end
return $exit_status return $exit_status
end end

View File

@ -133,3 +133,26 @@ function colordiff -d 'Colored diff output for unified diffs'
end end
end end
end end
# lame timer
for program in {g,}date
if $program --version
set milli $program
set unit ms
break
else
set unit sec
end
end
function timestamp -V milli
set -q milli[1]
and $milli +%s%3N
or date +%s
end
function delta -V milli
set -q milli[1]
and math "( "($milli +%s%3N)" - $argv[1])"
or math (date +%s) - $starttime
end