Skip to content
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions lib/App/Prove.pm
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use strict;
use warnings;

use TAP::Harness::Env;
use TAP::Harness::Runtime qw (IS_UNIXY IS_VMS IS_WIN32);
use Text::ParseWords qw(shellwords);
use File::Spec;
use Getopt::Long;
Expand Down Expand Up @@ -40,10 +41,6 @@ wrapper around an instance of this module.

=cut

use constant IS_WIN32 => ( $^O =~ /^(MS)?Win32$/ );
use constant IS_VMS => $^O eq 'VMS';
use constant IS_UNIXY => !( IS_VMS || IS_WIN32 );

use constant STATE_FILE => IS_UNIXY ? '.prove' : '_prove';
use constant RC_FILE => IS_UNIXY ? '.proverc' : '_proverc';

Expand Down
3 changes: 2 additions & 1 deletion lib/App/Prove/State.pm
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ use Carp;
use App::Prove::State::Result;
use TAP::Parser::YAMLish::Reader ();
use TAP::Parser::YAMLish::Writer ();
use TAP::Harness::Runtime qw (IS_WIN32);

use base 'TAP::Base';

BEGIN {
__PACKAGE__->mk_methods('result_class');
}

use constant IS_WIN32 => ( $^O =~ /^(MS)?Win32$/ );
use constant NEED_GLOB => IS_WIN32;

=head1 NAME
Expand Down
7 changes: 3 additions & 4 deletions lib/TAP/Base.pm
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ use warnings;

use base 'TAP::Object';

use TAP::Harness::Runtime qw (time HAS_TIME_HIRES);

=head1 NAME

TAP::Base - Base class that provides common functionality to L<TAP::Parser>
Expand All @@ -18,10 +20,7 @@ Version 3.51_01

our $VERSION = '3.51_01';

use constant GOT_TIME_HIRES => do {
eval 'use Time::HiRes qw(time);';
$@ ? 0 : 1;
};
use constant GOT_TIME_HIRES => HAS_TIME_HIRES;

=head1 SYNOPSIS

Expand Down
2 changes: 1 addition & 1 deletion lib/TAP/Formatter/Color.pm
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package TAP::Formatter::Color;
use strict;
use warnings;

use constant IS_WIN32 => ( $^O =~ /^(MS)?Win32$/ );
use TAP::Harness::Runtime qw (IS_WIN32);

use base 'TAP::Object';

Expand Down
3 changes: 2 additions & 1 deletion lib/TAP/Harness/Env.pm
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ package TAP::Harness::Env;
use strict;
use warnings;

use constant IS_VMS => ( $^O eq 'VMS' );
use TAP::Harness::Runtime qw (IS_VMS);

use TAP::Object;
use Text::ParseWords qw/shellwords/;

Expand Down
118 changes: 118 additions & 0 deletions lib/TAP/Harness/Runtime.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
package TAP::Harness::Runtime;

use strict;
use warnings;

use base q (Exporter);

use constant HAS_TIME_HIRES => !! eval q { use Time::HiRes qw (time); 1 };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This changes the eval from a block style evaluation to a string, which is not a good change.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Block eval would not be able to test a use statement, but this can easily be done with a block eval: eval { require Time::HiRes; Time::HiRes->import('time'); 1 }

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@karenetheridge original code had string evaluation.

I'm using form q { } for string containing code (hence { as paired delimiter).

