[Perlunit-users] assert_equals: On undef, use message if provided [PATCH included]
Status: Beta
Brought to you by:
mca1001
From: Anders J. <AJo...@nv...> - 2008-12-17 02:17:10
|
I propose the following patch. The effect is to propagate the provided message (if any) when one comparison value is undefined, such that the point of failure in the test case is easier to locate. Similar code exists elsewhere in Test::Unit::Assert (e.g. $assert_subs{'str_equals'}). Comments? Thanks, &ers -----begin Test-Unit-0.25-anders1.patch----- diff -Naur Test-Unit-0.25/lib/Test/Unit/Assert.pm Test-Unit-0.25-anders1/lib/Test/Unit/Assert.pm --- Test-Unit-0.25/lib/Test/Unit/Assert.pm 2005-10-15 13:25:28.000000000 -0700 +++ Test-Unit-0.25-anders1/lib/Test/Unit/Assert.pm 2008-12-16 17:44:28.071447000 -0800 @@ -124,7 +124,7 @@ # pass } elsif (defined($args[0]) xor defined($args[1])) { - $self->fail('one arg was not defined'); + $self->fail(@args>2 ? join('', @args[2..$#args]) : 'one arg was not defined'); } elsif (is_numeric($args[0])) { $self->assert_num_equals(@args); diff -Naur Test-Unit-0.25/t/tlib/AssertTest.pm Test-Unit-0.25-anders1/t/tlib/AssertTest.pm --- Test-Unit-0.25/t/tlib/AssertTest.pm 2005-10-15 14:19:18.000000000 -0700 +++ Test-Unit-0.25-anders1/t/tlib/AssertTest.pm 2008-12-16 17:44:03.032513000 -0800 @@ -25,6 +25,8 @@ # A false-negative that burned me; problem with is_numeric # Test must be all on one line [ __LINE__, sub { shift->assert_equals("start o:MyClass=HASH(0x1404343f0) | any o:MyClass=HASH(0x1404343f0) e:start | any o:MyClass=HASH(0x1404343f0) e:in", "start o: e: | any o:start e: | any o:in e:"); } ], + "explanation" => [ __LINE__, sub { shift->assert_equals(0, undef, "explanation") }], + "one arg was not defined" => [ __LINE__, sub { shift->assert_equals(0, undef) }], ); } -----end Test-Unit-0.25-anders1.patch----- ----------------------------------------------------------------------------------- This email message is for the sole use of the intended recipient(s) and may contain confidential information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message. ----------------------------------------------------------------------------------- |