diff options
author | Nicholas Clark <nick@ccl4.org> | 2011-03-05 10:44:50 +0000 |
---|---|---|
committer | Nicholas Clark <nick@ccl4.org> | 2011-03-05 20:26:10 +0000 |
commit | cb124425fee7b414700604d7521979e2bfaf49c5 (patch) | |
tree | 5b0b8fb5b407e250bf95c7207cdbc9dc429c8d39 | |
parent | 19d6612dd7b4d6a9dc8581f9a07338cb41b9d0b5 (diff) | |
download | perl-cb124425fee7b414700604d7521979e2bfaf49c5.tar.gz |
Eliminate must_die() from ReTest.pl, which is only used 3 times in pat.t
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.
-rw-r--r-- | t/re/ReTest.pl | 8 | ||||
-rw-r--r-- | t/re/pat.t | 19 |
2 files changed, 10 insertions, 17 deletions
diff --git a/t/re/ReTest.pl b/t/re/ReTest.pl index 72316cc5ab..41aae3a68b 100644 --- a/t/re/ReTest.pl +++ b/t/re/ReTest.pl @@ -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; diff --git a/t/re/pat.t b/t/re/pat.t index a37764b0c7..2640fdc0d4 100644 --- a/t/re/pat.t +++ b/t/re/pat.t @@ -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'); } { |