From: Graham Knop Date: Tue, 4 Mar 2014 02:46:23 +0000 (-0500) Subject: tests for _load_module X-Git-Tag: v1.003003~7 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=f579af32f2f8604645f404ec78cbe5506679a648;p=gitmo%2FRole-Tiny.git tests for _load_module --- diff --git a/t/lib/BrokenModule.pm b/t/lib/BrokenModule.pm new file mode 100644 index 0000000..6271159 --- /dev/null +++ b/t/lib/BrokenModule.pm @@ -0,0 +1,6 @@ +package BrokenModule; +use strict; +use warnings; + +my $f = blorp; +1; diff --git a/t/lib/FalseModule.pm b/t/lib/FalseModule.pm new file mode 100644 index 0000000..9e7ae7a --- /dev/null +++ b/t/lib/FalseModule.pm @@ -0,0 +1,3 @@ +package FalseModule; + +0; diff --git a/t/lib/TrackLoad.pm b/t/lib/TrackLoad.pm new file mode 100644 index 0000000..d3e58c5 --- /dev/null +++ b/t/lib/TrackLoad.pm @@ -0,0 +1,4 @@ +package TrackLoad; +our $LOADED; +$LOADED++; +1; diff --git a/t/load-module.t b/t/load-module.t new file mode 100644 index 0000000..84f1338 --- /dev/null +++ b/t/load-module.t @@ -0,0 +1,32 @@ +use strict; +use warnings FATAL => 'all'; +use Test::More; +use Test::Fatal; + +use Role::Tiny (); + +use lib 't/lib'; + +{ + package TrackLoad; + our $LOADED = 0; +} + +Role::Tiny::_load_module('TrackLoad'); +is $TrackLoad::LOADED, 0, 'modules not loaded if symbol table entries exist'; + +eval { Role::Tiny::_load_module('BrokenModule') }; +like "$@", qr/Compilation failed/, + 'broken modules throw errors'; +eval { require BrokenModule }; +like "$@", qr/Compilation failed/, + ' ... and still fail if required again'; + +eval { Role::Tiny::_load_module('FalseModule') }; +like "$@", qr/did not return a true value/, + 'modules returning false throw errors'; +eval { require FalseModule }; +like "$@", qr/did not return a true value/, + ' ... and still fail if required again'; + +done_testing;