Test-More / test-more

Test2, Test::More, Test::Simple and Test::Builder Perl modules for writing tests
Other
140 stars 87 forks source link

`subset` could use better diagnostic output #954

Open benb-zr opened 4 years ago

benb-zr commented 4 years ago
use strict;
use warnings;
use Test2::V0;
my $a = [
  map {
    [ $_ ]
  } qw(a b c d e f),
];
is $a, subset {
  item ["a"];
  item ["c"];
  item ["g"];
}, "got subset";
done_testing;

(Fails due to non-existence of g)

not ok 1 - got subset
# Failed test 'got subset'
# at test66.pl line 14.
# +------+-----------------------+------------------+--------+
# | PATH | GOT                   | CHECK            | LNs    |
# +------+-----------------------+------------------+--------+
# |      | ARRAY(0x7f94b2af2468) | <ORDERED SUBSET> | 10, 14 |
# | [?]  | <DOES NOT EXIST>      | <ARRAY>          | 13     |
# +------+-----------------------+------------------+--------+

Doesn't really indicate the nature of the failure.

exodist commented 4 years ago

oh, I see now.

In this case the error message is not wrong, you are missing an entire array. <ARRAY> is not useful, however the line 13 indicator is because it tells you which item caused the failure.

I am not sure how to improve this message as an array can literally contain any number of anything and there is no compact form for that. This is exactly the kind of situation the line number of the check was added for.