#!/usr/bin/perl -w use strict; use Test::Harness; use Getopt::Long; use Pod::Usage; use TestConnection qw($dbh); my $sql = <<'END_SQL'; SELECT relname FROM pg_class WHERE relkind = 'r' END_SQL my $sth = $dbh->prepare($sql); $sth->execute; my %tables; while (my $table = $sth->fetchrow_array) { # assumes that no app tables start with pg_ unless ('pg_' eq substr $table, 0, 3) { $tables{$table} = count_records($table); } } sub count_records { my $table = shift; my $sth = $dbh->prepare("SELECT count(*) FROM $table"); $sth->execute; my ($count) = $sth->fetchrow_array; $sth->finish; return $count; } GetOptions( 'help|?' => sub { pod2usage(-verbose => 2); exit }, 'verbose!' => \$Test::Harness::verbose, 'quiet' => sub { $Test::Harness::verbose = 0 }, 'fast' => \$ENV{FAST_TESTS}, 'include=s' => \my @include, 'exclude=s' => \my @exclude ); @include = map { glob } @include; @exclude = map { glob } @exclude; BEGIN { chdir 't' if -d 't'; } my @files = @include; unless (@files) { @files = glob "*.t"; } my @tests; foreach my $file ( sort @files ) { push @tests => $file unless grep { /\Q$file\E/ } @exclude; } runtests( @tests ); print "\n\n"; foreach my $table (sort keys %tables) { my $count = count_records($table); unless ($count == $tables{$table}) { print "$table started with $tables{$table} records and ended with $count records\n"; } } __DATA__ POD snipped