From b1cb1708dfc35370ee704b94a5e925248f6f0f35 Mon Sep 17 00:00:00 2001 From: Galen Charlton Date: Mon, 7 Jul 2008 12:54:52 -0500 Subject: [PATCH] bug 2295 [followup 2/2]: initialize data in startup method It was observed that the %thash and @formats variables were not being properly initalized during a make single-test run. To ensure initialization, created startup and shutdown methods to initialize those values as part of the test object. I have not yet investigated why the original way of setting up %thash and @formats did not work. Signed-off-by: Joshua Ferraro --- t/lib/KohaTest/Dates/Usage.pm | 37 +++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/t/lib/KohaTest/Dates/Usage.pm b/t/lib/KohaTest/Dates/Usage.pm index 6f5941833c..9dc75eddd4 100644 --- a/t/lib/KohaTest/Dates/Usage.pm +++ b/t/lib/KohaTest/Dates/Usage.pm @@ -9,15 +9,16 @@ use Test::More; use C4::Dates qw(format_date format_date_in_iso); -my %thash = ( - iso => [ '2001-01-01', '1989-09-21', '1952-01-00' ], - metric => [ "01-01-2001", '21-09-1989', '00-01-1952' ], - us => [ "01-01-2001", '09-21-1989', '01-00-1952' ], - sql => [ '20010101 010101', '19890921 143907', '19520100 000000' ], -); - - -my @formats = sort keys %thash; +sub startup_init_constants : Tests(startup => 0) { + my $self = shift; + $self->{thash} = { + iso => [ '2001-01-01', '1989-09-21', '1952-01-00' ], + metric => [ "01-01-2001", '21-09-1989', '00-01-1952' ], + us => [ "01-01-2001", '09-21-1989', '01-00-1952' ], + sql => [ '20010101 010101', '19890921 143907', '19520100 000000' ], + }; + $self->{formats} = [ sort keys %{ $self->{thash} } ]; +} sub check_formats : Test( 10 ) { my $self = shift; @@ -25,11 +26,11 @@ sub check_formats : Test( 10 ) { my $syspref = C4::Dates->new->format(); ok( $syspref, "Your system preference is: $syspref" ); - foreach ( @{ $thash{'iso'} } ) { + foreach ( @{ $self->{thash}->{'iso'} } ) { ok( format_date($_), "able to format_date() on $_" ); } - foreach ( @{ $thash{$syspref} } ) { + foreach ( @{ $self->{thash}->{$syspref} } ) { ok( format_date_in_iso($_), "able to format_date_in_iso() on $_" ); } ok( C4::Dates->today(), "(default) CLASS ->today : " . C4::Dates->today() ); @@ -38,7 +39,7 @@ sub check_formats : Test( 10 ) { sub defaults : Test( 24 ) { my $self = shift; - foreach (@formats) { + foreach (@{ $self->{formats} }) { my $pre = sprintf '(%-6s)', $_; my $date = C4::Dates->new(); ok( $date, "$pre Date Creation : new()" ); @@ -54,16 +55,16 @@ sub defaults : Test( 24 ) { sub valid_inputs : Test( 108 ) { my $self = shift; - foreach my $format (@formats) { + foreach my $format (@{ $self->{formats} }) { my $pre = sprintf '(%-6s)', $format; - foreach my $testval ( @{ $thash{$format} } ) { + foreach my $testval ( @{ $self->{thash}->{$format} } ) { my ( $val, $today ); my $date = C4::Dates->new( $testval, $format ); ok( $date, "$pre Date Creation : new('$testval','$format')" ); isa_ok( $date, 'C4::Dates' ); ok( $date->regexp, "$pre has regexp()" ); ok( $val = $date->output(), describe( "$pre output()", $val ) ); - foreach ( grep { !/$format/ } @formats ) { + foreach ( grep { !/$format/ } @{ $self->{formats} } ) { ok( $today = $date->output($_), describe( sprintf( "$pre output(%8s)", "'$_'" ), $today ) ); } ok( $today = $date->today(), describe( "$pre object->today", $today ) ); @@ -93,4 +94,10 @@ sub describe { return "$front : $tail"; } +sub shutdown_clear_constants : Tests( shutdown => 0 ) { + my $self = shift; + delete $self->{thash}; + delete $self->{formats}; +} + 1; -- 2.39.5