This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
t/re/regexp_unicode_prop.t: Avoid a TEST crash if failure
[perl5.git] / t / re / regexp_unicode_prop.t
index 5fbcf2f..2d5b36c 100644 (file)
@@ -8,6 +8,9 @@ use strict;
 use warnings;
 use 5.010;
 
+my @warnings;
+local $SIG {__WARN__} = sub {push @warnings, "@_"};
+
 BEGIN {
     chdir 't' if -d 't';
     require './test.pl';
@@ -16,6 +19,27 @@ BEGIN {
 
 sub run_tests;
 
+sub get_str_name($) {
+    my $char = shift;
+
+    my ($str, $name);
+
+    if ($char =~ /^\\/) {
+        $str  = eval qq ["$char"];
+        $name =      qq ["$char"];
+    }
+    elsif ($char =~ /^0x([0-9A-Fa-f]+)$/) {
+        $str  =  chr hex $1;
+        $name = "chr ($char)";
+    }
+    else {
+        $str  =      $char;
+        $name = qq ["$char"];
+    }
+
+    return ($str, $name);
+}
+
 #
 # This is the data to test.
 #
@@ -81,37 +105,37 @@ my @CLASSES = (
 
 );
 
-my @USER_DEFINED_PROPERTIES = (
-   #
-   # User defined properties
-   #
-   InKana1                   => ['\x{3040}', '!\x{303F}'],
-   InKana2                   => ['\x{3040}', '!\x{303F}'],
-   InKana3                   => ['\x{3041}', '!\x{3040}'],
-   InNotKana                 => ['\x{3040}', '!\x{3041}'],
-   InConsonant               => ['d',        '!e'],
-   IsSyriac1                 => ['\x{0712}', '!\x{072F}'],
-   IsSyriac1KanaMark         => ['\x{309A}', '!\x{3090}'],
-   IsSyriac1KanaMark         => ['\x{0730}', '!\x{0712}'],
-   '# User-defined character properties may lack \n at the end',
-   InGreekSmall              => ['\N{GREEK SMALL LETTER PI}',
-                                 '\N{GREEK SMALL LETTER FINAL SIGMA}'],
-   InGreekCapital            => ['\N{GREEK CAPITAL LETTER PI}', '!\x{03A2}'],
-   Dash                      => ['-'],
-   ASCII_Hex_Digit           => ['!-', 'A'],
-   IsAsciiHexAndDash         => ['-', 'A'],
-
-   # This overrides the official one
-   InLatin1                  => ['\x{0100}', '!\x{00FF}'],
-);
-
-my @USER_CASELESS_PROPERTIES = (
-   #
-   # User defined properties which differ depending on /i.  Second entry is
-   # false normally, true under /i
-   #
-   'IsMyUpper'                => ["M", "!m" ],
-);
+    my @USER_DEFINED_PROPERTIES = (
+        #
+        # User defined properties
+        #
+        InKana1                   => ['\x{3040}', '!\x{303F}'],
+        InKana2                   => ['\x{3040}', '!\x{303F}'],
+        InKana3                   => ['\x{3041}', '!\x{3040}'],
+        InNotKana                 => ['\x{3040}', '!\x{3041}'],
+        InConsonant               => ['d',        '!e'],
+        IsSyriac1                 => ['\x{0712}', '!\x{072F}'],
+        IsSyriac1KanaMark         => ['\x{309A}', '!\x{3090}'],
+        IsSyriac1KanaMark         => ['\x{0730}', '!\x{0712}'],
+        '# User-defined character properties may lack \n at the end',
+        InGreekSmall              => ['\N{GREEK SMALL LETTER PI}',
+                                        '\N{GREEK SMALL LETTER FINAL SIGMA}'],
+        InGreekCapital            => ['\N{GREEK CAPITAL LETTER PI}', '!\x{03A2}'],
+        Dash                      => ['-'],
+        ASCII_Hex_Digit           => ['!-', 'A'],
+        IsAsciiHexAndDash         => ['-', 'A'],
+
+        # This overrides the official one
+        InLatin1                  => ['\x{0100}', '!\x{00FF}'],
+    );
+
+    my @USER_CASELESS_PROPERTIES = (
+        #
+        # User defined properties which differ depending on /i.  Second entry
+        # is false normally, true under /i
+        #
+        'IsMyUpper'                => ["M", "!m" ],
+    );
 
 
 #
@@ -178,6 +202,7 @@ $count += 4 * @ILLEGAL_PROPERTIES;
 $count += 4 * grep {length $_ == 1} @ILLEGAL_PROPERTIES;
 $count += 8 * @USER_CASELESS_PROPERTIES;
 $count += 1;    # Test for pkg:IsMyLower
+$count += 1;    # No warnings generated
 
 plan(tests => $count);
 
@@ -188,32 +213,21 @@ sub match {
     $caseless = "" unless defined $caseless;
     $caseless = 'i' if $caseless;
 
-    my ($str, $name);
-
-    if ($char =~ /^\\/) {
-        $str  = eval qq ["$char"];
-        $name =      qq ["$char"];
-    }
-    elsif ($char =~ /^0x([0-9A-Fa-f]+)$/) {
-        $str  =  chr hex $1;
-        $name = "chr ($char)";
-    }
-    else {
-        $str  =      $char;
-        $name = qq ["$char"];
-    }
+    my ($str, $name) = get_str_name($char);
 
     undef $@;
     my $pat = "qr/$match/$caseless";
     my $match_pat = eval $pat;
-    is($@, '', "$pat compiled correctly to a regexp: $@");
-    like($str, $match_pat, "$name correctly matched");
+    if (is($@, '', "$pat compiled correctly to a regexp: $@")) {
+        like($str, $match_pat, "$name correctly matched");
+    }
 
     undef $@;
     $pat = "qr/$nomatch/$caseless";
     my $nomatch_pat = eval $pat;
-    is($@, '', "$pat compiled correctly to a regexp: $@");
-    unlike($str, $nomatch_pat, "$name correctly did not match");
+    if (is($@, '', "$pat compiled correctly to a regexp: $@")) {
+        unlike($str, $nomatch_pat, "$name correctly did not match");
+    }
 }
 
 sub run_tests {
@@ -365,14 +379,14 @@ sub IsMyUpper {
 
     my $mylower = qr/\p{pkg::IsMyLower}/i;
 
-    sub pkg::IsMyLower {
-        my $caseless = shift;
-        return "+utf8::"
-            . (($caseless)
-                ? 'Alphabetic'
-                : 'Lowercase')
-            . "\n&utf8::ASCII";
-    }
+sub pkg::IsMyLower {
+    my $caseless = shift;
+    return "+utf8::"
+        . (($caseless)
+            ? 'Alphabetic'
+            : 'Lowercase')
+        . "\n&utf8::ASCII";
+}
 
     like("A", $mylower, "Not available until runtime user-defined property with pkg:: and /i works");
 
@@ -397,5 +411,9 @@ sub INfoo   { die }
 sub Is::foo { die }
 sub In::foo { die }
 
+if (! is(@warnings, 0, "No warnings were generated")) {
+    diag join "\n", @warnings, "\n";
+}
+
 1;
 __END__