1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
|
package TestUtil;
use Exporter 'import';
our @EXPORT = qw(
expected_assert
expected_assert_bin
);
use Test2::V0;
use constant HAS_36 => $] >= 5.036;
sub expected_assert {
my ($expr) = @_;
my $m = match qr/\AAssertion failed \($expr\)/;
if (HAS_36) {
return $m;
}
# Workaround to less than 5.36
if ($expr eq 'true') { $expr = 1 if !HAS_36 }
if ($expr eq 'false') { $expr = "" if !HAS_36 }
my $m1 = match qr/\AAssertion failed \($expr\)/;
my $m2 = match qr/\AAssertion failed \("$expr"\)/;
return in_set($m, $m1, $m2);
}
sub expected_assert_bin {
my ($left, $op, $right) = @_;
my $m = match qr/\AAssertion failed \($left $op $right\)/;
if (HAS_36) {
return $m;
}
# Workaround to less than 5.36
if ($left eq 'true') { $left = 1 if !HAS_36 }
if ($left eq 'false') { $left = "" if !HAS_36 }
my $m1 = match qr/\AAssertion failed \($left $op $right\)/;
my $m2 = match qr/\AAssertion failed \("$left" $op $right\)/;
my $m3 = match qr/\AAssertion failed \("$left" $op "$right"\)/;
return in_set($m, $m1, $m2, $m3);
}
1;
|