Skip to content

Commit

Permalink
Remove Log::Log4perl initialization from test scripts
Browse files Browse the repository at this point in the history
When the DEBUG environment variable is defined, print logs to STDERR.
  • Loading branch information
ehuelsmann committed Aug 1, 2021
1 parent e7ae110 commit 4361763
Show file tree
Hide file tree
Showing 20 changed files with 7 additions and 72 deletions.
19 changes: 2 additions & 17 deletions t/05_condition_nested.t
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,14 @@ use warnings;
use lib qw(t);

use Test::More;
use Log::Any qw( $log );

my $debug = $ENV{TEST_DEBUG};

# base name used to find config files
my $cfgbase = $0;
$cfgbase =~ s/\.t$/.d/;

my $LOG_FILE = 'workflow_tests.log';
my $CONF_FILE = $cfgbase . '/log4perl.conf';

require Log::Log4perl;
if ($debug) {
if ( -f $LOG_FILE ) {
unlink($LOG_FILE);
}
Log::Log4perl::init($CONF_FILE);
}
else {
no warnings 'once';
Log::Log4perl::easy_init($Log::Log4perl::OFF);
}




require Workflow::Factory;
Expand Down Expand Up @@ -80,7 +65,7 @@ is( $workflow->state, 'INITIALIZED', 'initialized state' );
$workflow->execute_action('test_greedy_or');
is( $workflow->state, 'TEST_GREEDY_OR', 'wfcond state after test_greedy_or' );

Log::Log4perl::get_logger()->error('START OFFENDING TEST');
$log->error('START OFFENDING TEST');
$workflow->execute_action('greedy_or_1');
is( $workflow->state, 'INITIALIZED', 'wfcond state after greedy_or_1' )
or $workflow->execute_action('ack_subtest_fail');
Expand Down
22 changes: 5 additions & 17 deletions t/TestUtil.pm
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@ package TestUtil;
use strict;
use vars qw($VERSION);
use DateTime;
use Log::Any::Adapter;
use Test::More;
use List::MoreUtils qw(all);

$VERSION = '0.02';

my $LOG_FILE = 't/workflow_tests.log';
my $CONF_FILE = 't/log4perl.conf';

if ($ENV{DEBUG}) {
Log::Any::Adapter->set('Stderr');
}

