5 require "filter-util.pl" ;
9 use vars qw( $Inc $Perl ) ;
11 my $script = <<'EOM' ;
13 print "testing, testing, 1, 2, 3\n" ;
40 my $expected_output = <<EOM ;
41 testing, testing, 1, 2, 3
53 my $filename = "decrypt.tst" ;
55 writeFile($filename, $script) ;
56 `$Perl decrypt/encrypt $filename` ;
57 writeFile('plain', 'print "This is plain text\n" ; 1 ;') ;
59 my $a = `$Perl $Inc $filename 2>&1` ;
63 print "# running perl with $Perl\n";
64 print "# test 1: \$? $?\n" unless ($? >>8) == 0 ;
66 ok(1, ($? >>8) == 0) ;
67 print "# test 2: Got '$a'\n" unless $a eq $expected_output ;
68 ok(2, $a eq $expected_output) ;
70 # try to catch error cases
72 # case 1 - Perl debugger
73 $ENV{'PERLDB_OPTS'} = 'noTTY' ;
74 $a = `$Perl $Inc -d $filename 2>&1` ;
75 print "# test 3: Got '$a'\n" unless $a =~ /debugger disabled/ ;
76 ok(3, $a =~ /debugger disabled/) ;
78 # case 2 - Perl Compiler in use
79 $a = `$Perl $Inc -MCarp -MO=Deparse $filename 2>&1` ;
82 $skip = "# skipped -- compiler not available"
83 if $a =~ /^Can't locate O\.pm in/ ||
84 $a =~ /^Can't load '/ ||
85 $a =~ /^"my" variable \$len masks/ ;
86 print "# test 4: Got '$a'\n" unless $skip || $a =~ /Aborting, Compiler detected/;
87 ok(4, ($skip || $a =~ /Aborting, Compiler detected/), $skip) ;
89 # case 3 - unknown encryption
90 writeFile($filename, <<EOM) ;
92 mary had a little lamb
95 $a = `$Perl $Inc $filename 2>&1` ;
97 print "# test 5: Got '$a'\n" unless $a =~ /bad encryption format/ ;
98 ok(5, $a =~ /bad encryption format/) ;
100 # case 4 - extra source filter on the same line
101 writeFile($filename, <<EOM) ;
102 use Filter::decrypt ; use Filter::tee '/dev/null' ;
103 mary had a little lamb
106 $a = `$Perl $Inc $filename 2>&1` ;
107 print "# test 6: Got '$a'\n" unless $a =~ /too many filters/ ;
108 ok(6, $a =~ /too many filters/) ;