From 34116d3816ac0425bb0e787be266abade3e501c0 Mon Sep 17 00:00:00 2001 From: David Steele Date: Sun, 11 Jan 2015 11:52:16 -0500 Subject: [PATCH] Added usage to test.pl and automatic search for psql-bin. --- test/test.pl | 91 +++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 83 insertions(+), 8 deletions(-) diff --git a/test/test.pl b/test/test.pl index 0512f5192..d589399be 100755 --- a/test/test.pl +++ b/test/test.pl @@ -13,7 +13,7 @@ use Carp; use File::Basename; use Getopt::Long; use Cwd 'abs_path'; -use Cwd; +use Pod::Usage; use lib dirname($0) . '/../lib'; use BackRest::Utility; @@ -24,10 +24,40 @@ use BackRestTest::UtilityTest; use BackRestTest::FileTest; use BackRestTest::BackupTest; +#################################################################################################################################### +# Usage +#################################################################################################################################### + +=head1 NAME + +test.pl - Simple Postgres Backup and Restore Unit Tests + +=head1 SYNOPSIS + +test.pl [options] + + Test Options: + module test module to execute: + module-test execute the specified test in a module + module-test-run execute only the specified test run + dry-run show only the tests that would be executed but don't execute them + no-cleanup don't cleaup after the last test is complete - useful for debugging + + Configuration Options: + --psql-bin path to the psql executables (e.g. /usr/lib/postgresql/9.3/bin/) + --test-path path where tests are executed (defaults to ./test) + --log-level log level to use for tests (defaults to INFO) + --quiet, -q equivalent to --log-level=off + + General Options: + --version display version and exit + --help display usage and exit +=cut + #################################################################################################################################### # Command line parameters #################################################################################################################################### -my $strLogLevel = 'off'; # Log level for tests +my $strLogLevel = 'info'; # Log level for tests my $strModule = 'all'; my $strModuleTest = 'all'; my $iModuleTestRun = undef; @@ -35,8 +65,14 @@ my $bDryRun = false; my $bNoCleanup = false; my $strPgSqlBin; my $strTestPath; +my $bVersion = false; +my $bHelp = false; +my $bQuiet = false; -GetOptions ('pgsql-bin=s' => \$strPgSqlBin, +GetOptions ('q|quiet' => \$bQuiet, + 'version' => \$bVersion, + 'help' => \$bHelp, + 'pgsql-bin=s' => \$strPgSqlBin, 'test-path=s' => \$strTestPath, 'log-level=s' => \$strLogLevel, 'module=s' => \$strModule, @@ -44,7 +80,21 @@ GetOptions ('pgsql-bin=s' => \$strPgSqlBin, 'module-test-run=s' => \$iModuleTestRun, 'dry-run' => \$bDryRun, 'no-cleanup' => \$bNoCleanup) - or die 'error in command line arguments'; + or pod2usage(2); + +# Display version and exit if requested +if ($bVersion || $bHelp) +{ + print 'pg_backrest ' . version_get() . " unit test\n"; + + if ($bHelp) + { + print "\n"; + pod2usage(); + } + + exit 0; +} #################################################################################################################################### # Setup @@ -52,7 +102,12 @@ GetOptions ('pgsql-bin=s' => \$strPgSqlBin, # Set a neutral umask so tests work as expected umask(0); -# Set console log level to trace for testing +# Set console log level +if ($bQuiet) +{ + $strLogLevel = 'off'; +} + log_level_set(undef, uc($strLogLevel)); if ($strModuleTest ne 'all' && $strModule eq 'all') @@ -65,10 +120,30 @@ if (defined($iModuleTestRun) && $strModuleTest eq 'all') confess "--module-test must be provided for run \"${iModuleTestRun}\""; } -# Make sure PG bin has been defined +# Search for psql bin if (!defined($strPgSqlBin)) { - confess 'pgsql-bin was not defined'; + my @strySearchPath = ('/usr/lib/postgresql/VERSION/bin', '/Library/PostgreSQL/VERSION/bin'); + + foreach my $strSearchPath (@strySearchPath) + { + for (my $fVersion = 9; $fVersion >= 0; $fVersion -= 1) + { + my $strVersionPath = $strSearchPath; + $strVersionPath =~ s/VERSION/9\.$fVersion/g; + + if (-e "${strVersionPath}/initdb") + { + &log(INFO, "found pgsqlbin at ${strVersionPath}\n"); + $strPgSqlBin = ${strVersionPath}; + } + } + } + + if (!defined($strPgSqlBin)) + { + confess 'pgsql-bin was not defined and could not be located'; + } } #################################################################################################################################### @@ -144,5 +219,5 @@ if ($strModule eq 'all' || $strModule eq 'backup') if (!$bDryRun) { - &log(ASSERT, 'TESTS COMPLETED SUCCESSFULLY (DESPITE ANY ERROR MESSAGES YOU SAW)'); + &log(INFO, 'TESTS COMPLETED SUCCESSFULLY (DESPITE ANY ERROR MESSAGES YOU SAW)'); }