File: 41-line_numbers.t

package info (click to toggle)
libtext-micromason-perl 2.13-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 624 kB
  • ctags: 180
  • sloc: perl: 3,222; makefile: 23
file content (94 lines) | stat: -rw-r--r-- 3,029 bytes parent folder | download | duplicates (3)
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
#!/usr/bin/perl -w

use strict;
use Test::More tests => 37;

use_ok 'Text::MicroMason';

######################################################################

{
    ok my $m = Text::MicroMason->new( -LineNumbers );
    ok my $output = eval { $m->execute( text=>'Hello <% $_[0] %>!', 'world' ) };
    is $@, '';
    is $output, 'Hello world!';
}

######################################################################

{
    ok my $m = Text::MicroMason->new( -LineNumbers );
    ok my $output = eval { $m->interpret( text=>'1' ) };
    is $@, '';
    like $output, qr{# line 0 "text template [(]compiled at \S+line_numbers.t line \d+[)]"};
}

######################################################################

{
    ok my $m = Text::MicroMason->new( -LineNumbers );
    is eval { $m->execute( text=>'Hello <% $__[] %>!', 'world' ) }, undef;
    like $@,  qr{requires explicit package name at text template [(]compiled at \S+.t line \d+[)] line 1};
}

{
    ok my $m = Text::MicroMason->new( -LineNumbers );

    is eval { $m->execute( text=> "\n\n" . 'Hello <% $__[] %>!', 'world' ) }, undef;
    like $@, qr{requires explicit package name at text template [(]compiled at \S+.t line \d+[)] line 3};
}

######################################################################

{
    ok my $m = Text::MicroMason->new( -LineNumbers );
    ok my $output = eval { $m->execute( inline=>'Hello <% $_[0] %>!', 'world' ) };
    is $@, '';
    is $output, 'Hello world!';
}

{
    ok my $m = Text::MicroMason->new( -LineNumbers );
    ok my $output = eval { $m->interpret( inline=>'1' ) };
    is $@, '';
    like $output,  qr{# line \d+ "\S+line_numbers.t"};
}

{
    ok my $m = Text::MicroMason->new( -LineNumbers );
    is eval { $m->execute( inline => 'Hello <% $__[] %>!', 'world' ) }, undef; my $line = __LINE__;
    like $@, qr{requires explicit package name at \S+.t line \Q$line\E};
}

######################################################################

{
    ok my $m = Text::MicroMason->new( -LineNumbers );
    ok my $output = eval { $m->execute( file=>'samples/test.msn', name=>'Sam', hour=>14 ) };
    is $@, '';
    like $output, qr/\QGood afternoon, Sam!\E/;
}

{
    ok my $m = Text::MicroMason->new( -LineNumbers );
    is eval { $m->execute( file=>'samples/die.msn' ) }, undef;
    is $@, "MicroMason execution failed: Foo! at samples/die.msn line 1.\n";
}

######################################################################

SKIP: {
    skip "Test::Warn is not installed", 4
        unless eval { require Test::Warn; };
    use warnings;

    ok my $m = Text::MicroMason->new( -LineNumbers );
    Test::Warn::warnings_like(sub {
        ok my $output = eval { $m->execute( file => 'samples/uninitialized.msn' ) };
        is $@, '';
    }, [
        qr/^Use of uninitialized value.*at samples\/uninitialized\.msn line 1/,
        qr/^Use of uninitialized value.*at samples\/uninitialized\.msn line 8/,
    ]);
}