Clarify the status of bundled external perl modules
[openssl.git] / external / perl / Text-Template-1.46 / t / 07-safe3.t
1 #!perl
2 #
3 # test apparatus for Text::Template module
4
5 use Text::Template;
6
7 BEGIN {
8   eval "use Safe";
9   if ($@) {
10     print "1..0\n";
11     exit 0;
12   }
13 }
14
15 die "This is the test program for Text::Template version 1.46.
16 You are using version $Text::Template::VERSION instead.
17 That does not make sense.\n
18 Aborting"
19   unless $Text::Template::VERSION == 1.46;
20
21 print "1..3\n";
22
23 $n=1;
24
25 # Test the OUT feature with safe compartments
26
27 $template = q{
28 This line should have a 3: {1+2}
29
30 This line should have several numbers:
31 { $t = ''; foreach $n (1 .. 20) { $t .= $n . ' ' } $t }
32 };
33
34 $templateOUT = q{
35 This line should have a 3: { $OUT = 1+2 }
36
37 This line should have several numbers:
38 { foreach $n (1 .. 20) { $OUT .= $n . ' ' } }
39 };
40
41 $c = new Safe;
42
43 # Build templates from string
44 $template = new Text::Template ('type' => 'STRING', 'source' => $template,
45                                SAFE => $c)
46   or die;
47 $templateOUT = new Text::Template ('type' => 'STRING', 'source' => $templateOUT,
48                                   SAFE => $c)
49   or die;
50
51 # Fill in templates
52 $text = $template->fill_in()
53   or die;
54 $textOUT = $templateOUT->fill_in()
55   or die;
56
57 # (1) They should be the same
58 print +($text eq $textOUT ? '' : 'not '), "ok $n\n";
59 $n++;
60
61 # (2-3)  "Joel Appelbaum" <joel@orbz.com> <000701c0ac2c$aed1d6e0$0201a8c0@prime>
62 # "Contrary to the documentation the $OUT variable is not always
63 # undefined at the start of each program fragment.  The $OUT variable
64 # is never undefined after it is used once if you are using the SAFE
65 # option.  The result is that every fragment after the fragment that
66 # $OUT was used in is replaced by the old $OUT value instead of the
67 # result of the fragment.  This holds true even after the
68 # Text::Template object goes out of scope and a new one is created!"
69 #
70 # Also reported by Daini Xie.
71
72 {
73   my $template = q{{$OUT = 'x'}y{$OUT .= 'z'}};
74   my $expected = "xyz";
75   my $s = Safe->new;
76   my $o = Text::Template->new(type => 'string',
77                               source => $template,
78                              );
79   for (1..2) {
80     my $r = $o->fill_in(SAFE => $s);
81     if ($r ne $expected) {
82       print "not ok $n # <$r>\n";
83     } else {
84       print "ok $n\n";
85     }
86     $n++;
87   }
88 }
89
90 exit;
91