Perl module for testing data

I am looking for something like is_deeply or Test :: Deep cmp_deeply, but this just checks the keys / types of the data structure, not the values. For example, I don’t care that the key is an array of ref scalars, but not values.

Does anyone have any ideas? I am sure that I am not the first to understand various data structures. I want to test to make sure that the “signature” of the data structure is untouched, but I don't care less about the data in it or the regular expression matching, etc.

+3
source share
2 answers

You can easily write your own test functions using the functions Test :: Builder and Test :: More .

, , , , , - . .

use Test::Builder;
use Test::More 0.81_01;

sub is_arrayref_of_nonrefs
{
    my $value = shift;

    local $Test::Builder::Level = $Test::Builder::Level + 1;

    return Test::More::ok(0, 'value is an arrayref')
        if not ref $value or ref $value ne 'ARRAY';

    # fail if any references are found in the arrayref
    Test::More::ok((grep { ref } @$value), 'value is an arrayref of non-references');
}
+2

Test:: More isa_ok :

isa_ok( $array_ref, 'ARRAY' );
+1

All Articles