~ubuntu-branches/ubuntu/jaunty/horae/jaunty

« back to all changes in this revision

Viewing changes to 0CPAN/Config-IniFiles-2.39/t/08hook.t

  • Committer: Bazaar Package Importer
  • Author(s): Carlo Segre
  • Date: 2008-02-23 23:13:02 UTC
  • mfrom: (2.1.2 hardy)
  • Revision ID: james.westby@ubuntu.com-20080223231302-mnyyxs3icvrus4ke
Tags: 066-3
Apply patch to athena_parts/misc.pl for compatibility with 
perl-tk 804.28.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#
2
 
# Testcases for using perl hooks in Ini configuration files
3
 
# GCARLS 04/29/2005
4
 
#
5
 
 
6
 
use strict;
7
 
use Test;
8
 
 
9
 
BEGIN { $| = 1; plan tests => 13 }
10
 
use Config::IniFiles;
11
 
my $loaded = 1;
12
 
#Test 1
13
 
ok($loaded);
14
 
 
15
 
my $ini;
16
 
 
17
 
# Get files from the 't' directory, portably
18
 
chdir('t') if ( -d 't' );
19
 
 
20
 
# Test 2
21
 
# Create ini object with allowcode Option set to 1
22
 
$ini = new Config::IniFiles(-file => 'hook.ini', 
23
 
                            -allowcode => 1);
24
 
ok($ini->{allowcode});
25
 
 
26
 
#Test 3
27
 
# check standard parameter access
28
 
ok($ini->val('hooksection', 'testval') eq 'ok');
29
 
 
30
 
#Test 4
31
 
#check perl hook - accessing environment variables from a hooks sub
32
 
$ENV{'HOOK'}='PERLHOOK';
33
 
ok($ini->val('hooksection', 'envhook') eq 'PERLHOOK');
34
 
 
35
 
#Test 5
36
 
# check if a global sub can be called from a hook
37
 
 
38
 
sub gethook {
39
 
  my($arg)=@_;
40
 
  return("HOOK($arg)");
41
 
}
42
 
ok($ini->val('hooksection', 'hooksub') eq 'HOOK(4711)');
43
 
 
44
 
#Test 6
45
 
#check if single elements of an array are evaluated
46
 
my(@hookary);
47
 
@hookary=$ini->val('hooksection', 'hookary');
48
 
ok($#hookary==3);
49
 
 
50
 
#Test 7
51
 
ok($hookary[0] eq 'hook1');
52
 
 
53
 
#Test 8
54
 
ok($hookary[1] eq 'PERLHOOK');
55
 
 
56
 
#Test 9
57
 
ok($hookary[2] eq 'HOOK(4711)');
58
 
 
59
 
#Test 10
60
 
ok($hookary[3] eq 'hook4');
61
 
 
62
 
#Test 11
63
 
# Rewrite File
64
 
$ini->WriteConfig('hook_2.ini');
65
 
 
66
 
$ENV{'HOOK'}='PERLHOOK_2';
67
 
# check if perl hook still exist in the written file
68
 
$ini = new Config::IniFiles(-file => 'hook_2.ini', 
69
 
                            -allowcode => 1);
70
 
ok($ini->val('hooksection', 'envhook') eq 'PERLHOOK_2');
71
 
 
72
 
#Test 12
73
 
# check if perl hook in here document still exists
74
 
@hookary=$ini->val('hooksection', 'hookary');
75
 
ok($hookary[1] eq 'PERLHOOK_2');
76
 
 
77
 
 
78
 
#Test 13
79
 
# check if -allowcode => 0 prohibits perl code in ini files
80
 
$ini = new Config::IniFiles(-file => 'hook.ini', 
81
 
                            -allowcode => 0);
82
 
 
83
 
eval{
84
 
  $ini->val('hooksection', 'hooksub');
85
 
  ok(0);
86
 
} or ok(1);
87
 
 
88
 
unlink 'hook_2.ini';