For Type::Tiny I had these functions should_pass and should_fail along the lines of:
sub should_pass { my ($value, $constraint) = @_; ok( $constraint->check($value) ); } sub should_fail { my ($value, $constraint) = @_; ok( not $constraint->check($value) ); } should_pass(2222222, Int); should_fail(3.14159, Int);
Because the functions were copied-and-pasted into several different files, I factored them out into a .pm file in the "t" directory, then eventually renamed it Test::TypeTiny, documented it and moved it into "lib", so that it's a reusable testing module for people creating Type::Tiny-based type libraries.
Having these functions in one place instead of scattered about has allowed me to make improvements to them which benefit the entire test suite. For example, recently I added a "pedantic mode" which is triggered by $ENV{EXTENDED_TESTING}.
In reply to Re: Eliminating duplicated code in multiple test scripts using Test::More
by tobyink
in thread Eliminating duplicated code in multiple test scripts using Test::More
by eyepopslikeamosquito
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |