develooper Front page | perl.qa | Postings from July 2016

Re: Test2::Tools::Compare is vs. like

Thread Previous | Thread Next
From:
Andy Lester
Date:
July 27, 2016 15:34
Subject:
Re: Test2::Tools::Compare is vs. like
Message ID:
F9E302AA-D64F-4EF9-889D-ED8A968687D9@petdance.com

> On Jul 27, 2016, at 10:13 AM, Chad Granum <exodist7@gmail.com> wrote:
> 
> Specifically "This will ignore hash keys or array indexes that you do not actually specify in your $expect structure." directly documents the behavior.
> 


Right.  That is a fact that is clearly spelled out.  I think it would be helpful to have something that is higher level, that explains when you use which, and examples for each.

For instance, it might be something like (if my understanding is correct).

    my $employee = get_employee();
    my $expected_employee = { name => ‘Bob’, dept => ‘IT’ };

    # If you want to check the API, and ensure that get_employee() returns two and only two fields:
    is( get_employee(), $expected_employee );

    # If you want to check that you got the right record, but don’t care if it comes back with, say, a phone_number field:
    like( get_employee(), $expected_employee );

Also, when do you have to use the hash/field construction system?

    is( $employee, { name => 'Bob', dept => 'IT' } );
    like( $employee, { name => 'Bob', dept => 'IT' } );
    is( $employee, hash {
            field name => 'Bob';
            field dept => 'IT';
        }   
    );

When is it appropriate to use each of these?  Is it an error to mix like() and hash()/field()?

An example of calling like() on coderefs ("The same is true for coderefs, the value is passed in as the first argument (and in $_) and the sub should return a boolean value.”) would be good, too.

I’d be glad to write the docs if I knew the answers to the questions and the zen of what to use when.

As a newbie to Test2, I’d really like to start using it as much as possible, but I’m also afraid of screwing up existing tests because I use a new tool incorrectly.

Andy


--
Andy Lester => www.petdance.com


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About