1

Test::More has is_deeply() and mentions in the documentation that it should be used instead of eq_array() or eq_hash() because it has better diagnostics, and it states ...They may be deprecated in future versions

Now I'm replacing the use of eq_...() functions for is_deeply() but I run into a problem, there is no is_not_deeply() or such function, and I have a test like this:

ok (!eq_hash(\%h1, \%h2));

Is there an idiomatic alternative I can use to test deep inequality, preferably using Test::More?

Unlike eq_hash(), which just returns true or false and needs to be wrapped in ok(), is_deeply() itself is a test. So if you wrap it in "ok()" like below:

ok(!is_deeply(\%h1, \%h2));

There are now TWO tests, is_deeply() which is failing and ok(), which would pass!

MichielB
  • 4,181
  • 1
  • 30
  • 39
  • The documentation says that they are equivalent, so a negation should be equivalent. Is there a reason you cannot do `ok ( !is_deeply(...)` )? – TLP Dec 19 '21 at 11:19
  • 2
    Because unlike eq_hash, is_deeply is a test itself. So if you wrap it in "ok()", there are TWO tests, is_deeply which is failing and ok, which would pass! – MichielB Dec 19 '21 at 11:24
  • 1
    If this functionality is not available in `Test::More`, you could try use the [`isnt`](https://metacpan.org/pod/Test2::Tools::Compare) sub from [`Test2`](https://metacpan.org/pod/Test2) instead – Håkon Hægland Dec 19 '21 at 11:43
  • @MichielB You should mention that in your question. Put in the code and show how it is not working and why not. Then you may get answers. This question is vague. – TLP Dec 19 '21 at 11:58
  • @TLP I've clarified my question to explain this – MichielB Dec 19 '21 at 14:02

1 Answers1

3

It seems like this feature is not readily available with Test::More. Then I would recommend using Test2 instead:

use strict;
use warnings;
use Test2::V0;

my %h1 = (a => [1,2,3], b=>"x");
my %h2 = (a => [1,2,3], b=>"x");

isnt (\%h1, \%h2, "Hashes are not equal" );
done_testing;
Håkon Hægland
  • 39,012
  • 21
  • 81
  • 174