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

Re: Writing our own modules in Test2

Thread Previous | Thread Next
From:
Buddy Burden
Date:
June 24, 2016 21:41
Subject:
Re: Writing our own modules in Test2
Message ID:
576DA909.70602@gmail.com
Andy,

> I’ve accumulated a number of test functions in our work codebase for
> doing what I call “expressive” tests to avoid common cut & paste.  I’m
> using the term “expressive” for now because they’re expressing what it
> is you want, rather than making you write the code that explains them.

Sounds good.  I would definitely use such a module.

> is_empty_array( $foo );
> is_nonempty_array( $foo );
>
> because I believe that it’s easier to read the English “is empty array”
> than to translate “is( scalar @{$foo}, 0 )” into that meaning.

*Plus* it gives you an opportunity to display better diagnostics.  E.g. 
"okay, test failed, so the array's not _empty_ ... but what the hell is 
in it?"  This is exactly why I wrote:

     is_true($val);
     is_false($val);

Because with just `ok($val)` you can tell whether it's true or false, 
but, when it inevitably fails, you really want to know what the bad 
value turned out to be.

Anywho, things like this are, as you say, simple to write, but valuable 
in several different ways.


		-- Buddy

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