diff options
author | Michiel Beijen <mb@x14.nl> | 2021-12-18 12:10:15 +0100 |
---|---|---|
committer | Karl Williamson <khw@cpan.org> | 2021-12-24 08:26:21 -0700 |
commit | b135e9358aa994456ec32ccfe7a73e685f598797 (patch) | |
tree | 433ea3124e6f7a8e1f4363ee0c29161ee332d6d6 /ext | |
parent | ea5f65263ad54bd59f582eb38161753c2546d6b3 (diff) | |
download | perl-b135e9358aa994456ec32ccfe7a73e685f598797.tar.gz |
use is_deeply instead of eq_ Test::More functions
the eq_set, eq_hash, and eq_array functions in Test::More are
discouraged to use, and is_deeply is recommended. Ref:
https://metacpan.org/pod/Test::More#Discouraged-comparison-functions
The reason for this is that, if the tests fail, is_deeply has much
better diagnostics.
The other thing is that is_deeply is a test function directly, where
eq_hash and such need to be wrapped inside ok(). This is easy to forget
-- proof of this is in Benchmark.t, where we had this code, that did not
test anything:
eq_set([keys %$got], [qw(Foo Bar Baz)], 'should be exactly three objects');
It is now replaced by:
is_deeply([sort keys %$got], [sort qw(Foo Bar Baz)], 'should be exactly three objects');
this commit replaces all usage of eq_set, eq_hash, and eq_array in lib/
and ext/ for tests that use Test::More.
One small exception is where a negated test is used; Test::More does not
have is_not_deeply() or such. Test2 has `isnt()` for this, but that is
not in core. In those cases, we still keep using the eq_ operators.
Diffstat (limited to 'ext')
-rw-r--r-- | ext/Hash-Util-FieldHash/t/02_function.t | 6 | ||||
-rw-r--r-- | ext/Hash-Util-FieldHash/t/11_hashassign.t | 70 | ||||
-rw-r--r-- | ext/Pod-Functions/t/Functions.t | 4 | ||||
-rw-r--r-- | ext/XS-APItest/t/push.t | 16 |
4 files changed, 48 insertions, 48 deletions
diff --git a/ext/Hash-Util-FieldHash/t/02_function.t b/ext/Hash-Util-FieldHash/t/02_function.t index 32c00358ef..b4294ddadc 100644 --- a/ext/Hash-Util-FieldHash/t/02_function.t +++ b/ext/Hash-Util-FieldHash/t/02_function.t @@ -165,8 +165,8 @@ for my $preload ( [], [ map {}, 1 .. 3] ) { { my @refs = map gen_ref( $_), @test_types; @f{ @refs} = @test_types; - ok( - eq_set( [ values %f], [ @test_types, @preval]), + is_deeply( + [ sort values %f], [ sort ( @test_types, @preval) ], "all types present$pre", ); is( @@ -176,7 +176,7 @@ for my $preload ( [], [ map {}, 1 .. 3] ) { ); } die "preload gone" unless defined $preload; - ok( eq_set( [ values %f], \ @preval), "all types gone$pre"); + is_deeply( [ sort values %f], [ sort @preval], "all types gone$pre"); is( keys %$ob_reg, @$preload, "all types unregistered$pre"); } is( keys %$ob_reg, 0, "preload gone after loop"); diff --git a/ext/Hash-Util-FieldHash/t/11_hashassign.t b/ext/Hash-Util-FieldHash/t/11_hashassign.t index d3e45d32de..f807146391 100644 --- a/ext/Hash-Util-FieldHash/t/11_hashassign.t +++ b/ext/Hash-Util-FieldHash/t/11_hashassign.t @@ -31,12 +31,12 @@ my @temp = (key=>undef); is ($comma{$temp[0]}, "value", 'is key present? (using LHS of =>)'); @temp = %comma; -ok (eq_array (\@comma, \@temp), 'list from comma hash'); +is_deeply (\@comma, \@temp, 'list from comma hash'); @temp = each %comma; -ok (eq_array (\@comma, \@temp), 'first each from comma hash'); +is_deeply (\@comma, \@temp, 'first each from comma hash'); @temp = each %comma; -ok (eq_array ([], \@temp), 'last each from comma hash'); +is_deeply ([], \@temp, 'last each from comma hash'); my %temp = %comma; @@ -49,12 +49,12 @@ is ($temp{key}, "value", 'is key present? (maybe optimised)'); is ($comma{$temp[0]}, "value", 'is key present? (using LHS of =>)'); @temp = %temp; -ok (eq_array (\@temp, \@temp), 'list from copy of comma hash'); +is_deeply (\@temp, \@temp, 'list from copy of comma hash'); @temp = each %temp; -ok (eq_array (\@temp, \@temp), 'first each from copy of comma hash'); +is_deeply (\@temp, \@temp, 'first each from copy of comma hash'); @temp = each %temp; -ok (eq_array ([], \@temp), 'last each from copy of comma hash'); +is_deeply ([], \@temp, 'last each from copy of comma hash'); my @arrow = (Key =>"Value"); @@ -72,12 +72,12 @@ is ($arrow{Key}, "Value", 'is key present? (maybe optimised)'); is ($arrow{$temp[0]}, "Value", 'is key present? (using LHS of =>)'); @temp = %arrow; -ok (eq_array (\@arrow, \@temp), 'list from arrow hash'); +is_deeply (\@arrow, \@temp, 'list from arrow hash'); @temp = each %arrow; -ok (eq_array (\@arrow, \@temp), 'first each from arrow hash'); +is_deeply (\@arrow, \@temp, 'first each from arrow hash'); @temp = each %arrow; -ok (eq_array ([], \@temp), 'last each from arrow hash'); +is_deeply ([], \@temp, 'last each from arrow hash'); %temp = %arrow; @@ -90,12 +90,12 @@ is ($temp{Key}, "Value", 'is key present? (maybe optimised)'); is ($arrow{$temp[0]}, "Value", 'is key present? (using LHS of =>)'); @temp = %temp; -ok (eq_array (\@temp, \@temp), 'list from copy of arrow hash'); +is_deeply (\@temp, \@temp, 'list from copy of arrow hash'); @temp = each %temp; -ok (eq_array (\@temp, \@temp), 'first each from copy of arrow hash'); +is_deeply (\@temp, \@temp, 'first each from copy of arrow hash'); @temp = each %temp; -ok (eq_array ([], \@temp), 'last each from copy of arrow hash'); +is_deeply ([], \@temp, 'last each from copy of arrow hash'); fieldhash my %direct; fieldhash my %slow; @@ -103,9 +103,9 @@ fieldhash my %slow; $slow{Dromedary} = 1; $slow{Camel} = 2; -ok (eq_hash (\%slow, \%direct), "direct list assignment to hash"); +is_deeply (\%slow, \%direct, "direct list assignment to hash"); %direct = (Camel => 2, 'Dromedary' => 1); -ok (eq_hash (\%slow, \%direct), "direct list assignment to hash using =>"); +is_deeply (\%slow, \%direct, "direct list assignment to hash using =>"); $slow{Llama} = 0; # A llama is not a camel :-) ok (!eq_hash (\%direct, \%slow), "different hashes should not be equal!"); @@ -115,7 +115,7 @@ fieldhash %names; %names = ('$' => 'Scalar', '@' => 'Array', # Grr ' '%', 'Hash', '&', 'Code'); %names_copy = %names; -ok (eq_hash (\%names, \%names_copy), "check we can copy our hash"); +is_deeply (\%names, \%names_copy, "check we can copy our hash"); sub in { my %args = @_; @@ -137,7 +137,7 @@ sub out { } %names_copy = out (); -ok (eq_hash (\%names, \%names_copy), "pass hash from a subroutine"); +is_deeply (\%names, \%names_copy, "pass hash from a subroutine"); sub out_method { my $self = shift; @@ -145,7 +145,7 @@ sub out_method { } %names_copy = main->out_method (); -ok (eq_hash (\%names, \%names_copy), "pass hash from a method"); +is_deeply (\%names, \%names_copy, "pass hash from a method"); sub in_out { my %args = @_; @@ -153,7 +153,7 @@ sub in_out { } %names_copy = in_out (%names); -ok (eq_hash (\%names, \%names_copy), "pass hash to and from a subroutine"); +is_deeply (\%names, \%names_copy, "pass hash to and from a subroutine"); sub in_out_method { my $self = shift; @@ -162,26 +162,26 @@ sub in_out_method { } %names_copy = main->in_out_method (%names); -ok (eq_hash (\%names, \%names_copy), "pass hash to and from a method"); +is_deeply (\%names, \%names_copy, "pass hash to and from a method"); my %names_copy2 = %names; -ok (eq_hash (\%names, \%names_copy2), "check copy worked"); +is_deeply (\%names, \%names_copy2, "check copy worked"); # This should get ignored. %names_copy = ('%', 'Associative Array', %names); -ok (eq_hash (\%names, \%names_copy), "duplicates at the start of a list"); +is_deeply (\%names, \%names_copy, "duplicates at the start of a list"); # This should not %names_copy = ('*', 'Typeglob', %names); $names_copy2{'*'} = 'Typeglob'; -ok (eq_hash (\%names_copy, \%names_copy2), "duplicates at the end of a list"); +is_deeply (\%names_copy, \%names_copy2, "duplicates at the end of a list"); %names_copy = ('%', 'Associative Array', '*', 'Endangered species', %names, '*', 'Typeglob',); -ok (eq_hash (\%names_copy, \%names_copy2), "duplicates at both ends"); +is_deeply (\%names_copy, \%names_copy2, "duplicates at both ends"); # And now UTF8 @@ -204,12 +204,12 @@ foreach my $chr (60, 200, 600, 6000, 60000) { is ($utf8c{$temp[0]}, $value, 'is key present? (using LHS of $tempval)'); @temp = %utf8c; - ok (eq_array (\@utf8c, \@temp), 'list from utf8 comma hash'); + is_deeply (\@utf8c, \@temp, 'list from utf8 comma hash'); @temp = each %utf8c; - ok (eq_array (\@utf8c, \@temp), 'first each from utf8 comma hash'); + is_deeply (\@utf8c, \@temp, 'first each from utf8 comma hash'); @temp = each %utf8c; - ok (eq_array ([], \@temp), 'last each from utf8 comma hash'); + is_deeply ([], \@temp, 'last each from utf8 comma hash'); %temp = %utf8c; @@ -223,12 +223,12 @@ foreach my $chr (60, 200, 600, 6000, 60000) { is ($temp{$temp[0]}, $value, "is key present? (using LHS of $tempval)"); @temp = %temp; - ok (eq_array (\@temp, \@temp), 'list from copy of utf8 comma hash'); + is_deeply (\@temp, \@temp, 'list from copy of utf8 comma hash'); @temp = each %temp; - ok (eq_array (\@temp, \@temp), 'first each from copy of utf8 comma hash'); + is_deeply (\@temp, \@temp, 'first each from copy of utf8 comma hash'); @temp = each %temp; - ok (eq_array ([], \@temp), 'last each from copy of utf8 comma hash'); + is_deeply ([], \@temp, 'last each from copy of utf8 comma hash'); my $assign = sprintf '("\x{%x}" => "%d")', $chr, $chr; print "# $assign\n"; @@ -247,12 +247,12 @@ foreach my $chr (60, 200, 600, 6000, 60000) { is ($utf8a{$temp[0]}, $value, "is key present? (using LHS of $tempval)"); @temp = %utf8a; - ok (eq_array (\@utf8a, \@temp), 'list from utf8 arrow hash'); + is_deeply (\@utf8a, \@temp, 'list from utf8 arrow hash'); @temp = each %utf8a; - ok (eq_array (\@utf8a, \@temp), 'first each from utf8 arrow hash'); + is_deeply (\@utf8a, \@temp, 'first each from utf8 arrow hash'); @temp = each %utf8a; - ok (eq_array ([], \@temp), 'last each from utf8 arrow hash'); + is_deeply ([], \@temp, 'last each from utf8 arrow hash'); %temp = %utf8a; @@ -266,12 +266,12 @@ foreach my $chr (60, 200, 600, 6000, 60000) { is ($temp{$temp[0]}, $value, "is key present? (using LHS of $tempval)"); @temp = %temp; - ok (eq_array (\@temp, \@temp), 'list from copy of utf8 arrow hash'); + is_deeply (\@temp, \@temp, 'list from copy of utf8 arrow hash'); @temp = each %temp; - ok (eq_array (\@temp, \@temp), 'first each from copy of utf8 arrow hash'); + is_deeply (\@temp, \@temp, 'first each from copy of utf8 arrow hash'); @temp = each %temp; - ok (eq_array ([], \@temp), 'last each from copy of utf8 arrow hash'); + is_deeply ([], \@temp, 'last each from copy of utf8 arrow hash'); } diff --git a/ext/Pod-Functions/t/Functions.t b/ext/Pod-Functions/t/Functions.t index 2beccc1ac6..959bff45a7 100644 --- a/ext/Pod-Functions/t/Functions.t +++ b/ext/Pod-Functions/t/Functions.t @@ -35,12 +35,12 @@ my @categories = qw( Modules Objects Socket SysV User Network Time ); -ok( eq_array( \@Type_Order, \@categories ), +is_deeply( \@Type_Order, \@categories, '@Type_Order' ); my @cat_keys = grep exists $Type_Description{ $_ } => @Type_Order; -ok( eq_array( \@cat_keys, \@categories ), +is_deeply( \@cat_keys, \@categories, 'keys() %Type_Description' ); SKIP: { diff --git a/ext/XS-APItest/t/push.t b/ext/XS-APItest/t/push.t index e8a4c03a3c..c2ace0d4ac 100644 --- a/ext/XS-APItest/t/push.t +++ b/ext/XS-APItest/t/push.t @@ -8,16 +8,16 @@ my @mpushp = mpushp(); my @mpushn = mpushn(); my @mpushi = mpushi(); my @mpushu = mpushu(); -ok(eq_array(\@mpushp, [qw(one two three)]), 'mPUSHp()'); -ok(eq_array(\@mpushn, [0.5, -0.25, 0.125]), 'mPUSHn()'); -ok(eq_array(\@mpushi, [-1, 2, -3]), 'mPUSHi()'); -ok(eq_array(\@mpushu, [1, 2, 3]), 'mPUSHu()'); +is_deeply(\@mpushp, [qw(one two three)], 'mPUSHp()'); +is_deeply(\@mpushn, [0.5, -0.25, 0.125], 'mPUSHn()'); +is_deeply(\@mpushi, [-1, 2, -3], 'mPUSHi()'); +is_deeply(\@mpushu, [1, 2, 3], 'mPUSHu()'); my @mxpushp = mxpushp(); my @mxpushn = mxpushn(); my @mxpushi = mxpushi(); my @mxpushu = mxpushu(); -ok(eq_array(\@mxpushp, [qw(one two three)]), 'mXPUSHp()'); -ok(eq_array(\@mxpushn, [0.5, -0.25, 0.125]), 'mXPUSHn()'); -ok(eq_array(\@mxpushi, [-1, 2, -3]), 'mXPUSHi()'); -ok(eq_array(\@mxpushu, [1, 2, 3]), 'mXPUSHu()'); +is_deeply(\@mxpushp, [qw(one two three)], 'mXPUSHp()'); +is_deeply(\@mxpushn, [0.5, -0.25, 0.125], 'mXPUSHn()'); +is_deeply(\@mxpushi, [-1, 2, -3], 'mXPUSHi()'); +is_deeply(\@mxpushu, [1, 2, 3], 'mXPUSHu()'); |