File: parse.t

package info (click to toggle)
libconfigreader-simple-perl 1.29-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 220 kB
  • ctags: 27
  • sloc: perl: 657; makefile: 2
file content (110 lines) | stat: -rw-r--r-- 2,820 bytes parent folder | download | duplicates (7)
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
#!/usr/bin/perl
use strict;
use warnings;

use Test::More 'no_plan';
use Test::Output;

use File::Spec::Functions qw(catfile);

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
my $class  = 'ConfigReader::Simple';
my $method = 'parse';

use_ok( $class );
can_ok( $class, $method );

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Try it with a missing file, Warn off, Die off
# should return nothing, but with no warning
{
my $missing = 'a/b/c';
ok( ! -e $missing, "Missing file is actually missing" );

local $ConfigReader::Simple::Warn = 0;
local $ConfigReader::Simple::Die  = 0;

my $mock = bless {}, $class;
isa_ok( $mock, $class );
can_ok( $mock, $method );

ok( ! $mock->parse( $missing ), 
	'parse fails with missing file, $Warn and $Die off' );
}


# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Try it with a missing file, Warn off, Die on
# should return nothing, but with no warning
{
my $missing = 'a/b/c';
ok( ! -e $missing, "Missing file is actually missing" );

local $ConfigReader::Simple::Warn = 0;
local $ConfigReader::Simple::Die  = 1;

my $mock = bless {}, $class;
isa_ok( $mock, $class );
can_ok( $mock, $method );

ok( ! $mock->parse( $missing ), 
	'parse fails with missing file, $Warn and $Die off' );
}

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Try it with a missing file, Warn on, Die off
# should return nothing, but with a warning
{
my $missing = 'a/b/c';
ok( ! -e $missing, "Missing file is actually missing" );

local $ConfigReader::Simple::Warn = 1;
local $ConfigReader::Simple::Die  = 0;
local $SIG{__WARN__} = sub { print STDERR @_ };

my $mock = bless {}, $class;
isa_ok( $mock, $class );
can_ok( $mock, $method );

stderr_like
	{ $mock->parse( $missing ) }
	qr/Could not open/,
	"parse fails with missing file";
}

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Try it with a missing file, Warn on, Die on
# should return nothing, but with a warning
{
my $missing = 'a/b/c';
ok( ! -e $missing, "Missing file is actually missing" );

local $ConfigReader::Simple::Warn = 1;
local $ConfigReader::Simple::Die  = 1;
local $SIG{__WARN__} = sub { print STDERR @_ };

my $mock = bless {}, $class;
isa_ok( $mock, $class );
can_ok( $mock, $method );

stderr_like
	{ $mock->parse( $missing ) }
	qr/Could not open/,
	"parse fails with missing file";
}

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Try it with a file that ends on a continuation line that is uncontinued
# should still work
{
my $file = catfile( qw(t eof.config) );
ok( -e $file, "File exists" );

my $mock = bless {}, $class;
isa_ok( $mock, $class );
can_ok( $mock, $method );

ok( $mock->parse( $file ), 'parsing file is just fine' );
}