~ubuntu-branches/ubuntu/natty/libconfig-inifiles-perl/natty

« back to all changes in this revision

Viewing changes to t/08hook.t

  • Committer: Bazaar Package Importer
  • Author(s): Jonas Smedegaard, gregor herrmann
  • Date: 2009-01-24 22:25:26 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20090124222526-uutu8jg5r4vrfljq
Tags: 2.47-1
[ Jonas Smedegaard ]
* New upstream release. Closes: bug#430426, #380280.
* Depend on ${misc:Depends}.
* Fix Vcs-* fields to point to refer to correct package.
* Update CDBS snippets:
  + Update copyright-check output to more closely match proposed new
    copyright file format
  + Simplify internal variables
  + Ignore no files by default in copyright-check.mk
  + Correct and update copyright hints of the snippets themselves
  + Move dependency cleanup to new local snippet package-relations.mk.
* Update debian/copyright and copyright hints:
  + Rewrite debian/copyright using new file format, version 428
  + Add info on CDBS snippets (new owners, no new licenses)
* Add DEB_MAINTAINER_MODE in debian/rules (thanks to Romain Beauxis).

[ gregor herrmann ]
* debian/watch: use dist-based URL.
* debian/control: Changed: Switched Vcs-Browser field to ViewSVN
  (source stanza).

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';