VirtualBox

source: vbox/trunk/src/libs/openssl-1.1.1l/external/perl/Text-Template-1.46/t/07-safe3.t@ 91772

Last change on this file since 91772 was 91772, checked in by vboxsync, 3 years ago

openssl-1.1.1l: Applied and adjusted our OpenSSL changes to 1.1.1l. bugref:10126

File size: 2.1 KB
Line 
1#!perl
2#
3# test apparatus for Text::Template module
4
5use Text::Template;
6
7BEGIN {
8 eval "use Safe";
9 if ($@) {
10 print "1..0\n";
11 exit 0;
12 }
13}
14
15die "This is the test program for Text::Template version 1.46.
16You are using version $Text::Template::VERSION instead.
17That does not make sense.\n
18Aborting"
19 unless $Text::Template::VERSION == 1.46;
20
21print "1..3\n";
22
23$n=1;
24
25# Test the OUT feature with safe compartments
26
27$template = q{
28This line should have a 3: {1+2}
29
30This line should have several numbers:
31{ $t = ''; foreach $n (1 .. 20) { $t .= $n . ' ' } $t }
32};
33
34$templateOUT = q{
35This line should have a 3: { $OUT = 1+2 }
36
37This 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
58print +($text eq $textOUT ? '' : 'not '), "ok $n\n";
59$n++;
60
61# (2-3) "Joel Appelbaum" <[email protected]> <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
90exit;
91
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette