ignore zero values in report conditions
authorMischa POSLAWSKY <perl@shiar.org>
Fri, 9 Dec 2022 20:23:26 +0000 (21:23 +0100)
committerMischa POSLAWSKY <perl@shiar.org>
Mon, 12 Dec 2022 22:56:34 +0000 (23:56 +0100)
Fix empty stats again, with tests for probable future breakage.

barcat
t/t1600-empty_statistics.out [new file with mode: 0644]
t/t1601-integer_statistics.out
t/t1607-unvalued_statistics.out [new file with mode: 0644]

diff --git a/barcat b/barcat
index 655f386aa0dc52633ce9cccf778ddabd789708b5..cb3282eaf4b356e0a7a40aa4b97c59d00660eafd 100755 (executable)
--- a/barcat
+++ b/barcat
@@ -448,7 +448,7 @@ sub varfmt {
                defined && do {
                        $_ = $opt{'value-format'}->($_) if $format;
                        if ($cmd and $op eq ':') {
-                               $_ = varfmt($cmd, $vars);
+                               $_ = !!$_ && varfmt($cmd, $vars);
                        }
                        elsif ($cmd) {
                                eval $cmd;
diff --git a/t/t1600-empty_statistics.out b/t/t1600-empty_statistics.out
new file mode 100644 (file)
index 0000000..5c6a768
--- /dev/null
@@ -0,0 +1,2 @@
+barcat -s input/empty_input.txt
+0 values
index b91b3e80bf4329281ed569011729ddfd6ad18351..a80eec576a9f6b60281497119cd8146c33aae5c6 100644 (file)
@@ -1,2 +1,2 @@
-barcat -sL0 input/seq3.txt
+barcat -s input/seq3.txt | tail -n1
 6 total in 3 values (1 min, 2.00 avg, 3 max)
diff --git a/t/t1607-unvalued_statistics.out b/t/t1607-unvalued_statistics.out
new file mode 100644 (file)
index 0000000..7b5a121
--- /dev/null
@@ -0,0 +1,3 @@
+echo | barcat -s
+
+0 values over 1 lines