Subject: | Expose (somehow) output of deep_diag() after call to eq_deeply() |
This ticket is similar in motive and substance to RT #27275 in Test::More: "Expose
Test::Builder->_is_diag() as public method"
For the motivation/use case, please read the above referenced ticket.
Here is my horrible hack code for accomplishing what I want to accomplish. Essentially, I'm
re-implementing eq_deeply() and capturing deep_diag() in an exception:
_eq_deeply_with_fatal_diag( $results, $expected );
...
sub _eq_deeply_with_fatal_diag {
my ($d1, $d2, $name) = @_;
local $Test::Builder::Level = $Test::Builder::Level + 1; # Trust me, you want this.
local $Test::Deep::Stack = Test::Deep::Stack->new;
local $Test::Deep::CompareCache = Test::Deep::Cache->new;
local %Test::Deep::WrapCache;
my $ok = Test::Deep::descend( $d1, $d2 )
or die Test::Deep::deep_diag( $Test::Deep::Stack ); # here's the reason for this right here
return $ok;
}
The fatal isn't necessary (it fits into the way I handle my data-driven tests), you could easily
accomplish this by adding this to your eq_deeply():
return $ok ? $ok : wantarray ? ( $ok, deep_diag( $Test::Deep::Stack ) ) : $ok;
Thanks for your consideration,
David