########################################
# TICKET INFO
Expand Down Expand Up @@ -110,21 +113,6 @@ sub init_mock_persister {



# Initialize the logger and other resources; called when module
# required by test

sub init {
if ( -f $LOG_FILE ) {
unlink( $LOG_FILE );
}

require Log::Log4perl;
Log::Log4perl::init( $CONF_FILE );

}

init();

# Used with state tests with various configs.
sub run_state_tests{
my $factory = shift;
Expand Down
2 changes: 0 additions & 2 deletions t/condition.t
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ use Test::More tests => 11;
use Test::Exception;

no warnings 'once';
require Log::Log4perl;
Log::Log4perl::easy_init($Log::Log4perl::OFF);


require_ok( 'Workflow::Condition' );
Expand Down
2 changes: 0 additions & 2 deletions t/condition_evaluate.t
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ use TestUtil;
use Test::More tests => 1;

no warnings 'once';
require Log::Log4perl;
Log::Log4perl::easy_init($Log::Log4perl::OFF);


my $wf;
Expand Down
2 changes: 0 additions & 2 deletions t/config.t
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ use Test::More tests => 50;
use Test::Exception;

no warnings 'once';
require Log::Log4perl;
Log::Log4perl::easy_init($Log::Log4perl::OFF);


my ($parser);
Expand Down
1 change: 0 additions & 1 deletion t/context-persists.t
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use Env qw($TEST_VERBOSE);
use lib qw(t);
use TestUtil;

#use Log::Log4perl ":easy"; # makes workflow happy

use Workflow::Factory qw(FACTORY);

Expand Down
2 changes: 0 additions & 2 deletions t/context.t
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ use Test::More tests => 9;
use Test::Exception;

no warnings 'once';
require Log::Log4perl;
Log::Log4perl::easy_init($Log::Log4perl::OFF);


require_ok( 'Workflow::Context' );
Expand Down
2 changes: 0 additions & 2 deletions t/exception.t
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ use Test::More;
use Test::Exception;
use English qw(-no_match_vars);

use Log::Log4perl qw(:easy);
Log::Log4perl->easy_init($OFF);

use_ok( 'Workflow::Exception', qw(workflow_error validation_error configuration_error persist_error) );

Expand Down
2 changes: 0 additions & 2 deletions t/factory.t
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ use Test::More tests => 7;
use Test::Exception;

no warnings 'once';
require Log::Log4perl;
Log::Log4perl::easy_init($Log::Log4perl::OFF);


require_ok( 'Workflow::Factory' );
Expand Down
2 changes: 0 additions & 2 deletions t/factory_subclass.t
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ use TestUtil;
use Test::More tests => 5;

no warnings 'once';
require Log::Log4perl;
Log::Log4perl::easy_init($Log::Log4perl::OFF);


require_ok( 'FactorySubclass' );
Expand Down
2 changes: 0 additions & 2 deletions t/history.t
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ use TestUtil;
use Test::More tests => 18;

no warnings 'once';
require Log::Log4perl;
Log::Log4perl::easy_init($Log::Log4perl::OFF);


require_ok( 'Workflow::History' );
Expand Down
6 changes: 0 additions & 6 deletions t/log4perl.conf

This file was deleted.

2 changes: 0 additions & 2 deletions t/persister.t
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ use Test::Exception;
use Test::More tests => 18;

no warnings 'once';
require Log::Log4perl;
Log::Log4perl::easy_init($Log::Log4perl::OFF);


require_ok( 'Workflow::Persister' );
Expand Down
2 changes: 0 additions & 2 deletions t/persister_auto_generate_id.t
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ use Test::Exception;
use Mock::MonkeyPatch;

no warnings 'once';
require Log::Log4perl;
Log::Log4perl::easy_init($Log::Log4perl::OFF);


require Workflow::Factory;
Expand Down
2 changes: 0 additions & 2 deletions t/persister_dbi_inherit.t
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ use strict;
use lib qw(t);
use Test::More;

use Log::Log4perl qw(:easy);
Log::Log4perl->easy_init($OFF);

eval "require DBI";
if ( $@ ) {
Expand Down
1 change: 0 additions & 1 deletion t/persister_dbi_sqlite.t
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use lib qw(t);
use TestUtil;
use constant NUM_TESTS => 15;
use Test::More;
use Log::Log4perl qw( get_logger );
use TestDBUtil;

eval "require DBI";
Expand Down
2 changes: 0 additions & 2 deletions t/persister_sequence_id.t
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ use Test::Exception;
use Mock::MonkeyPatch;

no warnings 'once';
require Log::Log4perl;
Log::Log4perl::easy_init($Log::Log4perl::OFF);


require Workflow::Factory;
Expand Down
2 changes: 0 additions & 2 deletions t/validator.t
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ use Test::More tests => 2;
use Test::Exception;

no warnings 'once';
require Log::Log4perl;
Log::Log4perl::easy_init($Log::Log4perl::OFF);


require_ok( 'Workflow::Validator' );
Expand Down
2 changes: 0 additions & 2 deletions t/validator_has_required_field.t
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ use TestUtil;
use Test::More tests => 1;

no warnings 'once';
require Log::Log4perl;
Log::Log4perl::easy_init($Log::Log4perl::OFF);


require_ok( 'Workflow::Validator::HasRequiredField' );
2 changes: 0 additions & 2 deletions t/validator_matches_date_format.t
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ use Test::Exception;
use DateTime;
use Test::More;

use Log::Log4perl qw(:easy);
Log::Log4perl->easy_init($OFF);


require_ok( 'Workflow::Validator::MatchesDateFormat');
Expand Down

0 comments on commit 4361763

Please sign in to comment.