[tpm] Riddle me this ...
uri at stemsystems.com
Thu Dec 27 20:43:16 PST 2012
On 12/27/2012 11:25 PM, Uri Guttman wrote:
> 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
>> $ perl -MTest::More -E 'ok(! 1 eq not 1, "test1");ok(! 0 eq not 0,
>> ok 1
>> not ok 2
>> # Failed test at -e line 1.
>> # 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),
> ok 1
> ok 2 - test2
> 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'
> 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.
i want to clarify my statement there. it is the scalar prototype of not
that is causing this as well as its low precedence. it allows its scalar
context from its prototype to envelope '0, "foo\n" which forces that
comma to its scalar form. what you think is a list of 2 values in ok()
is really a list of 1 value. same with the print one liners. they are
both printing 1 value but the first looks like it is a list of 2 values.
More information about the toronto-pm