VirtualBox

source: vbox/trunk/src/libs/openssl-1.1.1l/external/perl/Text-Template-1.46/t/05-safe2.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.7 KB
Line 
1#!perl
2#
3# test apparatus for Text::Template module
4# still incomplete.
5
6use Text::Template;
7
8BEGIN {
9 eval "use Safe";
10 if ($@) {
11 print "1..0\n";
12 exit 0;
13 }
14}
15
16die "This is the test program for Text::Template version 1.46.
17You are using version $Text::Template::VERSION instead.
18That does not make sense.\n
19Aborting"
20 unless $Text::Template::VERSION == 1.46;
21
22print "1..12\n";
23$n = 1;
24
25$c = new Safe or die;
26
27# Test handling of packages and importing.
28$c->reval('$P = "safe root"');
29$P = $P = 'main';
30$Q::P = $Q::P = 'Q';
31
32# How to effectively test the gensymming?
33
34$t = new Text::Template TYPE => 'STRING', SOURCE => 'package is {$P}'
35 or die;
36
37# (1) Default behavior: Inherit from calling package, `main' in this case.
38$text = $t->fill_in();
39print +($text eq 'package is main' ? '' : 'not '), "ok $n\n";
40$n++;
41
42# (2) When a package is specified, we should use that package instead.
43$text = $t->fill_in(PACKAGE => 'Q');
44print +($text eq 'package is Q' ? '' : 'not '), "ok $n\n";
45$n++;
46
47# (3) When no package is specified in safe mode, we should use the
48# default safe root.
49$text = $t->fill_in(SAFE => $c);
50print +($text eq 'package is safe root' ? '' : 'not '), "ok $n\n";
51$n++;
52
53# (4) When a package is specified in safe mode, we should use the
54# default safe root, after aliasing to the specified package
55$text = $t->fill_in(SAFE => $c, PACKAGE => Q);
56print +($text eq 'package is Q' ? '' : 'not '), "ok $n\n";
57$n++;
58
59# Now let's see if hash vars are installed properly into safe templates
60$t = new Text::Template TYPE => 'STRING', SOURCE => 'hash is {$H}'
61 or die;
62
63# (5) First in default mode
64$text = $t->fill_in(HASH => {H => 'good5'} );
65print +($text eq 'hash is good5' ? '' : 'not '), "ok $n\n";
66$n++;
67
68# (6) Now in packages
69$text = $t->fill_in(HASH => {H => 'good6'}, PACKAGE => 'Q' );
70print +($text eq 'hash is good6' ? '' : 'not '), "ok $n\n";
71$n++;
72
73# (7) Now in the default root of the safe compartment
74$text = $t->fill_in(HASH => {H => 'good7'}, SAFE => $c );
75print +($text eq 'hash is good7' ? '' : 'not '), "ok $n\n";
76$n++;
77
78# (8) Now in the default root after aliasing to a package that
79# got the hash stuffed in
80$text = $t->fill_in(HASH => {H => 'good8'}, SAFE => $c, PACKAGE => 'Q2' );
81print +($text eq 'hash is good8' ? '' : 'not '), "ok $n\n";
82$n++;
83
84# Now let's make sure that none of the packages leaked on each other.
85# (9) This var should NOT have been installed into the main package
86print +(defined $H ? 'not ' : ''), "ok $n\n";
87$H=$H;
88$n++;
89
90# (10) good6 was overwritten in test 7, so there's nothing to test for here.
91print "ok $n\n";
92$n++;
93
94# (11) this value overwrote the one from test 6.
95print +($Q::H eq 'good7' ? '' : 'not '), "ok $n\n";
96$Q::H = $Q::H;
97$n++;
98
99# (12)
100print +($Q2::H eq 'good8' ? '' : 'not '), "ok $n\n";
101$Q2::H = $Q2::H;
102$n++;
103
104
105
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