Home > Net >  perl 5.28.x compilation: Failed test 'timelocal year for 1970 1 2 0 0 0'
perl 5.28.x compilation: Failed test 'timelocal year for 1970 1 2 0 0 0'

Time:02-16

In Linux, installation of perl is failing while running make test command for Local module

[user@hostname perl-5.28.3]$  make test
cpan/Time-Local/t/Local ........................................ #   Failed test 'timelocal year for 1970 1 2 0 0 0'
#   at t/Local.t line 109.
#          got: '170'
#     expected: '70'
#   Failed test 'timegm year for 1970 1 2 0 0 0'
#   at t/Local.t line 124.
#          got: '170'
#     expected: '70'
# Looks like you failed 2 tests of 187.
FAILED at test 6

System date is set correctly in my system

[user@hostname perl-5.28.3]$ date
Mon Feb 14 07:38:07 PST 2022

are there any workaround/patch exists for perl-5.28.x release for this issue?

make test failure:

[user@hostname perl-5.28.3]$ t/TEST ../cpan/Time-Local/t/Local.t
t/../cpan/Time-Local/t/Local ... #   Failed test 'timelocal year for 1970 1 2 0 0 0'
#   at t/Local.t line 109.
#          got: '170'
#     expected: '70'
#   Failed test 'timegm year for 1970 1 2 0 0 0'
#   at t/Local.t line 124.
#          got: '170'
#     expected: '70'
# Looks like you failed 2 tests of 187.
FAILED at test 6
Failed 1 test out of 0, 0.00% okay.
        ../cpan/Time-Local/t/Local.t

Any pointer will be highly appreciated.

CodePudding user response:

It is merely a badly written test which can be safely ignored.

The test was fixed in the newer version of Time::Local than the one bundled with perl-5.28.3. You could always install that version afterwards using cpan Time::Local.


If you insist on a clean install, you can run the following command:

patchperl 5.28.3 /path/to/untarred/perl/source/perl-5.28.3

It requires a Perl with Devel::PatchPerl installed. It installs the following patch:

--- cpan/Time-Local/t/Local.t
    cpan/Time-Local/t/Local.t
@@ -85,19  85,17 @@ my $epoch_is_64

 for ( @time, @neg_time ) {
     my ( $year, $mon, $mday, $hour, $min, $sec ) = @$_;
-    $year -= 1900;
     $mon--;

 SKIP: {
         skip '1970 test on VOS fails.', 12
-            if $^O eq 'vos' && $year == 70;
             if $^O eq 'vos' && $year == 1970;
         skip 'this platform does not support negative epochs.', 12
-            if $year < 70 && !$neg_epoch_ok;
             if $year < 1970 && !$neg_epoch_ok;

         # Test timelocal()
         {
-            my $year_in = $year < 70 ? $year   1900 : $year;
-            my $time = timelocal( $sec, $min, $hour, $mday, $mon, $year_in );
             my $time = timelocal( $sec, $min, $hour, $mday, $mon, $year );

             my ( $s, $m, $h, $D, $M, $Y ) = localtime($time);

@@ -106,13  104,12 @@ SKIP: {
             is( $h, $hour,     "timelocal hour for @$_" );
             is( $D, $mday,     "timelocal day for @$_" );
             is( $M, $mon,      "timelocal month for @$_" );
-            is( $Y, $year,     "timelocal year for @$_" );
             is( $Y, $year - 1900,     "timelocal year for @$_" );
         }

         # Test timegm()
         {
-            my $year_in = $year < 70 ? $year   1900 : $year;
-            my $time = timegm( $sec, $min, $hour, $mday, $mon, $year_in );
             my $time = timegm( $sec, $min, $hour, $mday, $mon, $year );

             my ( $s, $m, $h, $D, $M, $Y ) = gmtime($time);

@@ -121,14  118,13 @@ SKIP: {
             is( $h, $hour,     "timegm hour for @$_" );
             is( $D, $mday,     "timegm day for @$_" );
             is( $M, $mon,      "timegm month for @$_" );
-            is( $Y, $year,     "timegm year for @$_" );
             is( $Y, $year - 1900,     "timegm year for @$_" );
         }
     }
 }

 for (@bad_time) {
     my ( $year, $mon, $mday, $hour, $min, $sec ) = @$_;
-    $year -= 1900;
     $mon--;

     eval { timegm( $sec, $min, $hour, $mday, $mon, $year ) };
@@ -229,6  225,30 @@ SKIP:
     );
 }

 # 2-digit years
 {
        my $current_year = ( localtime() )[5];
        my $pre_break    = ( $current_year   49 ) - 100;
        my $break        = ( $current_year   50 ) - 100;
        my $post_break   = ( $current_year   51 ) - 100;
 
        is(
                ( ( localtime( timelocal( 0, 0, 0, 1, 1, $pre_break ) ) )[5] ),
                $pre_break   100,
                "year $pre_break is treated as next century",
        );
        is(
                ( ( localtime( timelocal( 0, 0, 0, 1, 1, $break ) ) )[5] ),
                $break   100,
                "year $break is treated as next century",
        );
        is(
                ( ( localtime( timelocal( 0, 0, 0, 1, 1, $post_break ) ) )[5] ),
                $post_break,
                "year $post_break is treated as current century",
        );
 }
 
 SKIP:
 {
     skip 'These tests only run for the package maintainer.', 8
  • Related