This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Add a test for source filters returned from code references in @INC.
[perl5.git] / t / op / incfilter.t
CommitLineData
bde61959
NC
1#!./perl -w
2
3# Tests for the source filters in coderef-in-@INC
4
5BEGIN {
6 chdir 't' if -d 't';
7 @INC = qw(. ../lib);
8 unless (find PerlIO::Layer 'perlio') {
9 print "1..0 # Skip: not perlio\n";
10 exit 0;
11 }
12 require "test.pl";
13}
14use strict;
15
16plan(tests => 12);
17
18unshift @INC, sub {
19 no warnings 'uninitialized';
20 ref $_[1] eq 'ARRAY' ? @{$_[1]} : $_[1];
21};
22
23my $fh;
24
25open $fh, "<", \'pass("Can return file handles from \@INC");';
26do $fh;
27
28my @origlines = ("# This is a blank line\n",
29 "pass('Can return generators from \@INC');\n",
30 "pass('Which return multiple lines');\n",
31 "1",
32 );
33my @lines = @origlines;
34sub generator {
35 $_ = shift @lines;
36 # Return of 0 marks EOF
37 return defined $_ ? 1 : 0;
38};
39
40do \&generator;
41
42@lines = @origlines;
43# Check that the array dereferencing works ready for the more complex tests:
44do [\&generator];
45
46do [sub {
47 my $param = $_[1];
48 is (ref $param, 'ARRAY', "Got our parameter");
49 $_ = shift @$param;
50 return defined $_ ? 1 : 0;
51 }, ["pass('Can return generators which take state');\n",
52 "pass('And return multiple lines');\n",
53 ]];
54
55
56open $fh, "<", \'fail("File handles and filters work from \@INC");';
57
58do [$fh, sub {s/fail/pass/}];
59
60open $fh, "<", \'fail("File handles and filters with state work from \@INC");';
61
62do [$fh, sub {s/$_[1]/pass/}, 'fail'];