File: 02_env.t

package info (click to toggle)
libconfig-crontab-perl 1.42-1~bpo7%2B1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy-backports-sloppy
  • size: 384 kB
  • sloc: perl: 1,197; makefile: 4
file content (127 lines) | stat: -rw-r--r-- 3,756 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#-*- mode: cperl -*-#
use Test::More;
use blib;

chdir 't' if -d 't';
require './setup.pl';

unless( have_crontab() ) {
    plan skip_all => "no crontab available";
    exit;
}
plan tests => 53;

use_ok('Config::Crontab');

## FIXME: add some space tests (as per crontab(5))

my $env;

$env = new Config::Crontab::Env;
is( $env->dump, '', "empty env" );
undef $env;

$env = new Config::Crontab::Env( -name  => 'MAILTO',
                                 -value => 'scott@perlcode.org' );
is( $env->dump, 'MAILTO=scott@perlcode.org' );
undef $env;

$env = new Config::Crontab::Env( -value => 'scott@perlcode.org' );
is( $env->dump, '' );
is( $env->name('MAILTO'), 'MAILTO' );
is( $env->dump, 'MAILTO=scott@perlcode.org' );
undef $env;

$env = new Config::Crontab::Env( -name => 'MAILTO' );
is( $env->dump, 'MAILTO=' );
is( $env->value('joe@schmoe.org'), 'joe@schmoe.org' );
is( $env->dump, 'MAILTO=joe@schmoe.org' );
undef $env;

$env = new Config::Crontab::Env;
is( $env->dump, '' );
is( $env->name('MAILTO'), 'MAILTO' );
is( $env->dump, 'MAILTO=' );
is( $env->value('foo@bar.baz'), 'foo@bar.baz' );
is( $env->dump, 'MAILTO=foo@bar.baz');
is( $env->value(undef), '' );
is( $env->dump, 'MAILTO=' );
is( $env->value('bar@baz.blech'), 'bar@baz.blech');
is( $env->dump, 'MAILTO=bar@baz.blech');
is( $env->name(undef), '' );
is( $env->dump, '' );
undef $env;

## test some quoting issues
$env = new Config::Crontab::Env( -name   => 'MAILTO',
                                 -value  => 'joe@schmoe.org', );
is( $env->dump, 'MAILTO=joe@schmoe.org' );
is( $env->value(q!"Scott Wiersdorf" <scott@perlcode.org>!), '"Scott Wiersdorf" <scott@perlcode.org>' );
is( $env->dump, 'MAILTO="Scott Wiersdorf" <scott@perlcode.org>' );
undef $env;

## test the 'active' method/attribute
$env = new Config::Crontab::Env( -name   => 'MAILTO',
                                 -value  => 'joe@schmoe.org',
                                 -active => 0 );
is( $env->dump, '#MAILTO=joe@schmoe.org' );
ok( $env->active(1) );
is( $env->dump, 'MAILTO=joe@schmoe.org' );
undef $env;

$env = new Config::Crontab::Env;
is( $env->dump, '' );
is( $env->name('MAILTO'), 'MAILTO' );
is( $env->value('foo@bar.org'), 'foo@bar.org' );
is( $env->dump, 'MAILTO=foo@bar.org' );
is( $env->active(0), 0 );
is( $env->dump, '#MAILTO=foo@bar.org' );
is( $env->value(undef), '' );
is( $env->dump, '#MAILTO=' );
ok( $env->active(1) );
is( $env->dump, 'MAILTO=' );
undef $env;

## test the parse constructor
$env = new Config::Crontab::Env(-data => 'MAILTO=joe@schmoe.org');
is( $env->dump, 'MAILTO=joe@schmoe.org' );
ok( $env->active );
is( $env->name, 'MAILTO' );
is( $env->value, 'joe@schmoe.org' );
undef $env;

## -active is ignored because of -data
$env = new Config::Crontab::Env( -active => 0,
                                 -data   => 'MAILTO=foo@bar.com');
is( $env->dump, 'MAILTO=foo@bar.com' );
undef $env;

$env = new Config::Crontab::Env( -data => 'MAILTO=' );
is( $env->dump, 'MAILTO=' );
undef $env;

## garbage in constructor should return undef
ok( ! defined($env = new Config::Crontab::Env( -data => 'garbage' )) );
undef $env;

## newline in constructor
$env = new Config::Crontab::Env( -data => "MAILTO=foo\@bar.com\n" );
is( $env->data, 'MAILTO=foo@bar.com' );
is( $env->value, 'foo@bar.com' );
undef $env;

## newline in data
$env = new Config::Crontab::Env;
is( $env->data("MAILTO=foo\@bar.com\n"), 'MAILTO=foo@bar.com' );
is( $env->value, 'foo@bar.com' );
is( $env->dump, 'MAILTO=foo@bar.com' );
undef $env;

## use the data method
$env = new Config::Crontab::Env;
is( $env->dump, '' );
is( $env->data( 'MAILTO = joe@schmoe.org' ), 'MAILTO=joe@schmoe.org' );
is( $env->name, 'MAILTO' );
is( $env->value, 'joe@schmoe.org' );
is( $env->dump, 'MAILTO=joe@schmoe.org' );
undef $env;