From b617c93668b117f605aeaf6a25340dd8abe83b84 Mon Sep 17 00:00:00 2001 From: Niels Thykier Date: Fri, 30 Jun 2017 18:34:14 +0000 Subject: Add simple Test::DH module in the test suite Signed-off-by: Niels Thykier --- t/Test/DH.pm | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 t/Test/DH.pm (limited to 't') diff --git a/t/Test/DH.pm b/t/Test/DH.pm new file mode 100644 index 00000000..832f239f --- /dev/null +++ b/t/Test/DH.pm @@ -0,0 +1,67 @@ +package Test::DH; + +use strict; +use warnings; + +use Test::More; + +use Exporter qw(import); + +use File::Basename qw(dirname); + +my $ROOT_DIR; + +BEGIN { + $ROOT_DIR = dirname(dirname(dirname(__FILE__))); +}; + +use lib "$ROOT_DIR/lib"; + +$ENV{PATH} = "$ROOT_DIR:$ENV{PATH}" if $ENV{PATH} !~ m{\Q$ROOT_DIR\E/?:}; + +use Debian::Debhelper::Dh_Lib; + +our @EXPORT = qw( + each_compat_up_to_and_incl_subtest each_compat_subtest + each_compat_from_and_above_subtest +); + +sub each_compat_up_to_and_incl_subtest($&) { + my ($compat, $code) = @_; + my $low = Debian::Debhelper::Dh_Lib::MIN_COMPAT_LEVEL; + error("compat $compat is no longer support! Min compat $low") + if $compat < $low; + subtest '' => sub { + while ($low <= $compat) { + $code->($low); + ++$low; + } + }; + return; +} + +sub each_compat_from_and_above_subtest($&) { + my ($compat, $code) = @_; + my $lowest = Debian::Debhelper::Dh_Lib::MIN_COMPAT_LEVEL; + my $end = Debian::Debhelper::Dh_Lib::MAX_COMPAT_LEVEL; + if ($lowest > $compat) { + diag("Bumping $compat to $lowest ($compat is no longer supported)"); + $compat = $lowest; + } + error("$compat is from the future! Max known is $end") + if $compat > $end; + subtest '' => sub { + while ($compat <= $end) { + $code->($compat); + ++$compat; + } + }; + return; +} + +sub each_compat_subtest(&) { + unshift(@_, Debian::Debhelper::Dh_Lib::MIN_COMPAT_LEVEL); + goto \&each_compat_from_and_above_subtest; +} + +1; -- cgit v1.2.3