diff options
author | Greg Sabino Mullane | 2009-04-29 19:48:23 +0000 |
---|---|---|
committer | Greg Sabino Mullane | 2009-04-29 19:48:23 +0000 |
commit | dca09b4507d2e4009e38ecee35e1ae69b05dae1d (patch) | |
tree | cf3be70f6616273e1a772f8515afe80d2448120b | |
parent | bc87f1cc0561d56b0a5b0e94fba49af03cdc62e4 (diff) |
Many Perl::Critic related cleanups.
41 files changed, 124 insertions, 126 deletions
diff --git a/.perlcriticrc b/.perlcriticrc index 1de41f254..b10f0b347 100644 --- a/.perlcriticrc +++ b/.perlcriticrc @@ -23,6 +23,7 @@ stop_words = Mullane Nagios Slony nols salesrep psql dbname postgres USERNAME us [-Documentation::RequirePodAtEnd] [-Documentation::RequirePodSections] [-Documentation::RequirePODUseEncodingUTF8] +[-Editor::RequireEmacsFileVariables] [-ErrorHandling::RequireCarping] [-ErrorHandling::RequireCheckingReturnValueOfEval] [-ErrorHandling::RequireUseOfExceptions] diff --git a/t/00_basic.t b/t/00_basic.t index dd58b71e0..a08435a06 100644 --- a/t/00_basic.t +++ b/t/00_basic.t @@ -2,13 +2,13 @@ ## Simply test that the script compiles and gives a valid version +use 5.006; use strict; use warnings; use Test::More tests => 2; -select(($|=1,select(STDERR),$|=1)[1]); eval { - require 'check_postgres.pl'; + require 'check_postgres.pl'; ## no critic (RequireBarewordIncludes) }; like($@, qr{\-\-help}, 'check_postgres.pl compiles'); diff --git a/t/00_signature.t b/t/00_signature.t index e8e05cd1f..358861407 100644 --- a/t/00_signature.t +++ b/t/00_signature.t @@ -7,7 +7,6 @@ use 5.006; use strict; use warnings; use Test::More; -select(($|=1,select(STDERR),$|=1)[1]); my $sigfile = 'check_postgres.pl.asc'; diff --git a/t/00_test_tester.t b/t/00_test_tester.t index 97fdc008f..150c6db3a 100644 --- a/t/00_test_tester.t +++ b/t/00_test_tester.t @@ -2,10 +2,10 @@ ## Make sure we have tests for all actions +use 5.006; use strict; use warnings; use Data::Dumper; -use DBI; use Test::More tests => 1; use lib 't','.'; use CP_Testing; diff --git a/t/02_autovac_freeze.t b/t/02_autovac_freeze.t index efe20767d..a24be524a 100644 --- a/t/02_autovac_freeze.t +++ b/t/02_autovac_freeze.t @@ -2,10 +2,10 @@ ## Test the "autovac_freeze" action +use 5.006; use strict; use warnings; use Data::Dumper; -use DBI; use Test::More tests => 8; use lib 't','.'; use CP_Testing; @@ -23,7 +23,7 @@ my $label = 'POSTGRES_AUTOVAC_FREEZE'; my $S = q{Action 'autovac_freeze'}; $t = qq{$S self-identifies correctly}; -$result = $cp->run(qq{-w 0%}); +$result = $cp->run(q{-w 0%}); like ($result, qr{^$label}, $t); $t = qq{$S identifies host}; diff --git a/t/02_backends.t b/t/02_backends.t index 1f079f925..73933c87c 100644 --- a/t/02_backends.t +++ b/t/02_backends.t @@ -2,6 +2,7 @@ ## Test the "backends" action +use 5.006; use strict; use warnings; use Data::Dumper; diff --git a/t/02_bloat.t b/t/02_bloat.t index b05c14fd4..72b02990c 100644 --- a/t/02_bloat.t +++ b/t/02_bloat.t @@ -2,6 +2,7 @@ ## Test the "bloat" action +use 5.006; use strict; use warnings; use Data::Dumper; @@ -26,7 +27,7 @@ $t=qq{$S fails when called with an invalid option}; like ($cp->run('-w=abc'), qr{must be a size or a percentage}, $t); like ($cp->run('-c=abc'), qr{must be a size or a percentage}, $t); -local $dbh->{AutoCommit} = 1; +$dbh->{AutoCommit} = 1; $dbh->do('VACUUM FULL'); $t=qq{$S returns ok for no bloat}; @@ -44,11 +45,11 @@ for my $size (qw/bytes kilobytes megabytes gigabytes terabytes exabytes petabyte } $t=qq{$S returns correct message if no tables due to exclusion}; -like ($cp->run("-w=1% --include=foobar"), qr{^$label UNKNOWN:.+No matching relations found due to exclusion}, $t); +like ($cp->run('-w=1% --include=foobar'), qr{^$label UNKNOWN:.+No matching relations found due to exclusion}, $t); ## Fresh database should have little bloat: $t=qq{$S returns okay for fresh database with no bloat}; -like ($cp->run("-w=1m"), qr{^$label OK: DB "postgres"}, $t); +like ($cp->run('-w=1m'), qr{^$label OK: DB "postgres"}, $t); $cp->drop_table_if_exists($tname); $dbh->do("CREATE TABLE $tname AS SELECT 123::int AS foo FROM generate_series(1,10000)"); diff --git a/t/02_checkpoint.t b/t/02_checkpoint.t index bff121085..e00813f1a 100644 --- a/t/02_checkpoint.t +++ b/t/02_checkpoint.t @@ -2,10 +2,10 @@ ## Test the "checkpoint" action +use 5.006; use strict; use warnings; use Data::Dumper; -use DBI; use Test::More tests => 13; use lib 't','.'; use CP_Testing; diff --git a/t/02_connection.t b/t/02_connection.t index b44d3a904..742a0f978 100644 --- a/t/02_connection.t +++ b/t/02_connection.t @@ -2,11 +2,10 @@ ## Test the "connection" action +use 5.006; use strict; use warnings; use Data::Dumper; -use DBI; -use Cwd; use Test::More tests => 12; use lib 't','.'; use CP_Testing; diff --git a/t/02_custom_query.t b/t/02_custom_query.t index 3eb835687..339f2ad03 100644 --- a/t/02_custom_query.t +++ b/t/02_custom_query.t @@ -2,12 +2,11 @@ ## Test the "custom_query" action +use 5.006; use strict; use warnings; use Data::Dumper; -use DBI; use Test::More tests => 11; - use lib 't','.'; use CP_Testing; diff --git a/t/02_database_size.t b/t/02_database_size.t index f84de05bd..9a6cf8de8 100644 --- a/t/02_database_size.t +++ b/t/02_database_size.t @@ -2,6 +2,7 @@ ## Test the "database_size" action +use 5.006; use strict; use warnings; use Data::Dumper; @@ -64,18 +65,18 @@ $dbh->do("CREATE DATABASE blargy WITH OWNER $user"); $dbh->{AutoCommit} = 0; like ($cp->run("--includeuser $user -w 10g"), qr{^POSTGRES_DATABASE_SIZE OK:.+ blargy}, $t); $dbh->{AutoCommit} = 1; -$dbh->do("DROP DATABASE blargy"); +$dbh->do('DROP DATABASE blargy'); $dbh->{AutoCommit} = 0; $t=qq{$S with includeuser option returns nothing}; -like ($cp->run("--includeuser mycatbeda -w 10g"), qr{^POSTGRES_DATABASE_SIZE OK:.+ }, $t); +like ($cp->run('--includeuser mycatbeda -w 10g'), qr{^POSTGRES_DATABASE_SIZE OK:.+ }, $t); $t=qq{$S has critical option trump the warning option}; like ($cp->run('-w 1 -c 1'), qr{^POSTGRES_DATABASE_SIZE CRITICAL}, $t); like ($cp->run('--critical=1 --warning=0'), qr{^POSTGRES_DATABASE_SIZE CRITICAL}, $t); $t=qq{$S returns correct MRTG output when no rows found}; -like ($cp->run("--output=MRTG -w 10g --includeuser nosuchuser"), qr{^-1}, $t); +like ($cp->run('--output=MRTG -w 10g --includeuser nosuchuser'), qr{^-1}, $t); $t=qq{$S returns correct MRTG output when rows found}; like ($cp->run('--output=MRTG -w 10g'), qr{\d+\n0\n\nDB: postgres\n}s, $t); @@ -99,6 +100,6 @@ $t=qq{$S returned correct performance data with include}; like ($cp->run('-w 5g --include=postgres'), qr{ \| time=\d\.\d\d postgres=\d+}, $t); $t=qq{$S with includeuser option returns nothing}; -like ($cp->run("--includeuser postgres --includeuser mycatbeda -w 10g"), qr{No matching entries found due to user exclusion}, $t); +like ($cp->run('--includeuser postgres --includeuser mycatbeda -w 10g'), qr{No matching entries found due to user exclusion}, $t); exit; diff --git a/t/02_dbstats.t b/t/02_dbstats.t index 24910cbb4..f06910135 100644 --- a/t/02_dbstats.t +++ b/t/02_dbstats.t @@ -2,10 +2,10 @@ ## Test the "dbstats" action +use 5.006; use strict; use warnings; use Data::Dumper; -use DBI; use Test::More tests => 42; use lib 't','.'; use CP_Testing; diff --git a/t/02_disabled_triggers.t b/t/02_disabled_triggers.t index dee8fe1b5..b163038f6 100644 --- a/t/02_disabled_triggers.t +++ b/t/02_disabled_triggers.t @@ -2,10 +2,10 @@ ## Test the "disabled_triggers" action +use 5.006; use strict; use warnings; use Data::Dumper; -use DBI; use Test::More tests => 13; use lib 't','.'; use CP_Testing; @@ -35,7 +35,7 @@ $t = qq{$S identifies host}; like ($result, qr{host:$host}, $t); $t = qq{$S accepts valid -w input}; -like ($cp->run(qq{-w 1}), qr/$label OK/, $t); +like ($cp->run(q{-w 1}), qr/$label OK/, $t); $t = qq{$S flags invalid -w input}; for (-1, 0, 'a') { @@ -43,7 +43,7 @@ for (-1, 0, 'a') { } $t = qq{$S accepts valid -c input}; -like ($cp->run(qq{-c 1}), qr/$label OK/, $t); +like ($cp->run(q{-c 1}), qr/$label OK/, $t); $t = qq{$S flags invalid -c input}; for (-1, 0, 'a') { @@ -73,9 +73,9 @@ $t = qq{$S counts disabled triggers}; $dbh->do(qq{ALTER TABLE "$testtbl" DISABLE TRIGGER "${testtrig_prefix}1"}); $dbh->do(qq{ALTER TABLE "$testtbl" DISABLE TRIGGER "${testtrig_prefix}2"}); $dbh->commit; -like ($cp->run(qq{-c 2}), qr/$label CRITICAL:.*?Disabled triggers: 2 /, $t); +like ($cp->run(q{-c 2}), qr/$label CRITICAL:.*?Disabled triggers: 2 /, $t); $t .= ' (MRTG)'; -is ($cp->run(qq{-c 2 --output=mrtg}), qq{2\n0\n\n\n}, $t); +is ($cp->run(q{-c 2 --output=mrtg}), qq{2\n0\n\n\n}, $t); exit; diff --git a/t/02_disk_space.t b/t/02_disk_space.t index 40dbd60f5..0f1a48ab8 100644 --- a/t/02_disk_space.t +++ b/t/02_disk_space.t @@ -2,10 +2,10 @@ ## Test the "disk_space" action +use 5.006; use strict; use warnings; use Data::Dumper; -use DBI; use Test::More tests => 7; use lib 't','.'; use CP_Testing; diff --git a/t/02_fsm_pages.t b/t/02_fsm_pages.t index ce02c8315..9b884c34f 100644 --- a/t/02_fsm_pages.t +++ b/t/02_fsm_pages.t @@ -2,6 +2,7 @@ ## Test the "fsm_pages" action +use 5.006; use strict; use warnings; use Data::Dumper; diff --git a/t/02_fsm_relations.t b/t/02_fsm_relations.t index 8ee30d8b3..d7ae557d0 100644 --- a/t/02_fsm_relations.t +++ b/t/02_fsm_relations.t @@ -2,6 +2,7 @@ ## Test the "fsm_relations" action +use 5.006; use strict; use warnings; use Data::Dumper; diff --git a/t/02_last_analyze.t b/t/02_last_analyze.t index 9865dd376..efa9461d8 100644 --- a/t/02_last_analyze.t +++ b/t/02_last_analyze.t @@ -2,10 +2,10 @@ ## Test the "last_analyze" action +use 5.006; use strict; use warnings; use Data::Dumper; -use DBI; use Test::More tests => 14; use lib 't','.'; use CP_Testing; @@ -24,7 +24,7 @@ my $label = 'POSTGRES_LAST_ANALYZE'; my $S = q{Action 'last_analyze'}; $t = qq{$S self-identifies correctly}; -$result = $cp->run(qq{-w 0}); +$result = $cp->run(q{-w 0}); like ($result, qr{^$label}, $t); $t = qq{$S identifies database}; @@ -50,9 +50,8 @@ for ('-1 second', } $t = qq{$S flags no-match-user}; -like ($cp->run(qq{-w 0 --includeuser=gandalf}), qr{No matching.*user}, $t); +like ($cp->run(q{-w 0 --includeuser=gandalf}), qr{No matching.*user}, $t); -local $dbh->{Warn}; $dbh->do('ANALYZE'); $cp->drop_table_if_exists($testtbl); $dbh->do(qq{CREATE TABLE $testtbl AS SELECT 123::INTEGER AS a FROM generate_series(1,200000)}); @@ -63,18 +62,18 @@ like ($cp->run("-w 0 --exclude=~.* --include=$testtbl"), qr{No matching tables found due to exclusion}, $t); $t = qq{$S sees a recent ANALYZE}; -$dbh->do(qq{SET default_statistics_target = 1000}); +$dbh->do(q{SET default_statistics_target = 1000}); $dbh->do(q{ANALYZE}); $dbh->commit(); sleep 1; like ($cp->run("-w 0 --include=$testtbl"), qr{^$label OK}, $t); $t = qq{$S returns correct MRTG information (OK case)}; -like ($cp->run("--output=mrtg -w 0 --include=$testtbl"), +like ($cp->run(qq{--output=mrtg -w 0 --include=$testtbl}), qr{^\d\n0\n\nDB: $dbname TABLE: public.$testtbl\n}, $t); $t = qq{$S returns correct MRTG information (fail case)}; -like($cp->run("--output=mrtg -w 0 --exclude=~.* --include=no_such_table"), +like($cp->run(q{--output=mrtg -w 0 --exclude=~.* --include=no_such_table}), qr{0\n0\n\nDB: $dbname TABLE: \?\n}, $t); exit; diff --git a/t/02_last_vacuum.t b/t/02_last_vacuum.t index 62b526296..53cd8e7a1 100644 --- a/t/02_last_vacuum.t +++ b/t/02_last_vacuum.t @@ -2,10 +2,10 @@ ## Test the "last_vacuum" action +use 5.006; use strict; use warnings; use Data::Dumper; -use DBI; use Test::More tests => 14; use lib 't','.'; use CP_Testing; @@ -24,7 +24,7 @@ my $label = 'POSTGRES_LAST_VACUUM'; my $S = q{Action 'last_vacuum'}; $t = qq{$S self-identifies correctly}; -$result = $cp->run(qq{-w 0}); +$result = $cp->run(q{-w 0}); like ($result, qr{^$label}, $t); $t = qq{$S identifies database}; @@ -50,10 +50,9 @@ for ('-1 second', } $t = qq{$S flags no-match-user}; -like ($cp->run(qq{-w 0 --includeuser=gandalf}), qr{No matching.*user}, $t); +like ($cp->run(q{-w 0 --includeuser=gandalf}), qr{No matching.*user}, $t); -local $dbh->{Warn}; -local $dbh->{AutoCommit} = 1; +$dbh->{AutoCommit} = 1; $dbh->do('VACUUM'); $cp->drop_table_if_exists($testtbl); $dbh->do(qq{CREATE TABLE $testtbl AS SELECT 123::INTEGER AS a FROM generate_series(1,200000)}); @@ -75,7 +74,7 @@ like ($cp->run("--output=mrtg -w 0 --exclude=~.* --include=$testtbl"), qr{\d+\n0\n\nDB: $dbname TABLE: public.$testtbl\n}, $t); $t = qq{$S returns correct MRTG information (fail case)}; -like ($cp->run("--output=mrtg -w 0 --exclude=~.* --include=no_such_table"), +like ($cp->run('--output=mrtg -w 0 --exclude=~.* --include=no_such_table'), qr{0\n0\n\nDB: $dbname TABLE: \?\n}, $t); exit; diff --git a/t/02_listener.t b/t/02_listener.t index 0edeb3ab9..cd47b34c5 100644 --- a/t/02_listener.t +++ b/t/02_listener.t @@ -2,10 +2,10 @@ ## Test the "listener" action +use 5.006; use strict; use warnings; use Data::Dumper; -use DBI; use Test::More tests => 8; use lib 't','.'; use CP_Testing; diff --git a/t/02_locks.t b/t/02_locks.t index c4b055d2c..ce1f0ae0c 100644 --- a/t/02_locks.t +++ b/t/02_locks.t @@ -2,10 +2,10 @@ ## Test the "locks" action +use 5.006; use strict; use warnings; use Data::Dumper; -use DBI; use Test::More tests => 14; use lib 't','.'; use CP_Testing; diff --git a/t/02_logfile.t b/t/02_logfile.t index 0269b26ad..ffd37781e 100644 --- a/t/02_logfile.t +++ b/t/02_logfile.t @@ -3,10 +3,10 @@ ## Test the "logfile" action ## this does not test $S for syslog or stderr output +use 5.006; use strict; use warnings; use Data::Dumper; -use DBI; use Test::More tests => 11; use lib 't','.'; use CP_Testing; @@ -44,7 +44,7 @@ $t = qq{$S returned expected text}; like ($result, qr{\bOK\b}, $t); $t = qq{$S flagged missing logfile param}; -like ($cp->run(""), qr{^ERROR:.*redirected.*stderr}, $t); +like ($cp->run(''), qr{^ERROR:.*redirected.*stderr}, $t); $t = qq{$S flagged erroneous logfile param}; like ($result = $cp->run("--logfile $logfile" . 'x'), qr{^$label\b}, $t); diff --git a/t/02_new_version_cp.t b/t/02_new_version_cp.t index bd1fe6506..c987e2a40 100644 --- a/t/02_new_version_cp.t +++ b/t/02_new_version_cp.t @@ -2,6 +2,7 @@ ## Test the "new_version_cp" action +use 5.006; use strict; use warnings; use Data::Dumper; diff --git a/t/02_new_version_pg.t b/t/02_new_version_pg.t index e9119709f..1302e9b31 100644 --- a/t/02_new_version_pg.t +++ b/t/02_new_version_pg.t @@ -2,6 +2,7 @@ ## Test the "new_version_pg" action +use 5.006; use strict; use warnings; use Data::Dumper; diff --git a/t/02_prepared_txns.t b/t/02_prepared_txns.t index b3c7d8d1e..72f356125 100644 --- a/t/02_prepared_txns.t +++ b/t/02_prepared_txns.t @@ -2,10 +2,10 @@ ## Test the "prepare_txns" action +use 5.006; use strict; use warnings; use Data::Dumper; -use DBI; use Test::More tests => 10; use lib 't','.'; use CP_Testing; @@ -24,17 +24,17 @@ like ($cp->run('foobar=12'), qr{^\s*Usage:}, $t); ## Clear any outstanding transactions $info = $dbh->selectall_arrayref('SELECT gid FROM pg_prepared_xacts'); -local $dbh->{AutoCommit} = 1; +$dbh->{AutoCommit} = 1; for (@$info) { my $gid = $_->[0]; $dbh->do("ROLLBACK PREPARED '$gid'"); } -local $dbh->{AutoCommit} = 0; +$dbh->{AutoCommit} = 0; $t=qq{$S works when called without warning or critical}; like ($cp->run(''), qr{^$label OK: .+No prepared transactions found}, $t); -$dbh->do("PREPARE TRANSACTION '123'"); +$dbh->do(q{PREPARE TRANSACTION '123'}); $t=qq{$S gives correct message when all databases excluded}; like ($cp->run('--include=sbsp'), qr{^$label UNKNOWN: .+No matching databases found due to exclusion}, $t); @@ -62,12 +62,12 @@ like ($cp->run('--output=MRTG'), qr{^\d\n0\n\npostgres\n$}, $t); ## Clear any outstanding transactions $info = $dbh->selectall_arrayref('SELECT gid FROM pg_prepared_xacts'); -local $dbh->{AutoCommit} = 1; +$dbh->{AutoCommit} = 1; for (@$info) { my $gid = $_->[0]; $dbh->do("ROLLBACK PREPARED '$gid'"); } -local $dbh->{AutoCommit} = 0; +$dbh->{AutoCommit} = 0; exit; diff --git a/t/02_query_runtime.t b/t/02_query_runtime.t index e0c533370..29b4c4781 100644 --- a/t/02_query_runtime.t +++ b/t/02_query_runtime.t @@ -2,10 +2,10 @@ ## Test the "query_runtime" action +use 5.006; use strict; use warnings; use Data::Dumper; -use DBI; use Test::More tests => 17; use lib 't','.'; use CP_Testing; diff --git a/t/02_query_time.t b/t/02_query_time.t index c26fab614..8366d6e0c 100644 --- a/t/02_query_time.t +++ b/t/02_query_time.t @@ -2,10 +2,10 @@ ## Test the "query_time" action +use 5.006; use strict; use warnings; use Data::Dumper; -use DBI; use Test::More tests => 13; use lib 't','.'; use CP_Testing; @@ -22,7 +22,7 @@ my $label = 'POSTGRES_QUERY_TIME'; my $S = q{Action 'query_time'}; $t = qq{$S self-identifies correctly}; -$result = $cp->run(qq{-w 0}); +$result = $cp->run(q{-w 0}); like ($result, qr{^$label}, $t); $t = qq{$S identifies host}; @@ -59,6 +59,6 @@ if ($child == 0) { sleep 1; $dbh = $cp->test_database_handle(); $t = qq{$S detects running query}; -like ($cp->run(qq{-w 1}), qr{$label WARNING:}, $t); +like ($cp->run(q{-w 1}), qr{$label WARNING:}, $t); exit; diff --git a/t/02_relation_size.t b/t/02_relation_size.t index f4289e4c3..6adb6b4f0 100644 --- a/t/02_relation_size.t +++ b/t/02_relation_size.t @@ -2,12 +2,11 @@ ## Test the "relation_size" action +use 5.006; use strict; use warnings; use Data::Dumper; -use DBI; use Test::More tests => 23; - use lib 't','.'; use CP_Testing; diff --git a/t/02_replicate_row.t b/t/02_replicate_row.t index 0879579e6..05bb063de 100644 --- a/t/02_replicate_row.t +++ b/t/02_replicate_row.t @@ -2,10 +2,10 @@ ## Test the "replicate_row" action +use 5.006; use strict; use warnings; use Data::Dumper; -use DBI; use Test::More tests => 19; use lib 't','.'; use CP_Testing; @@ -118,7 +118,7 @@ $dbh->commit(); if (fork) { $result = $cp->run('DB2replicate-row', '-c 10 -repinfo=reptest,id,1,foo,yin,yang'); like ($result, qr{^POSTGRES_REPLICATE_ROW OK:.+Row was replicated}, $t); - $result =~ /time=(\d+)/ or die "No time?"; + $result =~ /time=(\d+)/ or die 'No time?'; my $time = $1; cmp_ok ($time, '>=', 3, $t); } @@ -148,7 +148,7 @@ $t=qq{$S works when rows match, with simple output}; $dbh->commit(); if (fork) { $result = $cp->run('DB2replicate-row', '-c 10 --output=simple -repinfo=reptest,id,1,foo,yin,yang'); - $result =~ /^(\d+)/ or die "No time?"; + $result =~ /^(\d+)/ or die 'No time?'; my $time = $1; cmp_ok ($time, '>=', 3, $t); } diff --git a/t/02_sequence.t b/t/02_sequence.t index cc90e0946..6be438795 100644 --- a/t/02_sequence.t +++ b/t/02_sequence.t @@ -2,10 +2,10 @@ ## Test the "sequence" action +use 5.006; use strict; use warnings; use Data::Dumper; -use DBI; use Test::More tests => 11; use lib 't','.'; use CP_Testing; diff --git a/t/02_settings_checksum.t b/t/02_settings_checksum.t index 24977dd40..e13477242 100644 --- a/t/02_settings_checksum.t +++ b/t/02_settings_checksum.t @@ -2,10 +2,10 @@ ## Test the "settings_checksum" action +use 5.006; use strict; use warnings; use Data::Dumper; -use DBI; use Test::More tests => 8; use lib 't','.'; use CP_Testing; diff --git a/t/02_timesync.t b/t/02_timesync.t index 9cd9887bd..be4e76d4d 100644 --- a/t/02_timesync.t +++ b/t/02_timesync.t @@ -1,7 +1,8 @@ #!perl -## Test the "version" action +## Test of the the "version" action +use 5.006; use strict; use warnings; use Data::Dumper; @@ -23,7 +24,7 @@ my $timepatt = qr{\d{4}-\d\d-\d\d \d\d:\d\d:\d\d}; my $S = q{Action 'timesync'}; $t = qq{$S self-identifies correctly}; -$result = $cp->run(qq{-w 100}); +$result = $cp->run(q{-w 100}); like ($result, qr{^$label}, $t); $t = qq{$S identifies database}; @@ -68,11 +69,11 @@ for ('-1 second', } $t = qq{$S returns correct MRTG information (OK case)}; -like ($cp->run("--output=mrtg -w 1"), +like ($cp->run(q{--output=mrtg -w 1}), qr{^\d+\n\d+\n\nDB: $dbname\n}, $t); $t = qq{$S returns correct MRTG information (fail case)}; -like($cp->run("--output=mrtg -w 1"), +like($cp->run(q{--output=mrtg -w 1}), qr{^\d+\n\d+\n\nDB: $dbname\n}, $t); exit; diff --git a/t/02_txn_idle.t b/t/02_txn_idle.t index 8ceb4d6e7..75e1f8d9a 100644 --- a/t/02_txn_idle.t +++ b/t/02_txn_idle.t @@ -2,10 +2,10 @@ ## Test the "txn_idle" action +use 5.006; use strict; use warnings; use Data::Dumper; -use DBI; use Test::More tests => 13; use lib 't','.'; use CP_Testing; @@ -23,19 +23,19 @@ my $label = 'POSTGRES_TXN_IDLE'; my $S = q{Action 'txn_idle'}; $t = qq{$S self-identifies correctly}; -$result = $cp->run(qq{-w 0}); +$result = $cp->run(q{-w 0}); like ($result, qr{^$label}, $t); $t = qq{$S identifies host}; like ($result, qr{host:$host}, $t); $t = qq{$S accepts valid -w input}; -for ('1 second', +for my $name ('1 second', '1 minute', '1 hour', '1 day' ) { - like ($cp->run(qq{-w "$_"}), qr/^$label/, $t . " ($_)"); + like ($cp->run(qq{-w "$_"}), qr/^$label/, "$t ($name)"); } $t = qq{$S rejects invalid -w input}; @@ -46,9 +46,9 @@ for ('-1 second', } $t = qq{$S flags no-match-user}; -like ($cp->run(qq{-w 0 --includeuser=gandalf}), qr{No matching.*user}, $t); +like ($cp->run(q{-w 0 --includeuser=gandalf}), qr{No matching.*user}, $t); -if ($cp->run(qq{-w 0 --output=simple}) > 0) { +if ($cp->run(q{-w 0 --output=simple}) > 0) { BAIL_OUT(qq{Cannot continue with "$S" test: txn_idle count > 0\nIs someone else connected to your test database?}); } @@ -56,16 +56,16 @@ $t = qq{$S identifies no idles}; like ($result, qr{no idle in transaction}, $t); $t .= ' (MRTG)'; -is ($cp->run(qq{--output=mrtg -w 0}), qq{0\n0\n\nDB: $dbname\n}, $t); +is ($cp->run(q{--output=mrtg -w 0}), qq{0\n0\n\nDB: $dbname\n}, $t); $t = qq{$S identifies idle}; my $idle_dbh = $cp->test_database_handle(); $idle_dbh->do('SELECT 1'); sleep(1); -like ($cp->run(qq{-w 0}), qr{longest idle in txn: \d+s}, $t); +like ($cp->run(q{-w 0}), qr{longest idle in txn: \d+s}, $t); $t .= ' (MRTG)'; -like ($cp->run(qq{--output=mrtg -w 0}), qr{\d+\n0\n\nDB: $dbname\n}, $t); +like ($cp->run(q{--output=mrtg -w 0}), qr{\d+\n0\n\nDB: $dbname\n}, $t); $idle_dbh->commit; diff --git a/t/02_txn_time.t b/t/02_txn_time.t index 2dee2e73d..227d85923 100644 --- a/t/02_txn_time.t +++ b/t/02_txn_time.t @@ -2,10 +2,10 @@ ## Test the "txn_time" action +use 5.006; use strict; use warnings; use Data::Dumper; -use DBI; use Test::More tests => 14; use lib 't','.'; use CP_Testing; @@ -23,7 +23,7 @@ my $label = 'POSTGRES_TXN_TIME'; my $S = q{Action 'txn_time'}; $t = qq{$S self-identifies correctly}; -$result = $cp->run(qq{-w 0}); +$result = $cp->run(q{-w 0}); like ($result, qr{^$label}, $t); $t = qq{$S identifies host}; @@ -46,29 +46,29 @@ for ('-1 second', } $t = qq{$S flags no-match-user}; -like ($cp->run(qq{-w 0 --includeuser=gandalf}), qr{No matching.*user}, $t); +like ($cp->run(q{-w 0 --includeuser=gandalf}), qr{No matching.*user}, $t); -if ($cp->run(qq{-w 0 --output=simple}) > 0) { +if ($cp->run(q{-w 0 --output=simple}) > 0) { BAIL_OUT(qq{Cannot continue with "$S" test: txn_time count > 0\nIs someone else connected to your test database?}); } $t = qq{$S finds no txn}; -like ($cp->run(qq{-w 0 --include=nosuchtablename}), qr/$label OK:.*No transactions/, $t); +like ($cp->run(q{-w 0 --include=nosuchtablename}), qr/$label OK:.*No transactions/, $t); $t = qq{$S identifies no running txn}; like ($result, qr{longest txn: 0s}, $t); $t .= ' (MRTG)'; -is ($cp->run(qq{--output=mrtg -w 0}), qq{0\n0\n\nDB: $dbname\n}, $t); +is ($cp->run(q{--output=mrtg -w 0}), qq{0\n0\n\nDB: $dbname\n}, $t); $t = qq{$S identifies a one-second running txn}; my $idle_dbh = $cp->test_database_handle(); $idle_dbh->do('SELECT 1'); sleep(1); -like ($cp->run(qq{-w 0}), qr{longest txn: 1s}, $t); +like ($cp->run(q{-w 0}), qr{longest txn: 1s}, $t); $t .= ' (MRTG)'; -like ($cp->run(qq{--output=mrtg -w 0}), qr{\d+\n0\n\nDB: $dbname\n}, $t); +like ($cp->run(q{--output=mrtg -w 0}), qr{\d+\n0\n\nDB: $dbname\n}, $t); $idle_dbh->commit; diff --git a/t/02_txn_wraparound.t b/t/02_txn_wraparound.t index 130dd5ae8..8e0610088 100644 --- a/t/02_txn_wraparound.t +++ b/t/02_txn_wraparound.t @@ -2,10 +2,10 @@ ## Test the "txn_wraparound" action +use 5.006; use strict; use warnings; use Data::Dumper; -use DBI; use Test::More tests => 14; use lib 't','.'; use CP_Testing; @@ -38,7 +38,7 @@ $t = qq{$S identifies host}; like ($result, qr{host:$host}, $t); $t = qq{$S accepts valid -w input}; -like ($cp->run(qq{-w 1000000}), qr/$label OK/, $t); +like ($cp->run(q{-w 1000000}), qr/$label OK/, $t); $t = qq{$S flags invalid -w input}; for (-1, 0, 'a') { @@ -46,7 +46,7 @@ for (-1, 0, 'a') { } $t = qq{$S accepts valid -c input}; -like ($cp->run(qq{-c 1000000}), qr/$label OK/, $t); +like ($cp->run(q{-c 1000000}), qr/$label OK/, $t); $t = qq{$S flags invalid -c input}; for (-1, 0, 'a') { diff --git a/t/02_version.t b/t/02_version.t index 9f93b33d3..1ff66d0b7 100644 --- a/t/02_version.t +++ b/t/02_version.t @@ -2,6 +2,7 @@ ## Test the "version" action +use 5.006; use strict; use warnings; use Data::Dumper; @@ -106,8 +107,7 @@ is ($cp->run('--output=MRTG --mrtg=7.8'), qq{1\n0\n\n7.8.12\n}, $t); $t=qq{$S gives correct output for MRTG output}; is ($cp->run('--output=MRTG --mrtg=7.8.12'), qq{1\n0\n\n7.8.12\n}, $t); -local $dbh->{Warn} = 0; -$dbh->do('DROP SCHEMA cptest CASCADE'); +$cp->drop_schema_if_exists($fakeschema); $cp->reset_path(); exit; diff --git a/t/02_wal_files.t b/t/02_wal_files.t index 22c79d70e..53c61fcaa 100644 --- a/t/02_wal_files.t +++ b/t/02_wal_files.t @@ -2,6 +2,7 @@ ## Test the "wal_files" action +use 5.006; use strict; use warnings; use Data::Dumper; @@ -37,7 +38,7 @@ $cp->create_fake_pg_table('pg_ls_dir', 'text'); like ($cp->run('--critical=1'), qr{POSTGRES_WAL_FILES OK}, $t); -$dbh->do("INSERT INTO cptest.pg_ls_dir SELECT 'ABCDEF123456ABCDEF123456' FROM generate_series(1,99)"); +$dbh->do(q{INSERT INTO cptest.pg_ls_dir SELECT 'ABCDEF123456ABCDEF123456' FROM generate_series(1,99)}); $dbh->commit(); $t=qq{$S returns correct number of files}; diff --git a/t/03_translations.t b/t/03_translations.t index 53bbe6ce7..2abb9d8a1 100644 --- a/t/03_translations.t +++ b/t/03_translations.t @@ -2,6 +2,7 @@ ## Run some sanity checks on the translations +use 5.006; use strict; use warnings; use Data::Dumper; @@ -58,7 +59,7 @@ for my $line (split /\n/ => $slurp) { } } -$t=qq{All msg() function calls are mapped to an 'en' string}; +$t=q{All msg() function calls are mapped to an 'en' string}; my $ok = 1; for my $call (sort keys %call) { if (!exists $msg{'en'}{$call}) { @@ -69,7 +70,7 @@ for my $call (sort keys %call) { } $ok and pass $t; -$t=qq{All msg() function calls are called with correct number of arguments}; +$t=q{All msg() function calls are called with correct number of arguments}; $ok = 1; for my $call (sort keys %call) { next if !exists $msg{'en'}{$call}; @@ -79,7 +80,7 @@ for my $call (sort keys %call) { my $numargs = $l->{numargs}; for my $x (1..$numargs) { if ($msg !~ /\$$x/) { - fail sprintf qq{Message '%s' called with %d %s as line %d, but no %s argument found in msg '%s'}, + fail sprintf q{Message '%s' called with %d %s as line %d, but no %s argument found in msg '%s'}, $call, $numargs, 1==$numargs ? 'argument' : 'arguments', $line, '$'.$x, $msg; $ok = 0; } @@ -93,7 +94,7 @@ for my $call (sort keys %call) { } $ok and pass $t; -my %ok2notuse = map { $_, 1 } +my %ok2notuse = map { $_ => 1 } qw/time-week time-weeks time-month time-months time-year time-years/; my %ok2nottrans; @@ -101,7 +102,7 @@ for my $msg (qw/timesync-diff time-minute time-minutes maxtime version version-o $ok2nottrans{'fr'}{$msg} = 1; } -$t=qq{All 'en' message strings are used somewhere in the code}; +$t=q{All 'en' message strings are used somewhere in the code}; $ok = 1; for my $msg (sort keys %{$msg{'en'}}) { if (!exists $call{$msg}) { @@ -114,21 +115,21 @@ for my $msg (sort keys %{$msg{'en'}}) { $ok and pass $t; for my $l (sort keys %complete_langs) { - my $lang = $complete_langs{$l}; - next if $lang eq 'English'; + my $language = $complete_langs{$l}; + next if $language eq 'English'; $ok = 1; - $t=qq{Language $lang contains all valid message strings}; + $t=qq{Language $language contains all valid message strings}; for my $msg (sort keys %{$msg{'en'}}) { if (! exists $msg{$l}{$msg}) { - fail qq{Message '$msg' does not appear in the $lang translations}; + fail qq{Message '$msg' does not appear in the $language translations}; $ok = 0; } } $ok and pass $t; $ok = 1; - $t=qq{Language $lang contains no extra message strings}; + $t=qq{Language $language contains no extra message strings}; for my $msg (sort keys %{$msg{$l}}) { if (! exists $msg{'en'}{$msg}) { fail qq{Message '$msg' does not appear in the 'en' messages!}; @@ -138,7 +139,7 @@ for my $l (sort keys %complete_langs) { $ok and pass $t; $ok = 1; - $t=qq{Language $lang messages have same number of args as 'en'}; + $t=qq{Language $language messages have same number of args as 'en'}; for my $msg (sort keys %{$msg{'en'}}) { next if ! exists $msg{$l}{$msg}; my $val = $msg{'en'}{$msg}->[1]; @@ -147,7 +148,7 @@ for my $l (sort keys %complete_langs) { { last if $val !~ /\$$x/; if ($lval !~ /\$$x/) { - fail qq{Message '$msg' is missing \$$x argument for language $lang}; + fail qq{Message '$msg' is missing \$$x argument for language $language}; $ok = 0; } $x++; @@ -157,7 +158,7 @@ for my $l (sort keys %complete_langs) { $ok and pass $t; $ok = 1; - $t=qq{Language $lang messages appears to not be translated, but is not marked as such}; + $t=qq{Language $language messages appears to not be translated, but is not marked as such}; for my $msg (sort keys %{$msg{'en'}}) { next if ! exists $msg{$l}{$msg}; next if exists $ok2nottrans{$l}{$msg}; @@ -165,21 +166,21 @@ for my $l (sort keys %complete_langs) { my $lval = $msg{$l}{$msg}->[1]; my $indent = $msg{$l}{$msg}->[0]; if ($val eq $lval and $indent) { - fail qq{Message '$msg' in language $lang appears to not be translated, but it not marked as such}; + fail qq{Message '$msg' in language $language appears to not be translated, but it not marked as such}; $ok = 0; } } $ok and pass $t; $ok = 1; - $t=qq{Language $lang messages are marked as translated correctly}; + $t=qq{Language $language messages are marked as translated correctly}; for my $msg (sort keys %{$msg{'en'}}) { next if ! exists $msg{$l}{$msg}; my $val = $msg{'en'}{$msg}->[1]; my $lval = $msg{$l}{$msg}->[1]; my $indent = $msg{$l}{$msg}->[0]; if ($val ne $lval and !$indent) { - fail qq{Message '$msg' in language $lang appears to not be translated, but it not marked as such}; + fail qq{Message '$msg' in language $language appears to not be translated, but it not marked as such}; $ok = 0; } } diff --git a/t/99_cleanup.t b/t/99_cleanup.t index 730ed4005..c86274f97 100644 --- a/t/99_cleanup.t +++ b/t/99_cleanup.t @@ -2,10 +2,10 @@ ## Cleanup any mess we made +use 5.006; use strict; use warnings; use Data::Dumper; -use DBI; use Test::More tests => 1; use lib 't','.'; use CP_Testing; diff --git a/t/99_perlcritic.t b/t/99_perlcritic.t index 6346d3c7d..2d1c830f8 100644 --- a/t/99_perlcritic.t +++ b/t/99_perlcritic.t @@ -4,11 +4,11 @@ ## This is highly customized, so take with a grain of salt ## Requires ENV TEST_CRITIC or TEST_EVERYTHING to be set +use 5.006; use strict; use warnings; use Test::More; use Data::Dumper; -select(($|=1,select(STDERR),$|=1)[1]); my @testfiles; @@ -51,13 +51,6 @@ for my $filename (qw{check_postgres.pl }) { (my $policy = $v->policy()) =~ s/Perl::Critic::Policy:://; my $source = $v->source(); - next if $policy =~ /ProhibitInterpolationOfLiterals/; ## For now - - ## Allow skipping of items: - ## next if $d =~ /Subroutine "looks_like_number" not exported/; - ## next if $policy =~ /ProhibitCallsToUndeclaredSubs/; - ##next if $policy =~ /ProhibitHardTabs/ and ($source =~ /sql = qq/i or $source =~ /qw[\(\/]/); - $vios++; my $f = $v->filename(); my $l = $v->location(); @@ -123,6 +116,9 @@ for my $filename (sort @testfiles) { ## Skip common Test::More subroutines: next if $d =~ $testmoreok; + ## Specific 'test files' exceptions + next if $policy =~ /Modules::RequireVersionVar/o; + ## Skip other specific items: for my $k (sort keys %ok) { next unless $f =~ /$k/; @@ -131,16 +127,15 @@ for my $filename (sort @testfiles) { } } - ## Skip included file package warning - next if $policy =~ /RequireExplicitPackage/ and $filename =~ /setup/; - $vios++; my $l = $v->location(); my $line = $l->[0]; + my $pbp = $v->explanation(); diag "\nFile: $f (line $line)\n"; diag "Vio: $d\n"; diag "Policy: $policy\n"; - diag "Source: $source\n\n"; + diag "Source: $source\n"; + diag "PBP says: $pbp\n\n"; } my $SPACE = ++$count < 9 ? ' ' : ''; if ($vios) { diff --git a/t/99_pod.t b/t/99_pod.t index 47b6fb90c..484df6e28 100644 --- a/t/99_pod.t +++ b/t/99_pod.t @@ -2,12 +2,10 @@ ## Check our Pod, requires Test::Pod +use 5.006; use strict; use warnings; -use Test::More; -select(($|=1,select(STDERR),$|=1)[1]); - -plan tests => 2; +use Test::More tests => 2; my $PODVERSION = '0.95'; eval { @@ -36,9 +34,9 @@ SKIP: { my $trusted_names = [ - qr{^CLONE$}, - qr{^driver$}, - qr{^constant$}, + qr{^CLONE$}, ## no critic (ProhibitFixedStringMatches) + qr{^driver$}, ## no critic (ProhibitFixedStringMatches) + qr{^constant$}, ## no critic (ProhibitFixedStringMatches) ]; pod_coverage_ok('check_postgres', {trustme => $trusted_names}, 'check_postgres.pl pod coverage okay'); } diff --git a/t/99_spellcheck.t b/t/99_spellcheck.t index f0e0a3d18..2b9d9842c 100644 --- a/t/99_spellcheck.t +++ b/t/99_spellcheck.t @@ -3,10 +3,10 @@ ## Spellcheck as much as we can ## Requires ENV TEST_SPELL or TEST_EVERYTHING to be set +use 5.006; use strict; use warnings; use Test::More; -select(($|=1,select(STDERR),$|=1)[1]); my (@testfiles, $fh); @@ -24,15 +24,15 @@ else { } my %okword; -my $file = 'Common'; +my $filename = 'Common'; while (<DATA>) { if (/^## (.+):/) { - $file = $1; + $filename = $1; next; } next if /^#/ or ! /\w/; for (split) { - $okword{$file}{$_}++; + $okword{$filename}{$_}++; } } |