Using Test::Deep with Test::Builder

tomhukins on 2009-03-17T14:50:23

I find Test::Deep very useful when writing tests. It's very handy for checking complicated data structures in all sorts of different ways.

Recently I wanted to use Test::Deep in my own Test::Builder test subclass. I discovered Test::Deep::NoTest which seemed useful: it lets me call functions from Test::Deep without them expecting to run directly within a test script themselves.

So, Test::Deep::NoTest and eq_deeply() looked like what I wanted. And they did a fine job, except when comparisons failed: I could find out that a comparison had failed, but not why.

After a brisk stroll through Test::Deep's source code and a quick chat with its author, I wrote a patch to expose and document its cmp_details() method. This lets you compare data structures and get a description of any differences, if they exist.

If you want to use Test::Deep within your own test class, download version 0.104 or newer of Test::Deep and see the new documentation on Using Test::Deep with Test::Builder.