7fc3da2
From 1fd98154c60e0ab1d03f703f23b6775aed2bfc68 Mon Sep 17 00:00:00 2001
7fc3da2
From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= <ppisar@redhat.com>
7fc3da2
Date: Thu, 11 Sep 2014 10:35:29 +0200
7fc3da2
Subject: [PATCH] Expect unknown exception while loading CPAN configuration
7fc3da2
MIME-Version: 1.0
7fc3da2
Content-Type: text/plain; charset=UTF-8
7fc3da2
Content-Transfer-Encoding: 8bit
7fc3da2
7fc3da2
If DNS resolution does not work, CPAN run for the first time could not
7fc3da2
load its configuration and returns different exception than
7fc3da2
t/02_main.t expects.
7fc3da2
7fc3da2
This patch removes the bogus test and wrappes the exception to
7fc3da2
provide better explanation pointing to the CPAN as the culprit.
7fc3da2
7fc3da2
CPAN RT#98774
7fc3da2
7fc3da2
Signed-off-by: Petr Písař <ppisar@redhat.com>
7fc3da2
---
7fc3da2
 lib/CPAN/Inject.pm | 13 +++++++++----
7fc3da2
 t/02_main.t        | 11 ++---------
7fc3da2
 2 files changed, 11 insertions(+), 13 deletions(-)
7fc3da2
7fc3da2
diff --git a/lib/CPAN/Inject.pm b/lib/CPAN/Inject.pm
7fc3da2
index 86cf9ea..89fb120 100644
7fc3da2
--- a/lib/CPAN/Inject.pm
7fc3da2
+++ b/lib/CPAN/Inject.pm
7fc3da2
@@ -209,12 +209,17 @@ sub from_cpan_config {
7fc3da2
 	require Cwd;
7fc3da2
 	my $origin_working_directory = Cwd::getcwd;
7fc3da2
 
7fc3da2
-	# Support for different mechanisms depending on the version
7fc3da2
-	# of CPAN that is in use.
7fc3da2
-	if ( defined $CPAN::HandleConfig::VERSION ) {
7fc3da2
+	eval {
7fc3da2
+	    # Support for different mechanisms depending on the version
7fc3da2
+	    # of CPAN that is in use.
7fc3da2
+	    if ( defined $CPAN::HandleConfig::VERSION ) {
7fc3da2
 		CPAN::HandleConfig->load;
7fc3da2
-	} else {
7fc3da2
+	    } else {
7fc3da2
 		CPAN::Config->load;
7fc3da2
+	    }
7fc3da2
+	};
7fc3da2
+	if ($@) {
7fc3da2
+	    die "CPAN could not load its configuration: $@";
7fc3da2
 	}
7fc3da2
 
7fc3da2
 	# Restore working directory in case CPAN has changed it, RT#94963
7fc3da2
diff --git a/t/02_main.t b/t/02_main.t
7fc3da2
index 4686a7e..3e1b7a6 100644
7fc3da2
--- a/t/02_main.t
7fc3da2
+++ b/t/02_main.t
7fc3da2
@@ -8,7 +8,7 @@ BEGIN {
7fc3da2
 	$^W = 1;
7fc3da2
 }
7fc3da2
 
7fc3da2
-use Test::More tests => 24;
7fc3da2
+use Test::More tests => 23;
7fc3da2
 use File::Spec::Functions ':ALL';
7fc3da2
 use File::Remove          'remove';
7fc3da2
 use CPAN::Inject;
7fc3da2
@@ -76,14 +76,7 @@ SCOPE: {
7fc3da2
 			);
7fc3da2
 	};
7fc3da2
 	SKIP: {
7fc3da2
-		skip( "Current user owns CPAN::Config", 1 ) unless $@;
7fc3da2
-		like($@,
7fc3da2
-			qr/(The directory .* does not exist|The sources directory is not owned by the current user)/, 
7fc3da2
-			'Got expected error',
7fc3da2
-		);
7fc3da2
-	}
7fc3da2
-	SKIP: {
7fc3da2
-		skip( "Current user does not own CPAN::Config", 2 ) if $@;
7fc3da2
+		skip( "Error while loading CPAN configuration ($@)", 2 ) if $@;
7fc3da2
 		isa_ok( $cpan, 'CPAN::Inject' );
7fc3da2
 		is( $cpan->author,  'ADAMK',  '->author ok' );
7fc3da2
 	}
7fc3da2
-- 
7fc3da2
1.9.3
7fc3da2