[libcatmandu-perl] 85/101: file test in Importer

Jonas Smedegaard dr at jones.dk
Tue Feb 23 13:43:59 UTC 2016


This is an automated email from the git hooks/post-receive script.

js pushed a commit to branch master
in repository libcatmandu-perl.

commit 22c5dc2715a6b84be0729ee81bd4b0ecc13d2ece
Author: Nicolas Steenlant <nicolas.steenlant at ugent.be>
Date:   Tue Feb 9 16:02:33 2016 +0100

    file test in Importer
---
 Changes                  | 2 ++
 lib/Catmandu/Importer.pm | 3 +++
 t/Catmandu-Importer.t    | 3 +++
 3 files changed, 8 insertions(+)

diff --git a/Changes b/Changes
index 2701ed9..33715bc 100644
--- a/Changes
+++ b/Changes
@@ -1,6 +1,8 @@
 Revision history for Catmandu
 
 {{$NEXT}}
+  - fix os-dependent paths in tests
+  - throw an error if an Importer file path doesn't exist
 
 1.00_02  2016-02-09 10:17:58 CET
   - bump required version of URI::Template because we need variable names
diff --git a/lib/Catmandu/Importer.pm b/lib/Catmandu/Importer.pm
index c11ca0e..33b85da 100644
--- a/lib/Catmandu/Importer.pm
+++ b/lib/Catmandu/Importer.pm
@@ -78,6 +78,9 @@ sub _build_file {
         }
         $file = $template->process_to_string(%$vars);
     }
+    if (is_string($file) && $file !~ m!^https?://! && ! -f $file) {
+        Catmandu::BadArg->throw("file '$file' doesn't exist");
+    }
     $file;
 }
 
diff --git a/t/Catmandu-Importer.t b/t/Catmandu-Importer.t
index 3ab2bff..bb9038e 100644
--- a/t/Catmandu-Importer.t
+++ b/t/Catmandu-Importer.t
@@ -52,6 +52,9 @@ is_deeply $i->to_array, [{ hello => "World"}], 'import from string reference';
 $i = T::Importer->new( file => \"Hello\nWorld" );
 is join('',$i->fh->getlines), "Hello\nWorld", "import all";
 
+$i = T::Importer->new( file => "missing" );
+throws_ok { $i->fh->getlines } "Catmandu::BadArg", "throws an error if file doesn't exist";
+
 $i = T::DataPathImporter->new;
 is_deeply $i->to_array, [{abc => [{a=>1},{b=>2},{c=>3}]},{abc => [{d=>4},{e=>5},{f=>6}]}];
 $i = T::DataPathImporter->new(data_path => 'abc');

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-perl/packages/libcatmandu-perl.git



More information about the Pkg-perl-cvs-commits mailing list