Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 127 lines (113 sloc) 3.035 kb
eb63f99 Andy Wardley new test for file/line warnings
authored
1 #============================================================= -*-perl-*-
2 #
3 # t/fileline.t
4 #
5 # Test the reporting of template file and line number in errors.
6 #
7 # Written by Andy Wardley <abw@wardley.org>
8 #
b51a05e Andy Wardley Re-applied skip_all() to t/fileline.t when running under MSWin32
authored
9 # Copyright (C) 1996-2007 Andy Wardley. All Rights Reserved.
eb63f99 Andy Wardley new test for file/line warnings
authored
10 #
11 # This is free software; you can redistribute it and/or modify it
12 # under the same terms as Perl itself.
13 #
14 #========================================================================
15
865d262 Andy Wardley applied fix to fileline.t to switch slashes on Win32
authored
16 #BEGIN {
17 # if ( $^O eq 'MSWin32' ) {
18 # print "1..0 # Skip Temporarily skipping on Win32\n";
19 # exit(0);
20 # }
21 #}
b51a05e Andy Wardley Re-applied skip_all() to t/fileline.t when running under MSWin32
authored
22
eb63f99 Andy Wardley new test for file/line warnings
authored
23 use strict;
b51a05e Andy Wardley Re-applied skip_all() to t/fileline.t when running under MSWin32
authored
24 use warnings;
06c33bc Andy Wardley Rebuild in preparation for 2.15b
authored
25 use lib qw( ./lib ../lib ./blib/lib ../blib/lib ./blib/arch ../blib/arch );
eb63f99 Andy Wardley new test for file/line warnings
authored
26 use Template::Test;
27 use Template::Parser;
28 use Template::Directive;
29
30 #$Template::Parser::DEBUG = 1;
31 #$Template::Directive::PRETTY = 1;
32
33 my $dir = -d 't' ? 't/test/lib' : 'test/lib';
34
35 my $warning;
36 local $SIG{__WARN__} = sub {
37 $warning = shift;
38 };
39
40 my $vars = {
41 warning => sub { return $warning },
42 file => sub {
43 $warning =~ /at (.*?) line/;
ce54fd8 Andy Wardley Removed the line number from warnings reported at (eval $line).
authored
44 my $file = $1;
91f2ad2 Andy Wardley * updated comment wrt fileline eval bug - thanks to Andreas
authored
45 # The error returned includes a reference to the eval string
46 # e.g. ' ...at (eval 1) line 1'. On some platforms (notably
47 # FreeBSD and variants like OSX), the (eval $n) part contains
48 # a different number, presumably because it has previously
49 # performed additional string evals. It's not important to
50 # the success or failure of the test, so we delete it.
51 # Thanks to Andreas Koenig for identifying the problem.
52 # http://rt.cpan.org/Public/Bug/Display.html?id=20807
ce54fd8 Andy Wardley Removed the line number from warnings reported at (eval $line).
authored
53 $file =~ s/eval\s+\d+/eval/;
865d262 Andy Wardley applied fix to fileline.t to switch slashes on Win32
authored
54
55 # handle backslashes on Win32 by converting them to forward slashes
56 $file =~ s!\\!/!g if $^O eq 'MSWin32';
ce54fd8 Andy Wardley Removed the line number from warnings reported at (eval $line).
authored
57 return $file;
eb63f99 Andy Wardley new test for file/line warnings
authored
58 },
59 line => sub {
60 $warning =~ /line (\d*)/;
61 return $1;
62 },
63 warn => sub {
64 $warning =~ /(.*?) at /;
65 return $1;
66 },
67 };
68
06c33bc Andy Wardley Rebuild in preparation for 2.15b
authored
69 my $tt2err = Template->new({ INCLUDE_PATH => $dir })
70 || die Template->error();
71 my $tt2not = Template->new({ INCLUDE_PATH => $dir, FILE_INFO => 0 })
72 || die Template->error();
eb63f99 Andy Wardley new test for file/line warnings
authored
73
960da0d Andy Wardley * added test for the FILE_INFO configuration option
authored
74 test_expect(\*DATA, [ err => $tt2err, not => $tt2not ], $vars);
eb63f99 Andy Wardley new test for file/line warnings
authored
75
76 __DATA__
77 -- test --
78 [% place = 'World' -%]
79 Hello [% place %]
80 [% a = a + 1 -%]
81 file: [% file %]
82 line: [% line %]
83 warn: [% warn %]
84 -- expect --
85 -- process --
86 Hello World
87 file: input text
88 line: 3
89 warn: Argument "" isn't numeric in addition (+)
90
91 -- test --
92 [% INCLUDE warning -%]
70dccef Andy Wardley * fixed file path
authored
93 file: [% file.chunk(-16).last %]
eb63f99 Andy Wardley new test for file/line warnings
authored
94 line: [% line %]
95 warn: [% warn %]
96 -- expect --
97 -- process --
98 Hello
99 World
100 file: test/lib/warning
101 line: 2
102 warn: Argument "" isn't numeric in addition (+)
960da0d Andy Wardley * added test for the FILE_INFO configuration option
authored
103
104 -- test --
105 -- use not --
106 [% INCLUDE warning -%]
107 file: [% file.chunk(-16).last %]
108 line: [% line %]
109 warn: [% warn %]
110 -- expect --
111 Hello
112 World
ce54fd8 Andy Wardley Removed the line number from warnings reported at (eval $line).
authored
113 file: (eval)
960da0d Andy Wardley * added test for the FILE_INFO configuration option
authored
114 line: 10
115 warn: Argument "" isn't numeric in addition (+)
3db0de7 Andy Wardley * added test for pre-chomp bug
authored
116
117 -- test --
118 [% TRY;
119 INCLUDE chomp;
120 CATCH;
121 error;
122 END
123 %]
124 -- expect --
125 file error - parse error - chomp line 6: unexpected token (END)
126 [% END %]
Something went wrong with that request. Please try again.