It looks like Test::Deep
was inspired by is_deeply
. My question is how do I make cmp_deeply
part of a test instead of a test on its own? Because my list of tests only states 8, but everytime I use cmp_deeply
, it counts as a test, making my actual number of tests 11 (because I call cmp_deeply
3 times) when I only have 8 functions. I do not want to increase the number of my tests. Is there a more viable solution?
views:
89answers:
2
+6
A:
You should use eq_deeply
instead:
This is the same as
cmp_deeply()
except it just returns true or false. It does not create diagnostics...
Michael Carman
2009-08-13 22:10:32
This doesn't really answer the question though does it? Whether or not there is output, the number of tests would be the same between eq_deeply and cmp_deeply.
Ether
2009-09-04 20:13:06
No, `eq_deeply` *just returns true or false.* It doesn't report anything to the test harness.
Michael Carman
2009-09-05 00:55:41
+2
A:
There are a number of things you can do, but without knowing more of the specifics in your tests it is difficult to know which is the most appropriate:
Don't plan for a specific number of tests.
use Test::More; all( cmp_deeply($got0, $expected0), cmp_deeply($got1, $expected1), cmp_deeply($got2, $expected2) ); # ... your other 7 tests done_testing(); # signals that we're all done.. exiting normally.
Dynamically determine how many tests are being run, which makes sense if you are testing some deep and dynamic structure whose complexity (and number of tests required) is not known in advance:
use Test::More; use Test::Deep; # perhaps this is in some sort of loop? cmp_deeply($got0, $expected0); $numTests++; cmp_deeply($got1, $expected1); $numTests++; cmp_deeply($got2, $expected2); $numTests++; # ... your other 7 tests # TAP output must be either at the beginning or end of all output plan tests => $numTests + 7; # no more tests here! exit;
Ether
2009-08-14 01:58:45