From 5c06e68115ba4a48a24ac2ba7613da6c1fe96bca Mon Sep 17 00:00:00 2001 From: Aaron Gyes Date: Thu, 19 Sep 2019 14:24:46 -0700 Subject: [PATCH] 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. --- tests/test.fish | 12 ++++++------ tests/test_util.fish | 23 +++++++++++++++++++++++ 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/tests/test.fish b/tests/test.fish index 40a145172..fc29fb4d2 100644 --- a/tests/test.fish +++ b/tests/test.fish @@ -34,12 +34,12 @@ function test_in_file set -l base (basename $file .in) echo -n "Testing file $file ... " - set starttime (date +%s) + set starttime (timestamp) ../test/root/bin/fish <$file >$base.tmp.out 2>$base.tmp.err set -l exit_status $status set -l res ok - set test_duration (math (date +%s) - $starttime) + set test_duration (delta $starttime) diff $base.tmp.out $base.out >/dev/null set -l out_status $status @@ -47,7 +47,7 @@ function test_in_file set -l err_status $status 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 rm -f $base.tmp.{err,out} return 0 @@ -74,13 +74,13 @@ set -g python (__fish_anypython) function test_littlecheck_file set -l file $argv[1] echo -n "Testing file $file ... " - set starttime (date +%s) + set starttime (timestamp) $python ../littlecheck.py -s fish=../test/root/bin/fish $file set -l exit_status $status set -l res ok - set test_duration (math (date +%s) - $starttime) + set test_duration (delta $starttime) if test $exit_status -eq 0 - say green "ok ($test_duration sec)" + say green "ok ($test_duration $unit)" end return $exit_status end diff --git a/tests/test_util.fish b/tests/test_util.fish index a23d46ca5..a4a2e400f 100644 --- a/tests/test_util.fish +++ b/tests/test_util.fish @@ -133,3 +133,26 @@ function colordiff -d 'Colored diff output for unified diffs' 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