From 40fc64b32dc2a44ed91739f4356172d7cec4f9ed Mon Sep 17 00:00:00 2001 From: Mischa POSLAWSKY Date: Fri, 12 Mar 2021 02:23:07 +0100 Subject: [PATCH] test and warn about invalid marker values --- barcat | 13 ++++++-- t/t1019-invalid_marker.in | 1 + ...test\\_09998\\_b200v\\_c15000\\_0test.out" | 33 +++++++++++++++++++ 3 files changed, 45 insertions(+), 2 deletions(-) create mode 120000 t/t1019-invalid_marker.in create mode 100644 "t/t1019-invalid_marker_--markers=atest\\_09998\\_b200v\\_c15000\\_0test.out" diff --git a/barcat b/barcat index 0fd06e2..63eb3a5 100755 --- a/barcat +++ b/barcat @@ -222,13 +222,22 @@ if ($opt{markers} and $size > 0) { return sum(@order) / @order; } elsif ($func =~ /\A([0-9.]+)v\z/) { + die "Invalid marker $char: percentile $1 out of bounds\n" if $1 > 100; my $index = $#order * $1 / 100; return ($order[$index] + $order[$index + .5]) / 2; } - else { + elsif ($func =~ /\A-?[0-9.]+\z/) { return $func; } - } - $minval; + else { + die "Unknown marker $char: $func\n"; + } + }; + defined $pos or do { + warn $@ if $@; + next; + }; + $pos -= $minval; $pos >= 0 or next; color(36) for $barmark[$pos * $size] = $char; } diff --git a/t/t1019-invalid_marker.in b/t/t1019-invalid_marker.in new file mode 120000 index 0000000..74fd833 --- /dev/null +++ b/t/t1019-invalid_marker.in @@ -0,0 +1 @@ +t1012-unmarked.in \ No newline at end of file diff --git "a/t/t1019-invalid_marker_--markers=atest\\_09998\\_b200v\\_c15000\\_0test.out" "b/t/t1019-invalid_marker_--markers=atest\\_09998\\_b200v\\_c15000\\_0test.out" new file mode 100644 index 0000000..fbcebb5 --- /dev/null +++ "b/t/t1019-invalid_marker_--markers=atest\\_09998\\_b200v\\_c15000\\_0test.out" @@ -0,0 +1,33 @@ +Unknown marker a: test +Invalid marker b: percentile 200 out of bounds +Unknown marker 0: test + 998 --- +1987 ------- +2955 ---------- +3894 -------------- +4794 ----------------- +5646 -------------------- +6442 ----------------------- +7174 ------------------------- +7833 --------------------------- +8415 ----------------------------- +8912 ------------------------------- +9320 --------------------------------- +9636 ---------------------------------- +9855 ----------------------------------0 +9975 ----------------------------------0 +9996 ----------------------------------0 +9917 ----------------------------------0 +9738 ---------------------------------- +9463 --------------------------------- +9093 -------------------------------- +8632 ------------------------------ +8085 ---------------------------- +7457 -------------------------- +6755 ------------------------ +5985 --------------------- +5155 ------------------ +4274 --------------- +3350 ------------ +2392 -------- +1411 ----- -- 2.30.0