Reputation: 4021
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?
Upvotes: 0
Views: 1999
Reputation: 53976
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;
Upvotes: 2
Reputation: 30831
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...
Upvotes: 9