commit introducing this change is fixup! of original commit. I'm using such approach to show reaction to code review comment, referring fixup commit(s) dealing with given issue raised in given comment.
(when I was taught this approach I hesitated but at the end, in many PR-review cycles, I found out that review by commit and reacting with fixups saved lot of time especially on reviewer's side)

@Grinnz my aim was only to extract existing runtime detection into dedicated library, but your suggestion is too good to be omitted ... 033f677

use constant IS_VMS => $^O eq q (VMS);
use constant IS_WIN32 => ($^O =~ qr (^ (MS) Win32 $)x);
use constant IS_UNIXY => ! (IS_VMS || IS_WIN32);

my @constants = qw (
IS_VMS
IS_WIN32
IS_UNIXY
HAS_TIME_HIRES
);

our @EXPORT_OK = (
@constants,
HAS_TIME_HIRES ? qw (time) : (),
);

our %EXPORT_TAGS = (
all => \ @EXPORT_OK,
constants => \ @constants,
);

sub import {
my ($caller, @arguments) = @_;

# 'time' is exported only when Time::HiRes is available
# but can be always requested
@arguments = grep { $_ ne q (time) } @arguments
unless HAS_TIME_HIRES
;

local @_ = ($caller, @arguments);
goto \ &Exporter::import;
}

1;

__END__

=pod

=encoding utf8

=head1 NAME

TAP::Harness::Runtime - constants to identify runtime environment

=head1 SYNOPSIS

package My:Superb::Package;

# import constants
use TAP::Harness::Runtime qw (:constants);

=head1 DESCRIPTION

Module wraps runtime detection used by multiple modules into single module.

=head1 EXPORTABLE FUNCTIONS

=head2 HAS_TIME_HIRES

Constant evaluating as C<true> when module L<Time::HiRes> is importable.

=head2 IS_VMS

Constant evaluating as C<true> when running on VMS.

=head2 IS_WIN32

Constant evaluating as C<true> when running on Windows (32-bit or 64-bit)

=head2 IS_UNIXY

Constant evaluating as C<true> when running system which behaves like Unix.

=head2 time

When L<Time::HiRes> is available module reexports its C<time> function.

Symbol can be requested for import even if L<Time::HiRes> isn't available
without causing any error.

=head1 EXPORT TAGS

=head2 all

Import all exported symbols.

=head2 constants

Import all constants.

=head1 SEE ALSO

L<TAP::Harness>

=head1 BUGS

Please report any bugs or feature request at
L<https://github.com/Perl-Toolchain-Gang/Test-Harness/issues>

=head1 REPOSITORY

L<https://github.com/Perl-Toolchain-Gang/Test-Harness>

=head1 LICENCE AND COPYRIGHT

This module is free software; you can redistribute it and/or
modify it under same terms as L<Test::Harness> distribution.

4 changes: 3 additions & 1 deletion lib/TAP/Parser/Iterator.pm
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ use warnings;

use base 'TAP::Object';

use TAP::Harness::Runtime qw (IS_VMS);

=head1 NAME

TAP::Parser::Iterator - Base class for TAP source iterators
Expand Down Expand Up @@ -61,7 +63,7 @@ Iterate raw input without applying any fixes for quirky input syntax.

=cut

if ( $^O eq 'VMS' ) {
if (IS_VMS) {
eval <<'END' ;
sub next {
my $self = shift;
Expand Down
2 changes: 1 addition & 1 deletion lib/TAP/Parser/Iterator/Process.pm
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use IO::Handle;

use base 'TAP::Parser::Iterator';

use constant IS_WIN32 => !!( $^O =~ /^(MS)?Win32$/ );
use TAP::Harness::Runtime qw (IS_WIN32);

=head1 NAME

Expand Down
6 changes: 3 additions & 3 deletions lib/TAP/Parser/Multiplexer.pm
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ use Errno;

use base 'TAP::Object';

use constant IS_WIN32 => $^O =~ /^(MS)?Win32$/;
use constant IS_VMS => $^O eq 'VMS';
use constant SELECT_OK => !( IS_VMS || IS_WIN32 );
use TAP::Harness::Runtime qw (IS_UNIXY IS_VMS IS_WIN32);

use constant SELECT_OK => IS_UNIXY;

=head1 NAME

Expand Down
3 changes: 1 addition & 2 deletions lib/TAP/Parser/SourceHandler/Perl.pm
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ use strict;
use warnings;
use Config;

use constant IS_WIN32 => ( $^O =~ /^(MS)?Win32$/ );
use constant IS_VMS => ( $^O eq 'VMS' );
use TAP::Harness::Runtime qw (IS_VMS IS_WIN32);

use TAP::Parser::IteratorFactory ();
use TAP::Parser::Iterator::Process ();
Expand Down
9 changes: 2 additions & 7 deletions lib/Test/Harness.pm
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@ use 5.006;
use strict;
use warnings;

use constant IS_WIN32 => ( $^O =~ /^(MS)?Win32$/ );
use constant IS_VMS => ( $^O eq 'VMS' );

use TAP::Harness ();
use TAP::Harness::Runtime qw (HAS_TIME_HIRES IS_WIN32 IS_VMS);
use TAP::Parser::Aggregator ();
use TAP::Parser::Source ();
use TAP::Parser::SourceHandler::Perl ();
Expand All @@ -20,10 +18,7 @@ use base 'Exporter';

# $ML $Last_ML_Print

BEGIN {
eval q{use Time::HiRes 'time'};
our $has_time_hires = !$@;
}
our $has_time_hires = HAS_TIME_HIRES;

=head1 NAME

Expand Down
3 changes: 2 additions & 1 deletion t/compat/env.t
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ use strict;
use warnings;
use lib 't/lib';

use TAP::Harness::Runtime qw (IS_VMS);
use Test::More (
$^O eq 'VMS'
IS_VMS
? ( skip_all => 'VMS' )
: ( tests => 1 )
);
Expand Down
4 changes: 3 additions & 1 deletion t/compat/inc-propagation.t
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ use warnings;
use lib 't/lib';
use Config;

use TAP::Harness::Runtime qw (IS_VMS);

local
$ENV{PERL5OPT}; # avoid any user-provided PERL5OPT from contaminating @INC

Expand All @@ -22,7 +24,7 @@ sub has_crazy_patch {
}

use Test::More (
$^O eq 'VMS' ? ( skip_all => 'VMS' )
IS_VMS ? ( skip_all => 'VMS' )
: has_crazy_patch() ? ( skip_all => 'Incompatible @INC patch' )
: exists $ENV{HARNESS_PERL_SWITCHES}
? ( skip_all => 'Someone messed with HARNESS_PERL_SWITCHES' )
Expand Down
3 changes: 2 additions & 1 deletion t/compat/subclass.t
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ use strict;
use warnings;
use lib 't/lib';

use TAP::Harness::Runtime qw (IS_VMS);
use Test::More (
$^O eq 'VMS'
IS_VMS
? ( skip_all => 'VMS' )
: ( tests => 1 )
);
Expand Down
4 changes: 3 additions & 1 deletion t/compat/switches.t
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

use strict;
use warnings;

use TAP::Harness::Runtime qw (IS_VMS);
use Test::More (
$^O eq 'VMS'
IS_VMS
? ( skip_all => 'VMS' )
: ( tests => 4 )
);
Expand Down
14 changes: 8 additions & 6 deletions t/compat/test-harness-compat.t
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ use Config;

# use lib 't/lib';

use TAP::Harness::Runtime qw (IS_VMS);

use Test::More;
use File::Spec;
use Test::Harness qw(execute_tests);
Expand Down Expand Up @@ -150,7 +152,7 @@ if ($NoTaintSupport) {
'name' => "$TEST_DIR/too_many",
'wstat' => '1024'
},
( $^O eq 'VMS' ?
( IS_VMS ?
("$TEST_DIR/vms_nit" => {
'canon' => 1,
'estat' => '',
Expand All @@ -173,12 +175,12 @@ if ($NoTaintSupport) {
}
},
'totals' => {
'bad' => ($NoTaintSupport ? 11 : 12)-($^O eq 'VMS' ? 0 : 1),
'bad' => ($NoTaintSupport ? 11 : 12)-(IS_VMS ? 0 : 1),
'bonus' => 1,
'files' => ($NoTaintSupport ? 24 : 27),
'good' => ($NoTaintSupport ? 13 : 15)+($^O eq 'VMS' ? 0 : 1),
'good' => ($NoTaintSupport ? 13 : 15)+(IS_VMS ? 0 : 1),
'max' => ($NoTaintSupport ? 72 : 76),
'ok' => ($NoTaintSupport ? 75 : 78)+($^O eq 'VMS' ? 0 : 1),
'ok' => ($NoTaintSupport ? 75 : 78)+(IS_VMS ? 0 : 1),
'skipped' => 2,
'sub_skipped' => 2,
'tests' => ($NoTaintSupport ? 24 : 27),
Expand Down Expand Up @@ -742,7 +744,7 @@ if ($NoTaintSupport) {
'todo' => 0
}
},
( $^O eq 'VMS' ?
( IS_VMS ?
('vms_nit' => {
'failed' => {
"$TEST_DIR/vms_nit" => {
Expand Down Expand Up @@ -797,7 +799,7 @@ if ($NoTaintSupport) {

sub vague_status {
my $hash = shift;
return $hash unless $^O eq 'VMS';
return $hash unless IS_VMS;

while ( my ( $file, $want ) = each %$hash ) {
for (qw( estat wstat )) {
Expand Down
4 changes: 3 additions & 1 deletion t/perl5lib.t
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ use warnings;
use lib 't/lib';
use Config;

use TAP::Harness::Runtime qw (IS_VMS);

my $path_sep = $Config{path_sep};

sub has_crazy_patch {
Expand All @@ -21,7 +23,7 @@ sub has_crazy_patch {
}

use Test::More (
$^O eq 'VMS' ? ( skip_all => 'VMS' )
IS_VMS ? ( skip_all => 'VMS' )
: has_crazy_patch() ? ( skip_all => 'Incompatible @INC patch' )
: ( tests => 1 )
);
Expand Down
Loading