Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
test verbose output as well
  • Loading branch information
kraih committed Feb 26, 2016
1 parent 1becada commit 3f6f1ec
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions lib/Mojo/Exception.pm
Expand Up @@ -40,6 +40,7 @@ sub to_string {
my $str = $self->message;
return $str unless $self->verbose;

$str .= "\n" unless $str =~ /\n$/;
$str .= $_->[0] . ': ' . $_->[1] . "\n" for @{$self->lines_before};
$str .= $self->line->[0] . ': ' . $self->line->[1] . "\n" if $self->line->[0];
$str .= $_->[0] . ': ' . $_->[1] . "\n" for @{$self->lines_after};
Expand Down
3 changes: 1 addition & 2 deletions lib/Mojolicious/Renderer.pm
Expand Up @@ -136,8 +136,7 @@ sub render {
while ((my $next = _next($stash)) && !defined $inline) {
@$options{qw(handler template)} = ($stash->{handler}, $next);
$options->{format} = $stash->{format} || $self->default_format;
my $layout;
$output = $layout if $self->_render_template($c, \$layout, $options);
if ($self->_render_template($c, \my $tmp, $options)) { $output = $tmp }
$content->{content} = $output
if $content->{content} !~ /\S/ && $output =~ /\S/;
}
Expand Down
10 changes: 10 additions & 0 deletions t/mojo/exception.t
Expand Up @@ -72,4 +72,14 @@ is_deeply $e->lines_before->[-1], [3, 'use Test::More;'], 'right line';
is_deeply $e->line, [4, 'use Mojo::Exception;'], 'right line';
is_deeply $e->lines_after->[0], [5, ''], 'right line';

# Verbose
$e = Mojo::Exception->new('Test!')->lines_before([[3, 'foo();']])
->line([4, 'die;'])->lines_after([[5, 'bar();']])->verbose(1);
is $e, <<EOF, 'right result';
Test!
3: foo();
4: die;
5: bar();
EOF

done_testing();

0 comments on commit 3f6f1ec

Please sign in to comment.