Skip to content

Commit 58c00f7

Browse files
committed
Use a file from %INC instead of $^X in test
For some reason, opening `$^X` failed for someone. See GH #25.
1 parent d55ffc7 commit 58c00f7

File tree

13 files changed

+70
-31
lines changed

13 files changed

+70
-31
lines changed

Changes

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
{{$NEXT}}
22

3+
- Fixed a test failure when trying to open $^X on some platforms.
4+
5+
36
0.52 2025-08-09
47

58
- Really made it possible to force Specio to use only pure Perl dependencies. The changes in 0.51

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Specio - Type constraints and coercions for Perl
44

55
# VERSION
66

7-
version 0.52
7+
version 0.53
88

99
# SYNOPSIS
1010

lib/Test/Specio.pm

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,9 +223,24 @@ BEGIN {
223223
}
224224
}
225225

226-
our @EXPORT_OK = ( @vars, qw( builtins_tests describe test_constraint ) );
226+
our @EXPORT_OK = (
227+
@vars,
228+
qw( builtins_tests create_BAR_handle_code describe test_constraint )
229+
);
227230
our %EXPORT_TAGS = ( vars => \@vars );
228231

232+
sub create_BAR_handle_code {
233+
234+
# This used to be $^X, but that caused a test failure for someone
235+
# (https://github.com/houseabsolute/Specio/issues/25). Then I tried __FILE__, but that doesn't work
236+
# in cases where the file containing __FILE__ is eval'd, which we do in
237+
# `xt/author/no-ref-util.t`. So now I'm just grabbing the first file in %INC.
238+
return <<'EOF';
239+
my $file = $INC{ ( keys %INC )[0] };
240+
open BAR, '<', $file or die "Could not open $file for the test";
241+
EOF
242+
}
243+
229244
sub builtins_tests {
230245
my $GLOB = shift;
231246
my $GLOB_OVERLOAD = shift;
@@ -1516,5 +1531,5 @@ If you want to create a glob overloading object that returns a filehandle, do
15161531
this:
15171532
15181533
local *BAR;
1519-
open BAR, '<', $^X or die "Could not open $^X for the test";
1520-
my $GLOB_OVERLOAD_FH = _T::GlobOverload->new( \*BAR );
1534+
my $file = __FILE__;
1535+
open BAR, '<', $file or die "Could not open $file for the test";

t/builtins-sanity.t

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ use strict;
22
use warnings;
33

44
use Test::More 0.96;
5-
use Test::Specio qw( builtins_tests describe test_constraint :vars );
5+
use Test::Specio
6+
qw( builtins_tests create_BAR_handle_code describe test_constraint :vars );
67

78
use Specio::Library::Builtins;
89

@@ -20,9 +21,12 @@ my $GLOB_OVERLOAD = _T::GlobOverload->new( \*FOO );
2021

2122
local *BAR;
2223
{
23-
## no critic (InputOutput::ProhibitBarewordFileHandles, InputOutput::RequireBriefOpen)
24-
open BAR, '<', $^X or die "Could not open $^X for the test";
24+
local $@;
25+
## no critic (BuiltinFunctions::ProhibitStringyEval, ErrorHandling::RequireCheckingReturnValueOfEval)
26+
eval create_BAR_handle_code();
27+
die $@ if $@;
2528
}
29+
2630
my $GLOB_OVERLOAD_FH = _T::GlobOverload->new( \*BAR );
2731

2832
my $tests = builtins_tests( $GLOB, $GLOB_OVERLOAD, $GLOB_OVERLOAD_FH );

t/declare-helpers.t

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use warnings;
33

44
use Test::Fatal;
55
use Test::More 0.96;
6-
use Test::Specio qw( describe test_constraint :vars );
6+
use Test::Specio qw( create_BAR_handle_code describe test_constraint :vars );
77

88
use Specio::Declare;
99
use Specio::PartialDump qw( partial_dump );
@@ -22,8 +22,10 @@ my $GLOB_OVERLOAD = _T::GlobOverload->new( \*FOO );
2222

2323
local *BAR;
2424
{
25-
## no critic (InputOutput::ProhibitBarewordFileHandles, InputOutput::RequireBriefOpen)
26-
open BAR, '<', $^X or die "Could not open $^X for the test";
25+
local $@;
26+
## no critic (BuiltinFunctions::ProhibitStringyEval, ErrorHandling::RequireCheckingReturnValueOfEval)
27+
eval create_BAR_handle_code();
28+
die $@ if $@;
2729
}
2830
my $GLOB_OVERLOAD_FH = _T::GlobOverload->new( \*BAR );
2931

t/dict.t

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use warnings;
33

44
use Test::Fatal;
55
use Test::More 0.96;
6-
use Test::Specio qw( test_constraint :vars );
6+
use Test::Specio qw( create_BAR_handle_code test_constraint :vars );
77

88
use Specio::Declare;
99
use Specio::Library::Builtins;
@@ -75,8 +75,10 @@ my $GLOB_OVERLOAD = _T::GlobOverload->new( \*FOO );
7575

7676
local *BAR;
7777
{
78-
## no critic (InputOutput::ProhibitBarewordFileHandles, InputOutput::RequireBriefOpen)
79-
open BAR, '<', $^X or die "Could not open $^X for the test";
78+
local $@;
79+
## no critic (BuiltinFunctions::ProhibitStringyEval, ErrorHandling::RequireCheckingReturnValueOfEval)
80+
eval create_BAR_handle_code();
81+
die $@ if $@;
8082
}
8183
my $GLOB_OVERLOAD_FH = _T::GlobOverload->new( \*BAR );
8284

t/intersection.t

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use lib "$lib_path/lib";
1818

1919
use Test::Fatal;
2020
use Test::More 0.96;
21-
use Test::Specio qw( test_constraint :vars );
21+
use Test::Specio qw( create_BAR_handle_code test_constraint :vars );
2222

2323
use Specio::Constraint::Intersection;
2424
use Specio::Declare;
@@ -50,8 +50,10 @@ my $GLOB_OVERLOAD = _T::GlobOverload->new( \*FOO );
5050

5151
local *BAR;
5252
{
53-
## no critic (InputOutput::ProhibitBarewordFileHandles, InputOutput::RequireBriefOpen)
54-
open BAR, '<', $^X or die "Could not open $^X for the test";
53+
local $@;
54+
## no critic (BuiltinFunctions::ProhibitStringyEval, ErrorHandling::RequireCheckingReturnValueOfEval)
55+
eval create_BAR_handle_code();
56+
die $@ if $@;
5557
}
5658
my $GLOB_OVERLOAD_FH = _T::GlobOverload->new( \*BAR );
5759

t/map.t

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use warnings;
33

44
use Test::Fatal;
55
use Test::More 0.96;
6-
use Test::Specio qw( test_constraint :vars );
6+
use Test::Specio qw( create_BAR_handle_code test_constraint :vars );
77

88
use Specio::Declare;
99
use Specio::Library::Builtins;
@@ -45,8 +45,10 @@ my $GLOB_OVERLOAD = _T::GlobOverload->new( \*FOO );
4545

4646
local *BAR;
4747
{
48-
## no critic (InputOutput::ProhibitBarewordFileHandles, InputOutput::RequireBriefOpen)
49-
open BAR, '<', $^X or die "Could not open $^X for the test";
48+
local $@;
49+
## no critic (BuiltinFunctions::ProhibitStringyEval, ErrorHandling::RequireCheckingReturnValueOfEval
50+
eval create_BAR_handle_code();
51+
die $@ if $@;
5052
}
5153
my $GLOB_OVERLOAD_FH = _T::GlobOverload->new( \*BAR );
5254

t/string-sanity.t

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ BEGIN {
1717
use lib "$lib_path/lib";
1818

1919
use Test::More 0.96;
20-
use Test::Specio qw( test_constraint :vars );
20+
use Test::Specio qw( create_BAR_handle_code test_constraint :vars );
2121

2222
use Specio::Library::String;
2323

@@ -35,8 +35,10 @@ my $GLOB_OVERLOAD = _T::GlobOverload->new( \*FOO );
3535

3636
local *BAR;
3737
{
38-
## no critic (InputOutput::ProhibitBarewordFileHandles, InputOutput::RequireBriefOpen)
39-
open BAR, '<', $^X or die "Could not open $^X for the test";
38+
local $@;
39+
## no critic (BuiltinFunctions::ProhibitStringyEval, ErrorHandling::RequireCheckingReturnValueOfEval)
40+
eval create_BAR_handle_code();
41+
die $@ if $@;
4042
}
4143
my $GLOB_OVERLOAD_FH = _T::GlobOverload->new( \*BAR );
4244

t/subs.t

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use lib "$lib_path/lib";
1818

1919
use Test::Fatal;
2020
use Test::More 0.96;
21-
use Test::Specio qw( builtins_tests describe :vars );
21+
use Test::Specio qw( create_BAR_handle_code builtins_tests describe :vars );
2222

2323
use Specio::Declare;
2424
use Specio::Subs qw(
@@ -40,8 +40,10 @@ my $GLOB_OVERLOAD = _T::GlobOverload->new( \*FOO );
4040

4141
local *BAR;
4242
{
43-
## no critic (InputOutput::ProhibitBarewordFileHandles, InputOutput::RequireBriefOpen)
44-
open BAR, '<', $^X or die "Could not open $^X for the test";
43+
local $@;
44+
## no critic (BuiltinFunctions::ProhibitStringyEval, ErrorHandling::RequireCheckingReturnValueOfEval)
45+
eval create_BAR_handle_code();
46+
die $@ if $@;
4547
}
4648
my $GLOB_OVERLOAD_FH = _T::GlobOverload->new( \*BAR );
4749

0 commit comments

Comments
 (0)