From 576c62dbe64c582eb94ad60fd4782ab4b3057bf0 Mon Sep 17 00:00:00 2001 From: amacleay Date: Tue, 7 Jan 2014 11:52:07 -0500 Subject: Do not die if last require failed --- lib/Class/Refresh.pm | 11 ++++++++++- t/basic.t | 12 ++++++++++++ t/data/basic/after/UseFake.pm | 5 +++++ 3 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 t/data/basic/after/UseFake.pm diff --git a/lib/Class/Refresh.pm b/lib/Class/Refresh.pm index eb1dda8..320490d 100644 --- a/lib/Class/Refresh.pm +++ b/lib/Class/Refresh.pm @@ -187,11 +187,20 @@ sub load_module { my ($mod) = @_; $mod = $class->_file_to_mod($mod); + my $file = $class->_mod_to_file($mod); + my $last_require_failed = exists $INC{$file} && !defined $INC{$file}; + try { Class::Load::load_class($mod); } catch { - die $_; + if ($last_require_failed) { + # This file failed to load previously. + # Presumably that error has already been caught, so that's fine + } + else { + die $_; + } } finally { $class->_update_cache_for($mod); diff --git a/t/basic.t b/t/basic.t index 9b7eb8a..93e0772 100644 --- a/t/basic.t +++ b/t/basic.t @@ -2,8 +2,10 @@ use strict; use warnings; use Test::More; +use Test::Fatal; use lib 't/lib'; use Test::Class::Refresh; +use Try::Tiny; use Class::Refresh; @@ -37,4 +39,14 @@ is(eval '$Foo::FOO', 10, "package global exists with new value"); ok(!defined(eval '$Foo::BAR'), "other package global doesn't exist"); is(eval '$Foo::BAZ', 30, "third package global exists"); +try { require UseFake } catch { "We expect this to fail, that's alright and happens sometimes" }; +Class::Refresh->refresh; +ok(exists $INC{'UseFake.pm'}, "Failed package \$INC value exists"); +ok(!defined $INC{'UseFake.pm'}, "Failed package \$INC value is not defined after failed load"); + +# Now do the same thing to validate that there's no error in repopulating %CACHE +isnt(exception{ Class::Refresh->refresh }, "Second refresh is not an error"); +ok(exists $INC{'UseFake.pm'}, "Failed package \$INC value exists: second attempt"); +ok(!defined $INC{'UseFake.pm'}, "Failed package \$INC value is not defined after failed load: second attempt"); + done_testing; diff --git a/t/data/basic/after/UseFake.pm b/t/data/basic/after/UseFake.pm new file mode 100644 index 0000000..efc0d3e --- /dev/null +++ b/t/data/basic/after/UseFake.pm @@ -0,0 +1,5 @@ +package RequiresFake; + +use Fake; + +1; -- cgit v1.2.3 From a117735e35a304fbf9a1c1ad1139d2845e2bf39e Mon Sep 17 00:00:00 2001 From: amacleay Date: Fri, 10 Jan 2014 11:14:29 -0500 Subject: Fix to prevent Travis CI fail --- t/basic.t | 10 +++++----- t/data/basic/after/Bar.pm | 5 +++++ t/data/basic/after/UseFake.pm | 5 ----- 3 files changed, 10 insertions(+), 10 deletions(-) create mode 100644 t/data/basic/after/Bar.pm delete mode 100644 t/data/basic/after/UseFake.pm diff --git a/t/basic.t b/t/basic.t index 93e0772..9cf56a8 100644 --- a/t/basic.t +++ b/t/basic.t @@ -39,14 +39,14 @@ is(eval '$Foo::FOO', 10, "package global exists with new value"); ok(!defined(eval '$Foo::BAR'), "other package global doesn't exist"); is(eval '$Foo::BAZ', 30, "third package global exists"); -try { require UseFake } catch { "We expect this to fail, that's alright and happens sometimes" }; +try { require Bar } catch { "We expect this to fail, that's alright and happens sometimes" }; Class::Refresh->refresh; -ok(exists $INC{'UseFake.pm'}, "Failed package \$INC value exists"); -ok(!defined $INC{'UseFake.pm'}, "Failed package \$INC value is not defined after failed load"); +ok(exists $INC{'Bar.pm'}, "Failed package \$INC value exists"); +ok(!defined $INC{'Bar.pm'}, "Failed package \$INC value is not defined after failed load"); # Now do the same thing to validate that there's no error in repopulating %CACHE isnt(exception{ Class::Refresh->refresh }, "Second refresh is not an error"); -ok(exists $INC{'UseFake.pm'}, "Failed package \$INC value exists: second attempt"); -ok(!defined $INC{'UseFake.pm'}, "Failed package \$INC value is not defined after failed load: second attempt"); +ok(exists $INC{'Bar.pm'}, "Failed package \$INC value exists: second attempt"); +ok(!defined $INC{'Bar.pm'}, "Failed package \$INC value is not defined after failed load: second attempt"); done_testing; diff --git a/t/data/basic/after/Bar.pm b/t/data/basic/after/Bar.pm new file mode 100644 index 0000000..06875fb --- /dev/null +++ b/t/data/basic/after/Bar.pm @@ -0,0 +1,5 @@ +package Bar; + +use Bar::Fake; + +1; diff --git a/t/data/basic/after/UseFake.pm b/t/data/basic/after/UseFake.pm deleted file mode 100644 index efc0d3e..0000000 --- a/t/data/basic/after/UseFake.pm +++ /dev/null @@ -1,5 +0,0 @@ -package RequiresFake; - -use Fake; - -1; -- cgit v1.2.3