This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
t/op/chop.t: Don't use too large code points
authorKarl Williamson <khw@cpan.org>
Mon, 3 Jul 2017 15:33:09 +0000 (09:33 -0600)
committerKarl Williamson <khw@cpan.org>
Thu, 13 Jul 2017 03:14:23 +0000 (21:14 -0600)
The bug this was testing for requires a code point that will no longer
be legal on 32-bit machines.  So skip unless we're on a 64-bit platform,
and revise to use chr() in the skipped code instead of "\x{}".  The
latter would try to be compiled even if execution gets skipped, so would
cause it to die, whereas chr() is runtime, so get skipped if
inappropriate.  This also tested the very highest legal code point on
64-bit machines, which is now illegal, so test the new very highest one.

t/op/chop.t

index 743f21a..f69a7ab 100644 (file)
@@ -249,26 +249,28 @@ foreach my $start (@chars) {
     ok(1, "extend sp in pp_chomp");
 }
 
-{
+SKIP: {
     # [perl #73246] chop doesn't support utf8
     # the problem was UTF8_IS_START() didn't handle perl's extended UTF8
+    # The first code point that failed was 0x80000000, which is now illegal on
+    # 32-bit machines.
+
+    use Config;
+    ($Config{ivsize} > 4)
+        or skip("this build can't handle very large characters", 4);
 
-    no warnings 'deprecated'; # This is above IV_MAX on 32 bit machines
-    my $utf = "\x{80000001}\x{80000000}";
+    # Use chr instead of \x{} so doesn't try to compile these on 32-bit
+    # machines, which would crash
+    my $utf = chr(0x80000001) . chr(0x80000000);
     my $result = chop($utf);
-    is($utf, "\x{80000001}", "chopping high 'unicode'- remnant");
-    is($result, "\x{80000000}", "chopping high 'unicode' - result");
-
-    SKIP: {
-        no warnings 'overflow'; # avoid compile-time warnings below on 32-bit architectures
-        use Config;
-        $Config{ivsize} >= 8
-         or skip("this build can't handle very large characters", 2);
-        my $utf = "\x{ffffffffffffffff}\x{fffffffffffffffe}";
-        my $result = chop $utf;
-        is($utf, "\x{ffffffffffffffff}", "chop even higher 'unicode' - remnant");
-        is($result, "\x{fffffffffffffffe}", "chop even higher 'unicode' - result");
-    }
+    is($utf, chr(0x80000001), "chopping high 'unicode'- remnant");
+    is($result, chr(0x80000000), "chopping high 'unicode' - result");
+
+    no warnings;
+    $utf = chr(0x7fffffffffffffff) . chr(0x7ffffffffffffffe);
+    $result = chop($utf);
+    is($utf, chr(0x7fffffffffffffff), "chop even higher 'unicode'- remnant");
+    is($result, chr(0x7ffffffffffffffe), "chop even higher 'unicode' - result");
 }
 
 $/ = "\n";