@@ -350,31 +350,36 @@ sub run_tests {
350350
351351 # Defaults assumed if this fails
352352 eval { require Config; };
353- $: :reg_infty = $Config::Config {reg_infty } // 65535 ;
353+ $: :reg_infty = $Config::Config {reg_infty } // ((1<<31)-1) ;
354354 $: :reg_infty_m = $: :reg_infty - 1;
355355 $: :reg_infty_p = $: :reg_infty + 1;
356356 $: :reg_infty_m = $: :reg_infty_m; # Suppress warning.
357357
358358 # As well as failing if the pattern matches do unexpected things, the
359359 # next three tests will fail if you should have picked up a lower-than-
360360 # default value for $reg_infty from Config.pm, but have not.
361-
362- is(eval q{ ('aaa' =~ /(a{1,$::reg_infty_m})/)[0]} , ' aaa' , $message );
363- is($@ , ' ' , $message );
364- is(eval q{ ('a' x $::reg_infty_m) =~ /a{$::reg_infty_m}/} , 1, $message );
365- is($@ , ' ' , $message );
366- isnt(q{ ('a' x ($::reg_infty_m - 1)) !~ /a{$::reg_infty_m}/} , 1, $message );
367- is($@ , ' ' , $message );
361+ SKIP: {
362+ skip " REG_INFTY too big to test ($: :reg_infty)" , 7
363+ if $: :reg_infty > (1<<16);
364+
365+ is(eval q{ ('aaa' =~ /(a{1,$::reg_infty_m})/)[0]} , ' aaa' , $message );
366+ is($@ , ' ' , $message );
367+ is(eval q{ ('a' x $::reg_infty_m) =~ /a{$::reg_infty_m}/} , 1, $message );
368+ is($@ , ' ' , $message );
369+ isnt(q{ ('a' x ($::reg_infty_m - 1)) !~ /a{$::reg_infty_m}/} , 1, $message );
370+ is($@ , ' ' , $message );
371+
372+ # It should be 'a' x 2147483647, but that exhausts memory on
373+ # reasonably sized modern machines
374+ like(' a' x $: :reg_infty_m, qr / a{1,}/ ,
375+ " {1,} matches more times than REG_INFTY" );
376+ }
368377
369378 eval " 'aaa' =~ /a{1,$: :reg_infty}/" ;
370379 like($@ , qr / ^\Q Quantifier in {,} bigger than/ , $message );
371380 eval " 'aaa' =~ /a{1,$: :reg_infty_p}/" ;
372381 like($@ , qr / ^\Q Quantifier in {,} bigger than/ , $message );
373382
374- # It should be 'a' x 2147483647, but that exhausts memory on
375- # reasonably sized modern machines
376- like(' a' x $: :reg_infty_p, qr / a{1,}/ ,
377- " {1,} matches more times than REG_INFTY" );
378383 }
379384
380385 {
@@ -393,12 +398,17 @@ sub run_tests {
393398
394399 for my $l (@trials ) { # Ordered to free memory
395400 my $a = ' a' x $l ;
396- my $message = " Long monster, length = $l " ;
397- like(" ba$a =" , qr / a$a =/ , $message );
398- unlike(" b$a =" , qr / a$a =/ , $message );
399- like(" b$a =" , qr / ba+=/ , $message );
400-
401- like(" ba$a =" , qr / b(?:a|b)+=/ , $message );
401+ # we do not use like() or unlike() here as the string
402+ # is very long and is not useful if the match fails,
403+ # the useful part
404+ ok(" ba$a =" =~ m / a$a =/ , sprintf
405+ ' Long monster: ("ba".("a" x %d)."=") =~ m/aa...a=/' , $l );
406+ ok(" b$a =" !~ m / a$a =/ , sprintf
407+ ' Long monster: ("b" .("a" x %d)."=") !~ m/aa...a=/' , $l );
408+ ok(" b$a =" =~ m / ba+=/ , sprintf
409+ ' Long monster: ("b" .("a" x %d)."=") =~ m/ba+=/' , $l );
410+ ok(" ba$a =" =~ m / b(?:a|b)+=/ , sprintf
411+ ' Long monster: ("ba".("a" x %d)."=") =~ m/b(?:a|b)+=/' , $l );
402412 }
403413 }
404414
0 commit comments