This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Eliminate must_die() from ReTest.pl, which is only used 3 times in pat.t
authorNicholas Clark <nick@ccl4.org>
Sat, 5 Mar 2011 10:44:50 +0000 (10:44 +0000)
committerNicholas Clark <nick@ccl4.org>
Sat, 5 Mar 2011 20:26:10 +0000 (20:26 +0000)
Replace it with is(eval ..., undef); like($@, $error);

It's not viable to emulate Test::Exception's throws_ok() in test.pl, as it
only takes a code reference, whereas these tests are for compilation errors
and so use string eval.

t/re/ReTest.pl
t/re/pat.t

index 72316cc..41aae3a 100644 (file)
@@ -33,14 +33,6 @@ sub eval_ok ($;$) {
     }
 }
 
-sub must_die {
-    my ($code, $pattern, $name) = @_;
-    Carp::confess("Bad pattern") unless $pattern;
-    undef $@;
-    ref $code ? &$code : eval $code;
-    like($@, $pattern, $name // "\$\@ =~ /$pattern/");
-}
-
 sub must_warn {
     my ($code, $pattern, $name) = @_;
     Carp::confess("Bad pattern") unless $pattern;
index a37764b..2640fdc 100644 (file)
@@ -21,7 +21,7 @@ BEGIN {
     do "re/ReTest.pl" or die $@;
 }
 
-plan tests => 426;  # Update this when adding/deleting tests.
+plan tests => 433;  # Update this when adding/deleting tests.
 
 run_tests() unless caller;
 
@@ -584,14 +584,14 @@ sub run_tests {
     }
 
     {
-        must_die 'q(a:[b]:) =~ /[x[:foo:]]/',
-                 qr/POSIX class \[:[^:]+:\] unknown in regex/,
-                 'POSIX class [: :] must have valid name';
+        is(eval 'q(a:[b]:) =~ /[x[:foo:]]/', undef);
+       like ($@, qr/POSIX class \[:[^:]+:\] unknown in regex/,
+             'POSIX class [: :] must have valid name');
 
         for my $d (qw [= .]) {
-            must_die "/[[${d}foo${d}]]/",
-                     qr/\QPOSIX syntax [$d $d] is reserved for future extensions/,
-                     "POSIX syntax [[$d $d]] is an error";
+            is(eval "/[[${d}foo${d}]]/", undef);
+           like ($@, qr/\QPOSIX syntax [$d $d] is reserved for future extensions/,
+                 "POSIX syntax [[$d $d]] is an error");
         }
     }
 
@@ -675,8 +675,9 @@ sub run_tests {
     }
 
     foreach ('$+[0] = 13', '$-[0] = 13', '@+ = (7, 6, 5)', '@- = qw (foo bar)') {
-        must_die($_, qr/^Modification of a read-only value attempted/,
-                'Elements of @- and @+ are read-only');
+       is(eval $_, undef);
+        like($@, qr/^Modification of a read-only value attempted/,
+            'Elements of @- and @+ are read-only');
     }
 
     {