Created
December 1, 2009 00:26
-
-
Save jshirley/245926 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use Test::More; | |
use DateTime; | |
use MyApp::Types; | |
# We get a method for returning all defined types | |
foreach my $type ( MyApp::Types->type_names ) { | |
# Do we have a main::test_Whatever? | |
my $code = __PACKAGE__->can("test_$type"); | |
if ( $code ) { | |
# Yes, lets run it and pass in the code | |
# reference for typechecking. | |
# Remember, ->can returns a code ref! | |
$code->( MyApp::Types->can("is_$type") ); | |
} else { | |
# Lets be noisy until everyone does their part! | |
TODO: { | |
local $TODO = "No test_$type method defined"; | |
ok( 1 == 0, "write a test_$type method"); | |
} | |
} | |
} | |
done_testing; | |
# Define all the tests below here: | |
sub test_DateTimeAfterToday { | |
my ( $type_check ) = @_; | |
my $yesterday = DateTime->now; | |
my $tomorrow = DateTime->now->add( days => 1 ); | |
ok( !$type_check->( $yesterday ), "yesterday fails" ); | |
ok( $type_check->( $tomorrow ), "tomorrow passes" ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment