From 6c4255bdc7e2117cb32a63c7b2ecf72c6cc105e6 Mon Sep 17 00:00:00 2001 From: Ed J Date: Thu, 12 Sep 2024 05:19:01 +0100 Subject: [PATCH] better column-quantity checking without warnings --- lib/PDL/Graphics/Simple.pm | 4 ++-- t/simple.t | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/PDL/Graphics/Simple.pm b/lib/PDL/Graphics/Simple.pm index 636c887..f7525f6 100644 --- a/lib/PDL/Graphics/Simple.pm +++ b/lib/PDL/Graphics/Simple.pm @@ -964,8 +964,8 @@ sub _translate_plot { ############################## # Now check options - barf "plot style $ptn requires $pt->{args}[0] or $pt->{args}[1] columns; you gave ".(0+@args) - if @args != $pt->{args}[0] and @args != $pt->{args}[1]; + barf "plot style $ptn requires ".join(" or ", @{$pt->{args}})." columns; you gave ".(0+@args) + if !grep @args == $_, @{$pt->{args}}; if ($ptn eq 'contours' and @args == 1) { my $cntr_cnt = 9; diff --git a/t/simple.t b/t/simple.t index c52e6b8..c7ab511 100644 --- a/t/simple.t +++ b/t/simple.t @@ -55,8 +55,13 @@ for my $bounds (5, {}, [1..3], [1,1]) { eval { PDL::Graphics::Simple::_translate_plot(undef, undef, pdl(1), {yrange => $bounds}) }; like $@, qr/must be a 2-element ARRAY/; } +{ my @w; local $SIG{__WARN__} = sub {push @w, @_}; eval { PDL::Graphics::Simple::_translate_plot(undef, undef, with=>'lines', pdl(1), pdl(1), pdl(1)) }; like $@, qr/requires 1 or 2 columns/; +eval { PDL::Graphics::Simple::_translate_plot(undef, undef, with=>'polylines', pdl(1)) }; +like $@, qr/requires 2 columns/; +is "@w", "", "no warnings"; +} ############################## # Try the simple engine and convenience interfaces...