LibDirs::Perl probe tests
Robert 'phaylon' Sedlacek [Tue, 8 May 2012 19:25:42 +0000 (19:25 +0000)]
t/data/libdir/perl/lib/perl5/Foo.pm [new file with mode: 0644]
t/libdirs-perl.t [new file with mode: 0644]

diff --git a/t/data/libdir/perl/lib/perl5/Foo.pm b/t/data/libdir/perl/lib/perl5/Foo.pm
new file mode 100644 (file)
index 0000000..d781edd
--- /dev/null
@@ -0,0 +1,5 @@
+package Foo;
+
+our $VERSION = 0.001;
+
+1;
diff --git a/t/libdirs-perl.t b/t/libdirs-perl.t
new file mode 100644 (file)
index 0000000..799a7da
--- /dev/null
@@ -0,0 +1,35 @@
+use strictures 1;
+use Test::More;
+use FindBin;
+
+use System::Introspector::LibDirs::Perl;
+
+my $dir = "$FindBin::Bin/data/libdir/perl";
+
+no warnings 'redefine';
+*System::Introspector::LibDirs::Perl::_open_locate_libdirs_pipe = sub {
+    my $output = "$dir/lib/perl5\n";
+    open my $fh, '<', \$output;
+    return $fh;
+};
+
+my $probe = System::Introspector::LibDirs::Perl->new(
+    root => $dir,
+);
+my $data = $probe->gather;
+
+my $sha = delete $data->{"$dir/lib/perl5"}{Foo}[0]{sha256_hex};
+ok $sha, 'contains SHA fingerprint';
+
+my $size = delete $data->{"$dir/lib/perl5"}{Foo}[0]{size};
+ok $size, 'contains file size';
+
+is_deeply $data, {
+    "$dir/lib/perl5" => {
+        Foo => [
+            { file => "$dir/lib/perl5/Foo.pm", version => 0.001 },
+        ],
+    },
+}, 'package found';
+
+done_testing;