summaryrefslogtreecommitdiff
path: root/t/op
diff options
context:
space:
mode:
authorNicholas Clark <nick@ccl4.org>2006-04-15 11:59:26 +0000
committerNicholas Clark <nick@ccl4.org>2006-04-15 11:59:26 +0000
commitbde61959ea5e52e421c597172a9aeac53357fcd9 (patch)
treef6edde30b9481d491df2e699630a68e9fe2c8797 /t/op
parent719e2301283f7f9650137ddbdf3fd72ce198629b (diff)
downloadperl-bde61959ea5e52e421c597172a9aeac53357fcd9.tar.gz
Add a test for source filters returned from code references in @INC.
p4raw-id: //depot/perl@27811
Diffstat (limited to 't/op')
-rw-r--r--t/op/incfilter.t62
1 files changed, 62 insertions, 0 deletions
diff --git a/t/op/incfilter.t b/t/op/incfilter.t
new file mode 100644
index 0000000000..9e273c3800
--- /dev/null
+++ b/t/op/incfilter.t
@@ -0,0 +1,62 @@
+#!./perl -w
+
+# Tests for the source filters in coderef-in-@INC
+
+BEGIN {
+ chdir 't' if -d 't';
+ @INC = qw(. ../lib);
+ unless (find PerlIO::Layer 'perlio') {
+ print "1..0 # Skip: not perlio\n";
+ exit 0;
+ }
+ require "test.pl";
+}
+use strict;
+
+plan(tests => 12);
+
+unshift @INC, sub {
+ no warnings 'uninitialized';
+ ref $_[1] eq 'ARRAY' ? @{$_[1]} : $_[1];
+};
+
+my $fh;
+
+open $fh, "<", \'pass("Can return file handles from \@INC");';
+do $fh;
+
+my @origlines = ("# This is a blank line\n",
+ "pass('Can return generators from \@INC');\n",
+ "pass('Which return multiple lines');\n",
+ "1",
+ );
+my @lines = @origlines;
+sub generator {
+ $_ = shift @lines;
+ # Return of 0 marks EOF
+ return defined $_ ? 1 : 0;
+};
+
+do \&generator;
+
+@lines = @origlines;
+# Check that the array dereferencing works ready for the more complex tests:
+do [\&generator];
+
+do [sub {
+ my $param = $_[1];
+ is (ref $param, 'ARRAY', "Got our parameter");
+ $_ = shift @$param;
+ return defined $_ ? 1 : 0;
+ }, ["pass('Can return generators which take state');\n",
+ "pass('And return multiple lines');\n",
+ ]];
+
+
+open $fh, "<", \'fail("File handles and filters work from \@INC");';
+
+do [$fh, sub {s/fail/pass/}];
+
+open $fh, "<", \'fail("File handles and filters with state work from \@INC");';
+
+do [$fh, sub {s/$_[1]/pass/}, 'fail'];