9e273c3800f5acc1a1d5a4edbf5dc4214686ae37
[p5sagit/p5-mst-13.2.git] / t / op / incfilter.t
1 #!./perl -w
2
3 # Tests for the source filters in coderef-in-@INC
4
5 BEGIN {
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 }
14 use strict;
15
16 plan(tests => 12);
17
18 unshift @INC, sub {
19     no warnings 'uninitialized';
20     ref $_[1] eq 'ARRAY' ? @{$_[1]} : $_[1];
21 };
22
23 my $fh;
24
25 open $fh, "<", \'pass("Can return file handles from \@INC");';
26 do $fh;
27
28 my @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                  );
33 my @lines = @origlines;
34 sub generator {
35     $_ = shift @lines;
36     # Return of 0 marks EOF
37     return defined $_ ? 1 : 0;
38 };
39
40 do \&generator;
41
42 @lines = @origlines;
43 # Check that the array dereferencing works ready for the more complex tests:
44 do [\&generator];
45
46 do [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
56 open $fh, "<", \'fail("File handles and filters work from \@INC");';
57
58 do [$fh, sub {s/fail/pass/}];
59
60 open $fh, "<", \'fail("File handles and filters with state work from \@INC");';
61
62 do [$fh, sub {s/$_[1]/pass/}, 'fail'];