]> git.vpit.fr Git - perl/modules/Scope-Upper.git/blobdiff - t/lib/Scope/Upper/TestGenerator.pm
Silence experimental warnings on perl 5.17.11+ for given/when in tests
[perl/modules/Scope-Upper.git] / t / lib / Scope / Upper / TestGenerator.pm
index 8415632cc349a3a6859d53572f2f0ba3fe7f9d27..b4f6e1b6762d26e8aa179c468adbf54da8e70b6f 100644 (file)
@@ -32,16 +32,48 @@ my @blocks = (
  [ 'eval q[',   '];' ],
 );
 
+push @blocks, [ 'given (1) {', '}' ] if "$]" >= 5.010_001;
+
+my %exports = (
+ verbose_is => \&verbose_is,
+);
+
 sub import {
+ if ("$]" >= 5.017_011) {
+  require warnings;
+  warnings->unimport('experimental::smartmatch');
+ }
+
  if ("$]" >= 5.010_001) {
-  push @blocks, [ 'given (1) {', '}' ];
   require feature;
   feature->import('switch');
  }
+
+ my $pkg = caller;
+ while (my ($name, $code) = each %exports) {
+  no strict 'refs';
+  *{$pkg.'::'.$name} = $code;
+ }
 }
 
 @blocks = map [ map "$_\n", @$_ ], @blocks;
 
+sub verbose_is ($$;$) {
+ my ($a, $b, $desc) = @_;
+
+ if (defined $::testcase
+      and (defined $b) ? (not defined $a or $a ne $b) : defined $a) {
+  Test::Leaner::diag(<<DIAG);
+=== This testcase failed ===
+$::testcase
+==== vvvvv Errors vvvvvv ===
+DIAG
+  undef $::testcase;
+ }
+
+ Test::Leaner::is($a, $b, $desc);
+}
+
 sub _block {
  my ($height, $level, $i) = @_;
  my $j = $height - $i;