Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test_err(qr//) does not work with 0.98_05 #387

Closed
ppisar opened this issue Aug 7, 2013 · 4 comments
Closed

test_err(qr//) does not work with 0.98_05 #387

ppisar opened this issue Aug 7, 2013 · 4 comments

Comments

@ppisar
Copy link

ppisar commented Aug 7, 2013

I found a regression when fixing Test-Class https://rt.cpan.org/Public/Bug/Display.html?id=85004:

$ cat /tmp/runtests_return.t
#!/usr/bin/perl
use strict;
use warnings;

use Test::Builder::Tester tests => 1;
use Test::More;

test_out("not ok 1 - foo");
test_err(qr/.*/s);

fail("foo");

test_test("early return handled (fail)");
$ perl -I/tmp/Test-Simple-0.98_04/lib/ /tmp/runtests_return.t 
1..1
ok 1 - early return handled (fail)
$ perl -I/tmp/Test-Simple-0.98_05/lib/ /tmp/runtests_return.t 
1..1
not ok 1 - early return handled (fail)
#   Failed test 'early return handled (fail)'
#   at /tmp/runtests_return.t line 13.
# STDERR is:
# #   Failed test 'foo'
# #   at /tmp/runtests_return.t line 11.
# 
# not:
# (?^s:.*)
# 
# as expected

This is caused with Test-Simple commit:

commit 497965306444982d4948e24811e44e72619885f8
Author: Michael G. Schwern <schwern@pobox.com>
Date:   Mon Apr 15 17:13:43 2013 +0100

    Fix Test::Builder::Tester so it works with subtests.

    They already work in TB1.5 and this wasn't hard to fix.

    For #350

Do you have any idea what's wrong? It seems none test_err(qr//) matches anymore.

@ppisar
Copy link
Author

ppisar commented Aug 9, 2013

The problem is stringification in return:

sub _account_for_subtest {
    my( $self, $check ) = @_;

    # Since we ship with Test::Builder, calling a private method is safe...ish.
    return $t->_indent . $check;
}

If the $check is a regular expression, it coerces it into string which obviously will not match.

Because the reqular expression can be a multiline stuff, there is easy no way how to prepend indentation. I propose to omit the indent in case of regular expression.

@ppisar
Copy link
Author

ppisar commented Aug 9, 2013

Fix:

From 919f7398038fe24e7e23ffcff5c5abe1f00d13ce Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= <ppisar@redhat.com>
Date: Fri, 9 Aug 2013 09:16:10 +0200
Subject: [PATCH] Pass regular expression intact
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This commit:

commit 497965306444982d4948e24811e44e72619885f8
Author: Michael G. Schwern <schwern@pobox.com>
Date:   Mon Apr 15 17:13:43 2013 +0100

    Fix Test::Builder::Tester so it works with subtests.

broke test_err(qr//) because it converted the expression to a string.
This patch omits regular expressions from indentation.

<https://github.com/schwern/test-more/issues/387>

Signed-off-by: Petr Písař <ppisar@redhat.com>
---
 lib/Test/Builder/Tester.pm | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/lib/Test/Builder/Tester.pm b/lib/Test/Builder/Tester.pm
index 299ee52..fed11b5 100644
--- a/lib/Test/Builder/Tester.pm
+++ b/lib/Test/Builder/Tester.pm
@@ -479,6 +479,11 @@ sub expect {
 sub _account_for_subtest {
     my( $self, $check ) = @_;

+    if (ref $check) {
+        # Do not mangle regular expression
+        return $check;
+    }
+
     # Since we ship with Test::Builder, calling a private method is safe...ish.
     return $t->_indent . $check;
 }
-- 
1.8.1.4

@rjbs
Copy link
Contributor

rjbs commented Oct 29, 2013

Please consider testing with Test-Simple-0.99_01.tar.gz

@ppisar
Copy link
Author

ppisar commented Oct 30, 2013

Test-Simple-0.99_01 fixes this issue for me. Thank you.

@rjbs rjbs closed this as completed Jan 6, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants