work around missing Test::More::note in perl 5.8
authorSteve Hancock <perltidy@users.sourceforge.net>
Fri, 24 Jun 2022 20:03:56 +0000 (13:03 -0700)
committerSteve Hancock <perltidy@users.sourceforge.net>
Fri, 24 Jun 2022 20:03:56 +0000 (13:03 -0700)
t/testwide-passthrough.t
t/testwide-tidy.t

index 643023d393ee12464d6a70e9c28bd3896a2750c4..877409fd99e0db3f50e7ec9809e0533c2bfa158e 100644 (file)
@@ -21,10 +21,25 @@ use Perl::Tidy;
 # through perltidy should read/write identical contents (previously only
 # file test behaved correctly)
 
+# Test::More in perl versions before 5.10 does not have sub note
+# so just skip this test
+
 plan( tests => 6 );
 
 test_all();
 
+sub my_note {
+    my ($msg) = @_;
+
+    # try to work around problem where sub Test::More::note does not exist
+    # in older versions of perl
+    if ($] >= 5.010) {
+       note($msg);
+    }
+    return;
+}
+
+
 sub test_all {
     my $test_file = "$Bin/testwide-passthrough.pl.src";
     test_file2file($test_file);
@@ -40,7 +55,7 @@ sub test_file2file {
     my $source      = $test_file;
     my $destination = $tmp_file->filename();
 
-    note("Testing file2file: '$source' => '$destination'\n");
+    my_note("Testing file2file: '$source' => '$destination'\n");
 
     my $tidyresult = Perl::Tidy::perltidy(
         argv        => '-utf8 -npro',
@@ -54,7 +69,7 @@ sub test_file2file {
 
     my $source_hex      = unpack( 'H*', $source_str );
     my $destination_hex = unpack( 'H*', $destination_str );
-    note("Comparing contents:\n  $source_hex\n  $destination_hex\n");
+    my_note("Comparing contents:\n  $source_hex\n  $destination_hex\n");
 
     ok( $source_hex eq $destination_hex, 'file content compare' );
 }
@@ -65,7 +80,7 @@ sub test_scalar2scalar {
     my $source = slurp_raw($testfile);
     my $destination;
 
-    note("Testing scalar2scalar\n");
+    my_note("Testing scalar2scalar\n");
 
     my $tidyresult = Perl::Tidy::perltidy(
         argv        => '-utf8 -eos -npro',
@@ -77,7 +92,7 @@ sub test_scalar2scalar {
     my $source_hex      = unpack( 'H*', $source );
     my $destination_hex = unpack( 'H*', $destination );
 
-    note("Comparing contents:\n  $source_hex\n  $destination_hex\n");
+    my_note("Comparing contents:\n  $source_hex\n  $destination_hex\n");
     ok( $source_hex eq $destination_hex, 'scalar content compare' );
 }
 
@@ -87,7 +102,7 @@ sub test_scalararray2scalararray {
     my $source      = [ lines_raw($testfile) ];
     my $destination = [];
 
-    note("Testing scalararray2scalararray\n");
+    my_note("Testing scalararray2scalararray\n");
 
     my $tidyresult = Perl::Tidy::perltidy(
         argv        => '-utf8 -eos -npro',
@@ -102,7 +117,7 @@ sub test_scalararray2scalararray {
     my $source_hex      = unpack( 'H*', $source_str );
     my $destination_hex = unpack( 'H*', $destination_str );
 
-    note("Comparing contents:\n  $source_hex\n  $destination_hex\n");
+    my_note("Comparing contents:\n  $source_hex\n  $destination_hex\n");
     ok( $source_hex eq $destination_hex, 'scalararray content compare' );
 }
 
index 1dd12dc9d4419bcd63292b3956902af58cb4c2a0..13ba6405509a63a4d4bd2cbe297afe3f9e0d1609 100644 (file)
@@ -23,6 +23,17 @@ plan( tests => 6 );
 
 test_all();
 
+sub my_note {
+    my ($msg) = @_;
+
+    # work around problem where sub Test::More::note does not exist
+    # in older versions of perl
+    if ($] >= 5.010) {
+       note($msg);
+    }
+    return;
+}
+
 sub test_all {
     my $test_file = "$Bin/testwide-tidy.pl.src";
     my $tidy_file = "$Bin/testwide-tidy.pl.srctdy";
@@ -42,7 +53,7 @@ sub test_file2file {
     my $source      = $test_file;
     my $destination = $tmp_file->filename();
 
-    note("Testing file2file: '$source' => '$destination'\n");
+    my_note("Testing file2file: '$source' => '$destination'\n");
 
     my $tidyresult = Perl::Tidy::perltidy(
         argv        => '-utf8 -npro',
@@ -54,7 +65,7 @@ sub test_file2file {
     my $destination_str = slurp_raw($destination);
     my $destination_hex = unpack( 'H*', $destination_str );
 
-    note("Comparing contents:\n  $tidy_hex\n  $destination_hex\n");
+    my_note("Comparing contents:\n  $tidy_hex\n  $destination_hex\n");
     ok($tidy_hex eq $destination_hex, 'file content compare');
 
 }
@@ -67,7 +78,7 @@ sub test_scalar2scalar {
     my $source = slurp_raw($test_file);
     my $destination;
 
-    note("Testing scalar2scalar\n");
+    my_note("Testing scalar2scalar\n");
 
     my $tidyresult = Perl::Tidy::perltidy(
         argv        => '-utf8 -eos -npro',
@@ -78,7 +89,7 @@ sub test_scalar2scalar {
 
     my $destination_hex = unpack( 'H*', $destination );
 
-    note("Comparing contents:\n  $tidy_hex\n  $destination_hex\n");
+    my_note("Comparing contents:\n  $tidy_hex\n  $destination_hex\n");
     ok($tidy_hex eq $destination_hex, 'scalar content compare');
 
 }
@@ -91,7 +102,7 @@ sub test_scalararray2scalararray {
     my $source      = [ lines_raw($test_file) ];
     my $destination = [];
 
-    note("Testing scalararray2scalararray\n");
+    my_note("Testing scalararray2scalararray\n");
 
     my $tidyresult = Perl::Tidy::perltidy(
         argv        => '-utf8 -eos -npro',
@@ -103,7 +114,7 @@ sub test_scalararray2scalararray {
     my $destination_str = join( '', @$destination );
     my $destination_hex = unpack( 'H*', $destination_str );
 
-    note("Comparing contents:\n  $tidy_hex\n  $destination_hex\n");
+    my_note("Comparing contents:\n  $tidy_hex\n  $destination_hex\n");
     ok($tidy_hex eq $destination_hex, 'scalararray content compare');
 }