5 require Config; import Config;
6 if ($Config{'extensions'} !~ m{\bFilter/Util/Call\b}) {
7 print "1..0 # Skip: Filter::Util::Call was not built\n";
10 require 'lib/filter-util.pl';
16 use vars qw($Inc $Perl);
26 my $filename = "call.tst" ;
27 my $filenamebin = "call.bin" ;
28 my $module = "MyTest" ;
29 my $module2 = "MyTest2" ;
30 my $module3 = "MyTest3" ;
31 my $module4 = "MyTest4" ;
32 my $module5 = "MyTest5" ;
33 my $nested = "nested" ;
35 my $redir = $^O eq 'MacOS' ? "" : "2>&1";
40 # no filter function in module
41 ###############################
43 writeFile("${module}.pm", <<EOM) ;
46 use Filter::Util::Call ;
48 sub import { filter_add(bless []) }
53 my $a = `$Perl "-I." $Inc -e "use ${module} ;" $redir` ;
54 ok(1, (($? >>8) != 0 or (($^O eq 'MSWin32' || $^O eq 'MacOS' || $^O eq 'NetWare' || $^O eq 'mpeix') && $? != 0))) ;
55 ok(2, $a =~ /^Can't locate object method "filter" via package "MyTest"/) ;
57 # no reference parameter in filter_add
58 ######################################
60 writeFile("${module}.pm", <<EOM) ;
63 use Filter::Util::Call ;
65 sub import { filter_add() }
70 $a = `$Perl "-I." $Inc -e "use ${module} ;" $redir` ;
71 ok(3, (($? >>8) != 0 or (($^O eq 'MSWin32' || $^O eq 'MacOS' || $^O eq 'NetWare' || $^O eq 'mpeix') && $? != 0))) ;
72 #ok(4, $a =~ /^usage: filter_add\(ref\) at ${module}.pm/) ;
73 ok(4, $a =~ /^Not enough arguments for Filter::Util::Call::filter_add/) ;
82 # a simple filter, using a closure
85 writeFile("${module}.pm", <<EOM, <<'EOM') ;
89 use Filter::Util::Call ;
96 if (($status = filter_read()) > 0) {
106 writeFile($filename, <<EOM, <<'EOM') ;
113 print "I am $here\n" ;
114 print "some letters ABC\n" ;
117 Alphabetti Spagetti ($y)
122 $a = `$Perl "-I." $Inc $filename $redir` ;
123 ok(5, ($? >>8) == 0) ;
127 Alphabetti Spagetti (DEFDEF)
130 # a simple filter, not using a closure
133 writeFile("${module}.pm", <<EOM, <<'EOM') ;
137 use Filter::Util::Call ;
138 sub import { filter_add(bless []) }
145 if (($status = filter_read()) > 0) {
155 writeFile($filename, <<EOM, <<'EOM') ;
162 print "I am $here\n" ;
163 print "some letters ABC\n" ;
166 Alphabetti Spagetti ($y)
171 $a = `$Perl "-I." $Inc $filename $redir` ;
172 ok(7, ($? >>8) == 0) ;
176 Alphabetti Spagetti (DEFDEF)
184 writeFile("${module2}.pm", <<EOM, <<'EOM') ;
186 use Filter::Util::Call ;
189 sub import { filter_add(bless []) }
196 if (($status = filter_read()) > 0) {
205 writeFile("${module3}.pm", <<EOM, <<'EOM') ;
207 use Filter::Util::Call ;
210 sub import { filter_add(
216 if (($status = filter_read()) > 0) {
226 writeFile("${module4}.pm", <<EOM) ;
231 print "I'm feeling used!\n" ;
232 print "Fred Joe ABC DEF PQR XYZ\n" ;
233 print "See you Today\n" ;
237 writeFile("${module5}.pm", <<EOM, <<'EOM') ;
239 use Filter::Util::Call ;
242 sub import { filter_add(bless []) }
249 if (($status = filter_read()) > 0) {
258 writeFile($filename, <<EOM, <<'EOM') ;
260 # two filters for this file
267 print "some letters ABCXYZ\n" ;
270 Fred likes Alphabetti Spagetti ($y)
275 writeFile($nested, <<EOM, <<'EOM') ;
279 print "This is another file XYZ\n" ;
286 $a = `$Perl "-I." $Inc $filename $redir` ;
287 ok(9, ($? >>8) == 0) ;
288 ok(10, $a eq <<EOM) ;
290 Fred Joe ABC DEF PQR XYZ
292 This is another file XYZ
295 Fred likes Alphabetti Spagetti (DEFDEFPQR)
298 # using the module context (with a closure)
299 ###########################################
302 writeFile("${module2}.pm", <<EOM, <<'EOM') ;
304 use Filter::Util::Call ;
320 if (($status = filter_read()) > 0) {
321 foreach $pattern (@strings)
334 writeFile($filename, <<EOM, <<'EOM') ;
336 use $module2 qw( XYZ KLM) ;
337 use $module2 qw( ABC NMO) ;
340 print "some letters ABCXYZ KLM NMO\n" ;
341 $y = "ABCDEFXYZKLMNMO" ;
343 Alphabetti Spagetti ($y)
348 $a = `$Perl "-I." $Inc $filename $redir` ;
349 ok(11, ($? >>8) == 0) ;
350 ok(12, $a eq <<EOM) ;
351 some letters PQRPQR PQR PQR
352 Alphabetti Spagetti (PQRDEFPQRPQRPQR)
357 # using the module context (without a closure)
358 ##############################################
361 writeFile("${module2}.pm", <<EOM, <<'EOM') ;
363 use Filter::Util::Call ;
372 filter_add (bless [@strings])
381 if (($status = filter_read()) > 0) {
382 foreach $pattern (@$self)
393 writeFile($filename, <<EOM, <<'EOM') ;
395 use $module2 qw( XYZ KLM) ;
396 use $module2 qw( ABC NMO) ;
399 print "some letters ABCXYZ KLM NMO\n" ;
400 $y = "ABCDEFXYZKLMNMO" ;
402 Alphabetti Spagetti ($y)
407 $a = `$Perl "-I." $Inc $filename $redir` ;
408 ok(13, ($? >>8) == 0) ;
409 ok(14, $a eq <<EOM) ;
410 some letters PQRPQR PQR PQR
411 Alphabetti Spagetti (PQRDEFPQRPQRPQR)
418 writeFile("${module2}.pm", <<EOM, <<'EOM') ;
420 use Filter::Util::Call ;
438 if (($status = filter_read()) > 0) {
441 # and now the second line (it will append)
442 $status = filter_read() ;
452 writeFile($filename, <<EOM, <<'EOM') ;
467 $a = `$Perl "-I." $Inc $filename $redir` ;
468 ok(15, ($? >>8) == 0) ;
469 ok(16, $a eq <<EOM) ;
477 writeFile("${block}.pm", <<EOM, <<'EOM') ;
479 use Filter::Util::Call ;
488 filter_add (bless [@strings] )
503 my $string = <<'EOM' ;
504 print "hello mum\n" ;
506 print "Who wants it?\n$x\n" ;
510 writeFile($filename, <<EOM, $string ) ;
514 $a = `$Perl "-I." $Inc $filename $redir` ;
515 ok(17, ($? >>8) == 0) ;
516 ok(18, $a eq <<EOM) ;
525 writeFile("${block}.pm", <<EOM, <<'EOM') ;
527 use Filter::Util::Call ;
538 filter_add(bless [@strings] )
545 my ($here) = quotemeta getcwd ;
547 if (($status = filter_read()) > 0) {
556 writeFile($filename, <<EOM, <<'EOM') ;
559 print "We are in DIR\n" ;
562 $a = `$Perl "-I." $Inc $filename $redir` ;
563 ok(19, ($? >>8) == 0) ;
564 ok(20, $a eq <<EOM) ;
572 writeFile("${block}.pm", <<EOM, <<'EOM') ;
574 use Filter::Util::Call ;
584 filter_add(bless \$count )
593 if ($status = filter_read()) > 0 ;
596 filter_del() if $$self <= 0 ;
604 writeFile($filename, <<EOM, <<'EOM') ;
610 HERE today gone tomorrow\n" ;
613 $a = `$Perl "-I." $Inc $filename $redir` ;
614 ok(21, ($? >>8) == 0) ;
615 ok(22, $a eq <<EOM) ;
619 HERE today gone tomorrow
626 writeFile("${block}.pm", <<EOM, <<'EOM') ;
628 use Filter::Util::Call ;
636 filter_add(bless [] )
644 if (($status = filter_read_exact(9)) > 0) {
654 writeFile($filenamebin, <<EOM, <<'EOM') ;
660 HERE today gone tomorrow\n" ;
663 $a = `$Perl "-I." $Inc $filenamebin $redir` ;
664 ok(23, ($? >>8) == 0) ;
665 ok(24, $a eq <<EOM) ;
669 THERE today gone tomorrow
677 writeFile("${block}.pm", <<EOM, <<'EOM') ;
679 use Filter::Util::Call ;
687 filter_add(bless [] )
695 if (($status = filter_read()) > 0) {
705 writeFile($filename, <<EOM, <<'EOM') ;
714 HERE today gone tomorrow
717 $a = `$Perl "-I." $Inc $filename $redir` ;
718 ok(25, ($? >>8) == 0) ;
719 ok(26, $a eq <<EOM) ;
723 HERE today gone tomorrow
733 writeFile("${block}.pm", <<EOM, <<'EOM') ;
735 use Filter::Util::Call ;
743 filter_add(bless [] )
751 if (($status = filter_read()) > 0) {
761 writeFile($filename, <<EOM, <<'EOM') ;
770 HERE today gone tomorrow
773 $a = `$Perl "-I." $Inc $filename $redir` ;
774 ok(27, ($? >>8) == 0) ;
775 ok(28, $a eq <<EOM) ;
779 HERE today gone tomorrow
785 1 while unlink $filename ;
786 1 while unlink $filenamebin ;
787 1 while unlink "${module}.pm" ;
788 1 while unlink "${module2}.pm" ;
789 1 while unlink "${module3}.pm" ;
790 1 while unlink "${module4}.pm" ;
791 1 while unlink "${module5}.pm" ;
792 1 while unlink $nested ;
793 1 while unlink "${block}.pm" ;