File: 08-errors.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 (59 lines) | stat: -rw-r--r-- 2,112 bytes parent folder | download
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
#!/usr/bin/perl -w

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

use Text::MicroMason;
my $m = Text::MicroMason->new( );

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

{
    my $scr_mobj = "Hello <% die('Foo!') %>!";

    is eval { $m->execute( text => $scr_mobj ); 1 }, undef;
    like ($@, qr/Foo!/, "Error $@ must match Foo!");

    is eval { $m->execute( text => $scr_mobj ); 1 }, undef;
    like ($@, qr<\QMicroMason execution failed: Foo! at text template (compiled at t/08-errors.t line>, 
          "Error $@ must match MicroMason failure");

    is eval { $m->execute( file => 'samples/die.msn' ); 1 }, undef;
    like ($@, qr(\QMicroMason execution failed: Foo! at samples/die.msn line),
          "Error $@ must match MicroMason failure");
}

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

{
    my $scr_mobj = <<EOT;
Hello world!
This <% thing( %> is a test.
End.
EOT

    is eval { $m->compile( text => $scr_mobj ); 1 }, undef, "template with error dies";
    ok my @lines = split(/\n/, $@), 'multiline output in $@';
    like shift @lines, qr{MicroMason compilation failed: syntax error at text template \(compiled at t/08-errors.t line \d+\) line [89]},
        'first line of $@ describes the error location'
            or diag $@;
    like shift @lines, qr/^$/, 'second line of $@ is blank'
        or diag $@;

    like $lines[0], qr{   0  # line 1 "text template \(compiled at t/08-errors.t line }, 'third line of $@ has a #line'
        or diag $@;

    like pop @lines, qr{\s+eval \{\.\.\.\} called at t/08-errors.t line \d+}, 'last line of $@ has line number too'
        or diag $@;

    # Perl 5.6 has one line of "at line number" junk, but perl 5.8 has
    # two lines. The next line is our diagnostics message.
    ok ((pop @lines) =~ m{\Q** Please use Text::MicroMason->new(-LineNumbers) for better diagnostics!}
        or (pop @lines) =~ m{\Q** Please use Text::MicroMason->new(-LineNumbers) for better diagnostics!});

    my $n = 0;
    foreach my $line (@lines) {
        like $line, qr/^\s*$n\s+/ or diag $@;
        $n++;
    }
}