[tpm] Riddle me this ...

Uri Guttman uri at stemsystems.com
Thu Dec 27 20:25:03 PST 2012


On 12/27/2012 10:41 PM, James E Keenan wrote:

> But we experience the same problem with 'ok' as with 'is':
>
> $ perl -MTest::More -E 'ok(! 1 eq not 1);ok(! 0 eq not 0);done_testing;'
> ok 1
> ok 2
> 1..2
>
> $ perl -MTest::More -E 'ok(! 1 eq not 1, "test1");ok(! 0 eq not 0,
> "test2");done_testing;'
> ok 1
> not ok 2
> #   Failed test at -e line 1.
> 1..2
> # Looks like you failed 1 test of 2.
>
> Adding a description changes the outcome of the second test, and both
> descriptions vanish into the ether.

it is a precedence issue with 'not' remember, not is a low precedence 
op. look at this change putting () around the second call to not:

perl -MTest::More -E 'ok(! 1 eq not 1, "test1");ok(! 0 eq (not 0), 
"test2");done_testing;'
ok 1
ok 2 - test2
1..2

look at these two and you can see the difference more clearly. not is a 
scalar with low precedence. so 0, "foo\n" is the SCALAR comma op which 
will return "foo\n" to not which then makes it 0 and fails the test.


perl -le 'print !0 eq not 0, "foo\n"'

perl -le 'print !0 eq not 0'
1

so the test is faulty itself by leaving not bare without parens to clear 
up the expression.

the reason the test name is eaten when it passes is the same thing. the 
result of not 1, "test1" is false and the name isn't ever passed to 
ok(). the test itself passes due to the false value returned by not.

uri






More information about the toronto-pm mailing list