in reply to Use of qr// modifier with Test::More::like

I'm not sure this has anything to do with Test::More.

use Test::More 'tests' => 7; # all tests pass my $string = "abc\ndef\nghi"; my $pattern = qr/def/; my $pattern_m = qr/^def$/m; ok( $string =~ /^def$/m, 'literal/m pattern matches' ); ok( $string =~ $pattern, 'plain qr stored pattern matches' ); is( "$pattern_m", '(?m-xis:^def$)', 'qr/m as string: (?m-xis:^def$)'); like( $string, '/(?m-xis:^def$)/', 'string (?m-xis:^def$) matches' ); ok( $string =~ /(?m-xis:^def$)/, 'literal (?m-xis:^def$) matches'); ok( ! ($string =~ $pattern_m), 'qr/m stored pattern does not match' ); unlike( $string, $pattern_m, 'qr/m stored pattern not "like"' );

Perhaps I've done something foolish here (using Test::More to check Test::More, maybe), but this looks like a bug.

Update after gary.monson's reply: Sorry I wasn't clear. This looks to me like a bug in perl. Without running it, I would have expected the last two tests to come out the opposite of how they did. I originally thought the OP's behavior might have to do with how Test::Builder uses string eval to do its comparison, but that doesn't seem to be the case.

Replies are listed 'Best First'.
Re^2: Use of qr// modifier with Test::More::like
by gary.monson (Novice) on Mar 27, 2008 at 02:30 UTC

    Sorry - I probably didn't make my worries as clear as they should be. I am wondering if it is a problem with qr//m itself, rather than Test::More. Otherwise, maybe Test::More is doing something with the qr//m that I wasn't expecting? I tried looking inside the source of Test::More, but got lost pretty quick.

    When you say "this looks like a bug" - do you mean in Test::More, perl, or my code?

    If your code is supposed to show that Test::More is fine, well, I'm not sure that it does. Your last test *should* be failing rather than passing, for the same reason my test # 4 should be passing. $string *should* match $pattern_m, so like() should pass, and unlike() should fail.

    Thanks,
    Gary