3 # Tests for the source filters in coderef-in-@INC
8 unless (find PerlIO::Layer 'perlio') {
9 print "1..0 # Skip: not perlio\n";
15 use Filter::Util::Call;
20 no warnings 'uninitialized';
21 ref $_[1] eq 'ARRAY' ? @{$_[1]} : $_[1];
26 open $fh, "<", \'pass("Can return file handles from \@INC");';
29 my @origlines = ("# This is a blank line\n",
30 "pass('Can return generators from \@INC');\n",
31 "pass('Which return multiple lines');\n",
34 my @lines = @origlines;
37 # Return of 0 marks EOF
38 return defined $_ ? 1 : 0;
41 do \&generator or die;
44 # Check that the array dereferencing works ready for the more complex tests:
45 do [\&generator] or die;
49 is (ref $param, 'ARRAY', "Got our parameter");
51 return defined $_ ? 1 : 0;
52 }, ["pass('Can return generators which take state');\n",
53 "pass('And return multiple lines');\n",
57 open $fh, "<", \'fail("File handles and filters work from \@INC");';
59 do [$fh, sub {s/fail/pass/; return;}] or die;
61 open $fh, "<", \'fail("File handles and filters with state work from \@INC");';
63 do [$fh, sub {s/$_[1]/pass/; return;}, 'fail'] or die;
65 print "# 2 tests with pipes from subprocesses.\n";
67 open $fh, 'echo pass|' or die $!;
71 open $fh, 'echo fail|' or die $!;
73 do [$fh, sub {s/$_[1]/pass/; return;}, 'fail'] or die;
77 my $status = filter_read();
78 tr/A-Za-z/N-ZA-Mn-za-m/;
83 open $fh, "<", \<<'EOC';
85 cnff("This will rot13'ed prepend");
90 open $fh, "<", \<<'EOC';
92 pass("This will rot13'ed twice");
95 do [$fh, sub {tr/A-Za-z/N-ZA-Mn-za-m/; return;}] or die;
98 sub prepend_rot13_filter {
101 # Filters should append to any existing data in $_
102 # But (logically) shouldn't filter it twice.
105 my $status = filter_read();
106 my $got = substr $_, 0, length $test, '';
107 is $got, $test, "Upstream didn't alter existing data";
108 tr/A-Za-z/N-ZA-Mn-za-m/;
110 die "Looping infinitely" unless $count--;
115 open $fh, "<", \<<'EOC';
116 ORTVA {cercraq_ebg13_svygre};
117 pass("This will rot13'ed twice");
120 do [$fh, sub {tr/A-Za-z/N-ZA-Mn-za-m/; return;}] or die;
122 # This generates a heck of a lot of oks, but I think it's necessary.
124 sub prepend_block_counting_filter {
130 my $status = filter_read($amount);
131 cmp_ok (length $_, '<=', $amount, "block mode works?");
133 if ($status <= 0 or /\n/s) {
138 die "Looping infinitely";
143 open $fh, "<", \<<'EOC';
144 BEGIN {prepend_block_counting_filter};
149 do [$fh, sub {return;}] or die;
151 open $fh, "<", \<<'EOC';
152 BEGIN {prepend_block_counting_filter};
153 pas("SSS make s fast SSS");
156 do [$fh, sub {s/s/ss/gs; s/([\nS])/$1$1$1/gs; return;}] or die;
158 sub prepend_line_counting_filter {
162 my $status = filter_read();
163 my $newlines = tr/\n//;
164 cmp_ok ($newlines, '<=', 1, "1 line at most?");
165 $_ = $output . $_ if defined $output;
170 open $fh, "<", \<<'EOC';
171 BEGIN {prepend_line_counting_filter};
172 pass("You should see this line thrice");
175 do [$fh, sub {$_ .= $_ . $_; return;}] or die;