[tpm] Riddle me this ...

James E Keenan jkeen at verizon.net
Thu Dec 27 19:41:12 PST 2012


On 12/27/12 10:08 PM, Olaf Alders wrote:
>
> On 2012-12-27, at 9:25 PM, James E Keenan wrote:
>
>> Shouldn't the outcome of a test be independent of whether the test has a description/name/label or not?
>>
>> First, try this at the command line:
>>
>> $>   perl -MTest::More -E 'is(! 1, not 1);is(! 0, not 0);done_testing;'
>>
>> You should get:
>>
>> ok 1
>> ok 2
>> 1..2
>>
>> ... which is what I would expect.
>>
>>
>> But now, try this, which simply adds a description to each test:
>>
>> $ perl -MTest::More -E 'is(! 1, not 1, "test1");is(! 0, not 0, "test2");done_testing;'
>> ok 1
>> not ok 2
>> #   Failed test at -e line 1.
>> #          got: '1'
>> #     expected: ''
>> 1..2
>> # Looks like you failed 1 test of 2.
>>
>> Neither test prints its description, and the second test now fails.
>
> Hi Jim,
>
> I think Liam has answered the question, but I wanted to point out from the Test::More docs that (quoting here) "You are encouraged to use is() and isnt() over ok() where possible, however do not be tempted to use them to find out if something is true or false!"
>

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.

jimk


More information about the toronto-pm mailing list