perl 5.28.x 编译:测试失败 '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'
在 Linux 中,当 运行 为本地模块
创建测试命令时,perl 安装失败
[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
系统日期在我的系统中设置正确
[user@hostname perl-5.28.3]$ date
Mon Feb 14 07:38:07 PST 2022
perl-5.28.x 是否存在针对此问题的 workaround/patch 版本?
使测试失败:
[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
任何指点将不胜感激。
这只是一个写得不好的测试,可以放心地忽略。
该测试在比 perl-5.28.3 捆绑的新版本 Time::Local 中得到修复。您始终可以在之后使用 cpan Time::Local
.
安装该版本
如果您坚持要进行全新安装,可以运行执行以下命令:
patchperl 5.28.3 /path/to/untarred/perl/source/perl-5.28.3
它需要安装 Devel::PatchPerl 的 Perl。它安装以下补丁:
--- 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
在 Linux 中,当 运行 为本地模块
创建测试命令时,perl 安装失败[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
系统日期在我的系统中设置正确
[user@hostname perl-5.28.3]$ date
Mon Feb 14 07:38:07 PST 2022
perl-5.28.x 是否存在针对此问题的 workaround/patch 版本?
使测试失败:
[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
任何指点将不胜感激。
这只是一个写得不好的测试,可以放心地忽略。
该测试在比 perl-5.28.3 捆绑的新版本 Time::Local 中得到修复。您始终可以在之后使用 cpan Time::Local
.
如果您坚持要进行全新安装,可以运行执行以下命令:
patchperl 5.28.3 /path/to/untarred/perl/source/perl-5.28.3
它需要安装 Devel::PatchPerl 的 Perl。它安装以下补丁:
--- 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