Committed by Greg Sabino Mullane <[email protected]>

Overhaul t/00_release.t: add in new dbdimp.c version
string. In the process, refactor everything into a single hash, and verify
the number of version strings per file as well.

---
 t/00_release.t | 104 +++++++++++++++++++++++++++------------------------------
 1 file changed, 49 insertions(+), 55 deletions(-)

diff --git a/t/00_release.t b/t/00_release.t
index 7a59769..3b70a92 100644
--- a/t/00_release.t
+++ b/t/00_release.t
@@ -12,73 +12,66 @@ use lib 't','.';
 if (! $ENV{RELEASE_TESTING}) {
        plan (skip_all =>  'Test skipped unless environment variable 
RELEASE_TESTING is set');
 }
-plan tests => 1;
+plan tests => 2;
 
-my %v;
 my $vre = qr{(\d+\.\d+\.\d+\_?\d*)};
 
-## Grab version from various files
-my $file = 'META.yml';
-open my $fh, '<', $file or die qq{Could not open "$file": $!\n};
-while (<$fh>) {
-       push @{$v{$file}} => [$1,$.] if /version\s*:\s*$vre/;
-}
-close $fh or warn qq{Could not close "$file": $!\n};
+my %filelist = (
+       'dbdimp.c'             => [1, [ qr{ping test v$vre},        ]],
+       'META.yml'             => [3, [ qr{version\s*:\s*$vre},     ]],
+       'Pg.pm'                => [3, [ qr{VERSION = qv\('$vre'},
+                                               qr{documents version $vre},
+                                    qr{ping test v$vre},        ]],
+       'lib/Bundle/DBD/Pg.pm' => [1, [ qr{VERSION = '$vre'},       ]],
+       'Makefile.PL'          => [1, [ qr{VERSION = '$vre'},       ]],
+       'README'               => [1, [ qr{is version $vre},
+                                    qr{TEST VERSION \($vre},    ]],
+       'Changes'              => [1, [ qr{^(?:Version )*$vre},     ]],
+);
 
-$file = 'Makefile.PL';
-open $fh, '<', $file or die qq{Could not open "$file": $!\n};
-while (<$fh>) {
-       push @{$v{$file}} => [$1,$.] if /VERSION = '$vre'/;
-}
-close $fh or warn qq{Could not close "$file": $!\n};
+my %v;
+my $goodversion = 1;
+my $goodcopies = 1;
+my $lastversion = '?';
 
-$file = 'Pg.pm';
-open $fh, '<', $file or die qq{Could not open "$file": $!\n};
-while (<$fh>) {
-       push @{$v{$file}} => [$1,$.] if (/VERSION = qv\('$vre'/ or /documents 
version $vre/);
-}
-close $fh or warn qq{Could not close "$file": $!\n};
+## Walk through each file and slurp out the version numbers
+## Make sure that the version number matches
+## Verify the total number of version instances in each file as well
 
-$file = 'lib/Bundle/DBD/Pg.pm';
-open $fh, '<', $file or die qq{Could not open "$file": $!\n};
-while (<$fh>) {
-       push @{$v{$file}} => [$1,$.] if /VERSION = '$vre'/;
-}
-close $fh or warn qq{Could not close "$file": $!\n};
-
-$file = 'Changes';
-open $fh, '<', $file or die qq{Could not open "$file": $!\n};
-while (<$fh>) {
-       if (/^(?:Version )*$vre/) {
-               push @{$v{$file}} => [$1,$.];
-               last;
+for my $file (sort keys %filelist) {
+       my ($expected,$regexlist) = @{ $filelist{$file} };
+       #diag "Want file $file to have $expected";
+
+       my $instances = 0;
+       open my $fh, '<', $file or die qq{Could not open "$file": $!\n};
+  SLURP: while (<$fh>) {
+               for my $regex (@{ $regexlist }) {
+                       if ($_ =~ /$regex/) {
+                               push @{$v{$file}} => [$1, $.];
+                               $instances++;
+                               last SLURP if $file eq 'Changes'; ## Only the 
top version please
+                       }
+               }
        }
+       close $fh or warn qq{Could not close "$file": $!\n};
+
+       if ($instances != $expected) {
+               $goodcopies = 0;
+               diag "Version instance mismatch for $file: expected $expected, 
found $instances";
+       }
+
 }
-close $fh or warn qq{Could not close "$file": $!\n};
 
-$file = 'README';
-open $fh, '<', $file or die qq{Could not open "$file": $!\n};
-while (<$fh>) {
-       push @{$v{$file}} => [$1,$.] if (/is version $vre/ or /TEST VERSION 
\($vre/);
+
+if ($goodcopies) {
+       pass ('All files had the expected number of version strings');
 }
-close $fh or warn qq{Could not close "$file": $!\n};
-
-my $good = 1;
-my $lastver;
-for my $filename (keys %v) {
-       for my $glob (@{$v{$filename}}) {
-               my ($ver,$line) = @$glob;
-               if (! defined $lastver) {
-                       $lastver = $ver;
-               }
-               elsif ($ver ne $lastver) {
-                       $good = 0;
-               }
-       }
+else {
+       fail ('All files did not have the expected number of version strings');
 }
 
-if ($good) {
-       pass ("All version numbers are the same ($lastver)");
+if ($goodversion) {
+       pass ("All version numbers are the same ($lastversion)");
 }
 else {
        fail ('All version numbers were not the same!');
@@ -91,3 +84,4 @@ else {
 }
 
 exit;
+
-- 
1.8.4

Reply via email to