Browse files

Add test for regexp eval fail

  • Loading branch information...
1 parent 8b7484f commit f2025c2745c4e412b57733351b7c32d9cc2a21ce @rafl rafl committed Jun 18, 2010
Showing with 39 additions and 2 deletions.
  1. +1 −1 .gitignore
  2. +1 −1 Makefile.PL
  3. +37 −0 t/regexp_eval.t
View
2 .gitignore
@@ -8,7 +8,7 @@ Makefile
Makefile.old
blib/
cover_db/
-t/
+t/e2e/
lib/Devel/Cover/Inc.pm
pm_to_blib
*.out
View
2 Makefile.PL
@@ -372,7 +372,7 @@ WriteMakefile
"Digest::MD5" => 0,
},
dist => { COMPRESS => "gzip --best --force" },
- test => { TESTS => "t/*/*.t" },
+ test => { TESTS => "t/*/*.t t/*.t" },
clean => { FILES => join " ", "t/e2e/*" },
depend => { distdir => "@files" },
realclean => $] < 5.008008 ?
View
37 t/regexp_eval.t
@@ -0,0 +1,37 @@
+use strict;
+use warnings;
+use Test::More tests => 1;
+
+# This tests against what is basically a perl bug. When evaluating
+# code within a regular expression, the state of the regular
+# expression engine may not be altered, i.e. no regex match may be
+# performed within a regular expression.
+#
+# The following code doesn't do that, but entering the eval within the
+# regular expression involves a nextstate OP. We hook, among other
+# things, into those opcodes, and execute some of our own
+# code. Devel::Cover::use_file, to be precise. That function currently
+# uses regular expressions, and therefore breaks shit.
+#
+# We currently avoid calling use_file at all within regexp evals. This
+# test makes sure we actually do, and will yell at us if we ever start
+# doing it again.
+#
+# CPAN RT#57174 is the corresponding Devel::Cover bug. This still
+# needs to be submitted to and fixed in perl core.
+
+'x' =~ m{ (?: ((??{ 'x' })) )? }x;
+
+# on debugging perls we'd already have hit an assertion failure
+# here. We don't do "pass 'no assertion fail'" tho. I don't know if
+# that might mess up $1 for the next test. We also have to use $1
+# instead of capturing in a lexical, as that tends to fail rather
+# differently.
+
+# on non-debugging perls, the above match tends to succeed, and only
+# rarely segfaults. Therefore we also make sure that the result is
+# correct. If we hit the bug, it tends to either contain complete
+# garbage, (parts of) some random constants from the perl interpreter,
+# or segfaults completely when invoking the get magic on it.
+
+is $1, 'x';

0 comments on commit f2025c2

Please sign in to comment.