Add the following packages libalgorithm-diff-perl libspiffy-perl libtext-diff-perl...
[pkg-perl] / deb-src / libfilter-perl / libfilter-perl-1.34 / t / decrypt.t
1
2 use strict;
3 use warnings;
4
5 require "filter-util.pl" ;
6 use Cwd ;
7 my $here = getcwd ;
8
9 use vars qw( $Inc $Perl ) ;
10
11 my $script = <<'EOM' ;
12
13 print "testing, testing, 1, 2, 3\n" ;
14 require "./plain" ;
15 use Cwd ;
16 $cwd = getcwd ;
17 print <<EOT ;
18 some
19 more test
20 lines
21 EOT
22
23 print "a multi-line
24  string
25 $cwd\n" ;
26
27 format STDOUT_TOP =
28 I'm a format top
29 .
30
31 format STDOUT =
32 @<<<<<<<<<
33 "I'm not"
34 .
35
36
37 write ;
38 EOM
39
40 my $expected_output = <<EOM ;
41 testing, testing, 1, 2, 3
42 This is plain text
43 some
44 more test
45 lines
46 a multi-line
47  string
48 $here
49 I'm a format top
50 I'm not
51 EOM
52
53 my $filename = "decrypt.tst" ;
54
55 writeFile($filename, $script) ;
56 `$Perl decrypt/encrypt $filename` ;
57 writeFile('plain', 'print "This is plain text\n" ; 1 ;') ;
58
59 my $a = `$Perl $Inc $filename 2>&1` ;
60
61 print "1..6\n" ;
62
63 print "# running perl with $Perl\n";
64 print "# test 1: \$? $?\n" unless ($? >>8) == 0 ;
65
66 ok(1, ($? >>8) == 0) ;
67 print "# test 2: Got '$a'\n" unless $a eq $expected_output ;
68 ok(2, $a eq $expected_output) ;
69
70 # try to catch error cases
71
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/) ;
77
78 # case 2 - Perl Compiler in use
79 $a = `$Perl $Inc -MCarp -MO=Deparse $filename 2>&1` ;
80 #print "[[$a]]\n" ;
81 my $skip = "" ;
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) ;
88
89 # case 3 - unknown encryption
90 writeFile($filename, <<EOM) ;
91 use Filter::decrypt ;
92 mary had a little lamb
93 EOM
94
95 $a = `$Perl $Inc $filename 2>&1` ;
96
97 print "# test 5: Got '$a'\n" unless $a =~ /bad encryption format/ ;
98 ok(5, $a =~ /bad encryption format/) ;
99
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
104 EOM
105  
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/) ;
109
110 unlink $filename ;
111 unlink 'plain' ;