File: 01-bad-args.t

package info (click to toggle)
libhtml-template-perl 2.97-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 740 kB
  • sloc: perl: 2,572; makefile: 8
file content (93 lines) | stat: -rw-r--r-- 3,662 bytes parent folder | download | duplicates (6)
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
use strict;
use Test::More qw(no_plan);
# tests => 6;
use_ok('HTML::Template');

my $tmpl;
eval { $tmpl = HTML::Template->new() };
like($@, qr/\QHTML::Template->new called with multiple (or no) template sources specified!/, 'new() with no args dies');

eval { $tmpl = HTML::Template->new('file') };
like($@, qr/\QHTML::Template->new() called with odd number of option parameters/, 'new() with odd number of args dies');

eval { $tmpl = HTML::Template->new(type => 'filename') };
like($@, qr/\Qcalled with 'type' parameter set, but no 'source'!/, "new(type => 'filename') dies without source");

eval { $tmpl = HTML::Template->new(type => 'frobnitz', source => '../templates/simple.tmpl') };
like($@, qr/\Qtype parameter must be set to 'filename', 'arrayref', 'scalarref' or 'filehandle'!/,
    'new() dies with invalid type');

eval { $tmpl = HTML::Template->new(filename => 'simple.tmpl', path => 'templates', associate => 'Class::With::No::Param'); };
like(
    $@,
    qr/called with associate option, containing object of type.*\Qwhich lacks a param() method!/,
    'associate() object with no param() method'
);

eval { $tmpl = HTML::Template->new(filename => 'simple.tmpl', path => 'templates', 'debug') };
like(
    $@,
    qr/\Qcalled with odd number of option parameters - should be of the form option => value/,
    'new() called with option with no value'
);

=head1 NAME

t/01-bad-args.t

=head1 OBJECTIVE

Test whether constructor fails with appropriate messages if passed bad
or missing arguments.

=cut

__END__
# Below this point are tests which ...
use Test::Exception;

# Applying Test::Exception to this case;
# Note idiosyncratic syntax:
# no parens surrounding block and test description; white space is optional
# block holding method to be tested;
# no comma between block and test description
# test description
dies_ok {$tmpl = HTML::Template->new()} 'new() with no args dies' ;
dies_ok {HTML::Template->new()} 'new() with no args dies';
dies_ok{$tmpl = HTML::Template->new()} 'new() with no args dies' ;
dies_ok{HTML::Template->new()} 'new() with no args dies';

# Customary Test::More syntax; parens around arguments to ok() are optional. 
ok(1, 'return a true value');
ok 1, 'return a true value';

throws_ok { $tmpl = HTML::Template->new('file') }
        qr/\QHTML::Template->new() called with odd number of option parameters/,
        'new() with odd number of args dies';

throws_ok {$tmpl = HTML::Template->new(type => 'filename') }
        qr/\Qcalled with 'type' parameter set, but no 'source'!/,
        "new(type => 'filename') dies without source";

throws_ok { $tmpl = HTML::Template->new(
                                 type => 'frobnitz',
                                 source => '../templates/simple.tmpl'
                                 ) }
        qr/\Qtype parameter must be set to 'filename', 'arrayref', 'scalarref' or 'filehandle'!/,
        'new() dies with invalid type';

throws_ok {$tmpl = HTML::Template->new(filename => 'simple.tmpl',
                                 path => 'templates',
                                 associate => 'Class::With::No::Param'
                                 ) }
qr/called with associate option, containing object of type.*\Qwhich lacks a param() method!/,
'associate() object with no param() method';

throws_ok {$tmpl = HTML::Template->new(
                                 filename => 'simple.tmpl',
                                 path => 'templates',
                                 'debug'
                                 ) }
qr/\Qcalled with odd number of option parameters - should be of the form option => value/,
'new() called with option with no value';