From 5ba726905f8518f612bfc80744eccd6833655697 Mon Sep 17 00:00:00 2001 From: "Philippe Bruhat (BooK)" Date: Thu, 12 Dec 2024 23:35:28 +0100 Subject: [PATCH] fix string comparisons with $] to use numeric comparison instead The fix follows Zefram's suggestion from https://www.nntp.perl.org/group/perl.perl5.porters/2012/05/msg186846.html > On older perls, however, $] had a numeric value that was built up using > floating-point arithmetic, such as 5+0.006+0.000002. This would not > necessarily match the conversion of the complete value from string form > [perl #72210]. You can work around that by explicitly stringifying > $] (which produces a correct string) and having *that* numify (to a > correctly-converted floating point value) for comparison. I cultivate > the habit of always stringifying $] to work around this, regardless of > the threshold where the bug was fixed. So I'd write > > use if "$]" >= 5.014, warnings => "non_unicode"; This ensures that the comparisons will still work when Perl's major version changes to anything greater than 9. --- lib/Test2/API.pm | 2 +- lib/Test2/Formatter/TAP.pm | 2 +- lib/Test2/Tools/Tiny.pm | 4 ++-- t/HashBase.t | 2 +- t/Legacy/Regression/736_use_ok.t | 2 +- t/Legacy/overload_threads.t | 2 +- t/Legacy_And_Test2/preload_diag_note.t | 2 +- t/Test2/behavior/init_croak.t | 2 +- t/Test2/behavior/nested_context_exception.t | 2 +- t/Test2/modules/API.t | 2 +- t/Test2/modules/API/Breakage.t | 2 +- t/Test2/modules/API/Instance.t | 6 +++--- t/Test2/modules/Hub.t | 2 +- t/Test2/modules/IPC/Driver.t | 2 +- t/Test2/modules/IPC/Driver/Files.t | 2 +- t/Test2/modules/Util.t | 4 ++-- t/Test2/regression/ipc_files_abort_exit.t | 2 +- t/modules/Require/Perl.t | 2 +- 18 files changed, 22 insertions(+), 22 deletions(-) diff --git a/lib/Test2/API.pm b/lib/Test2/API.pm index a9324add3..d15bf43d4 100644 --- a/lib/Test2/API.pm +++ b/lib/Test2/API.pm @@ -74,7 +74,7 @@ sub CLONE { BEGIN { no warnings 'once'; - if($] ge '5.014' || $ENV{T2_CHECK_DEPTH} || $Test2::API::DO_DEPTH_CHECK) { + if("$]" >= 5.014 || $ENV{T2_CHECK_DEPTH} || $Test2::API::DO_DEPTH_CHECK) { *DO_DEPTH_CHECK = sub() { 1 }; } else { diff --git a/lib/Test2/Formatter/TAP.pm b/lib/Test2/Formatter/TAP.pm index 9f8f30470..35647a2d7 100644 --- a/lib/Test2/Formatter/TAP.pm +++ b/lib/Test2/Formatter/TAP.pm @@ -66,7 +66,7 @@ sub _open_handles { sub encoding { my $self = shift; - if ($] ge "5.007003" and @_) { + if ("$]" >= 5.007003 and @_) { my ($enc) = @_; my $handles = $self->{+HANDLES}; diff --git a/lib/Test2/Tools/Tiny.pm b/lib/Test2/Tools/Tiny.pm index efa5efccc..c4843b798 100644 --- a/lib/Test2/Tools/Tiny.pm +++ b/lib/Test2/Tools/Tiny.pm @@ -3,7 +3,7 @@ use strict; use warnings; BEGIN { - if ($] lt "5.008") { + if ("$]" < 5.008) { require Test::Builder::IO::Scalar; } } @@ -260,7 +260,7 @@ sub capture(&) { ($ok, $e) = try { # Scalar refs as filehandles were added in 5.8. - if ($] ge "5.008") { + if ("$]" >= 5.008) { open($out_fh, '>', \$out) or die "Failed to open a temporary STDOUT: $!"; open($err_fh, '>', \$err) or die "Failed to open a temporary STDERR: $!"; } diff --git a/t/HashBase.t b/t/HashBase.t index e040de6e3..cce309ac5 100644 --- a/t/HashBase.t +++ b/t/HashBase.t @@ -84,7 +84,7 @@ is($pkg->do_it, 'const', "worked as expected"); } ok(!$pkg->FOO, "overrode const sub"); { -local $TODO = "known to fail on $]" if $] le "5.006002"; +local $TODO = "known to fail on $]" if "$]" <= 5.006002; is($pkg->do_it, 'const', "worked as expected, const was constant"); } diff --git a/t/Legacy/Regression/736_use_ok.t b/t/Legacy/Regression/736_use_ok.t index d0f194c0b..c1d7c60c5 100644 --- a/t/Legacy/Regression/736_use_ok.t +++ b/t/Legacy/Regression/736_use_ok.t @@ -19,7 +19,7 @@ sub capture(&) { } { -local $TODO = "known to fail on $]" if $] le "5.006002"; +local $TODO = "known to fail on $]" if "$]" <= 5.006002; my $file = __FILE__; my $line = __LINE__ + 4; like( diff --git a/t/Legacy/overload_threads.t b/t/Legacy/overload_threads.t index fbc067aea..592de4e20 100644 --- a/t/Legacy/overload_threads.t +++ b/t/Legacy/overload_threads.t @@ -20,7 +20,7 @@ BEGIN { use Test::More; -plan skip_all => "known to crash on $]" if $] le "5.006002"; +plan skip_all => "known to crash on $]" if "$]" <= 5.006002; plan tests => 5; diff --git a/t/Legacy_And_Test2/preload_diag_note.t b/t/Legacy_And_Test2/preload_diag_note.t index b5cf68be7..c8a0dff4f 100644 --- a/t/Legacy_And_Test2/preload_diag_note.t +++ b/t/Legacy_And_Test2/preload_diag_note.t @@ -1,7 +1,7 @@ use strict; use warnings; -if ($] lt "5.008") { +if ("$]" < 5.008) { print "1..0 # SKIP Test cannot run on perls below 5.8.0\n"; exit 0; } diff --git a/t/Test2/behavior/init_croak.t b/t/Test2/behavior/init_croak.t index bebf410b8..5cc5d6798 100644 --- a/t/Test2/behavior/init_croak.t +++ b/t/Test2/behavior/init_croak.t @@ -14,7 +14,7 @@ BEGIN { } } -skip_all("known to fail on $]") if $] le "5.006002"; +skip_all("known to fail on $]") if "$]" <= 5.006002; $@ = ""; my ($file, $line) = (__FILE__, __LINE__ + 1); diff --git a/t/Test2/behavior/nested_context_exception.t b/t/Test2/behavior/nested_context_exception.t index 0c79c8a85..ef90c56cb 100644 --- a/t/Test2/behavior/nested_context_exception.t +++ b/t/Test2/behavior/nested_context_exception.t @@ -5,7 +5,7 @@ use Test2::Tools::Tiny; use Test2::API qw/context/; -skip_all("known to fail on $]") if $] le "5.006002"; +skip_all("known to fail on $]") if "$]" <= 5.006002; sub outer { my $code = shift; diff --git a/t/Test2/modules/API.t b/t/Test2/modules/API.t index c96c423a4..036af71ed 100644 --- a/t/Test2/modules/API.t +++ b/t/Test2/modules/API.t @@ -114,7 +114,7 @@ like( "got warning about adding driver too late" ); }; -if ($] le "5.006002") { +if ("$]" <= 5.006002) { todo("TODO known to fail on $]", $sub1); } else { $sub1->(); diff --git a/t/Test2/modules/API/Breakage.t b/t/Test2/modules/API/Breakage.t index 0ceeeab90..b6bacd7eb 100644 --- a/t/Test2/modules/API/Breakage.t +++ b/t/Test2/modules/API/Breakage.t @@ -1,7 +1,7 @@ use strict; use warnings; -if ($] lt "5.008") { +if ("$]" < 5.008) { print "1..0 # SKIP Test cannot run on perls below 5.8.0 because local doesn't work on hash keys.\n"; exit 0; } diff --git a/t/Test2/modules/API/Instance.t b/t/Test2/modules/API/Instance.t index 9923c501d..9580f74ba 100644 --- a/t/Test2/modules/API/Instance.t +++ b/t/Test2/modules/API/Instance.t @@ -211,7 +211,7 @@ if (CAN_REALLY_FORK) { like($warnings[0], qr/Process .* did not exit cleanly \(wstat: \S+, exit: 0, sig: 15\)/, "Warn about exit"); } -if (CAN_THREAD && $] ge '5.010') { +if (CAN_THREAD && "$]" >= 5.010) { require threads; my $one = $CLASS->new; @@ -297,7 +297,7 @@ if (CAN_THREAD && $] ge '5.010') { } SKIP: { - last SKIP if $] lt "5.008"; + last SKIP if "$]" < 5.008; my $one = $CLASS->new; my $stderr = ""; { @@ -326,7 +326,7 @@ This is not a supported configuration, you will have problems. } SKIP: { - last SKIP if $] lt "5.008"; + last SKIP if "$]" < 5.008; require Test2::API::Breakage; no warnings qw/redefine once/; my $ran = 0; diff --git a/t/Test2/modules/Hub.t b/t/Test2/modules/Hub.t index 50e1497ed..53e6e81b3 100644 --- a/t/Test2/modules/Hub.t +++ b/t/Test2/modules/Hub.t @@ -141,7 +141,7 @@ tests IPC => sub { } } - if (CAN_THREAD && $] ge '5.010') { + if (CAN_THREAD && "$]" >= 5.010) { require threads; my $thr = threads->new(sub { $do_send->() }); $thr->join; diff --git a/t/Test2/modules/IPC/Driver.t b/t/Test2/modules/IPC/Driver.t index d5ebbd5fd..2e6026d51 100644 --- a/t/Test2/modules/IPC/Driver.t +++ b/t/Test2/modules/IPC/Driver.t @@ -26,7 +26,7 @@ for my $meth (qw/send cull add_hub drop_hub waiting is_viable/) { } SKIP: { - last SKIP if $] lt "5.008"; + last SKIP if "$]" < 5.008; tests abort => sub { my $one = Test2::IPC::Driver->new(no_fatal => 1); my ($err, $out) = ("", ""); diff --git a/t/Test2/modules/IPC/Driver/Files.t b/t/Test2/modules/IPC/Driver/Files.t index cf7d5622d..ce3521cfb 100644 --- a/t/Test2/modules/IPC/Driver/Files.t +++ b/t/Test2/modules/IPC/Driver/Files.t @@ -6,7 +6,7 @@ use List::Util qw/shuffle/; use strict; use warnings; -if ($] lt "5.008") { +if ("$]" < 5.008) { print "1..0 # SKIP Test cannot run on perls below 5.8.0\n"; exit 0; } diff --git a/t/Test2/modules/Util.t b/t/Test2/modules/Util.t index efbfd08dd..1171ff7a5 100644 --- a/t/Test2/modules/Util.t +++ b/t/Test2/modules/Util.t @@ -34,7 +34,7 @@ use Test2::Util qw/ /; BEGIN { - if ($] lt "5.008") { + if ("$]" < 5.008) { require Test::Builder::IO::Scalar; } } @@ -83,7 +83,7 @@ close($io); my $fh; my $out = ''; -if ($] ge "5.008") { +if ("$]" >= 5.008) { open($fh, '>', \$out) or die "Could not open filehandle"; } else { $fh = Test::Builder::IO::Scalar->new(\$out) or die "Could not open filehandle"; diff --git a/t/Test2/regression/ipc_files_abort_exit.t b/t/Test2/regression/ipc_files_abort_exit.t index 5550f1774..e800216e1 100644 --- a/t/Test2/regression/ipc_files_abort_exit.t +++ b/t/Test2/regression/ipc_files_abort_exit.t @@ -6,7 +6,7 @@ use Test2::Util qw/CAN_REALLY_FORK/; BEGIN { skip_all "Set AUTHOR_TESTING to run this test" unless $ENV{AUTHOR_TESTING}; skip_all "System cannot fork" unless CAN_REALLY_FORK; - skip_all "known to fail on $]" if $] le "5.006002"; + skip_all "known to fail on $]" if "$]" <= 5.006002; } use IPC::Open3 qw/open3/; diff --git a/t/modules/Require/Perl.t b/t/modules/Require/Perl.t index e0a9f2a29..6723f8a97 100644 --- a/t/modules/Require/Perl.t +++ b/t/modules/Require/Perl.t @@ -1,6 +1,6 @@ use Test2::Bundle::Extended -target => 'Test2::Require::Perl'; is($CLASS->skip('v5.6'), undef, "will not skip"); -is($CLASS->skip('v10.10'), 'Perl v10.10.0 required', "will skip"); +is($CLASS->skip('v100.100'), 'Perl v100.100.0 required', "will skip"); # fix this before 2054 done_testing;