Skip to content

Commit

Permalink
abs_path should not be necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Apr 6, 2015
1 parent 1f604b6 commit 49978de
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 18 deletions.
3 changes: 1 addition & 2 deletions t/mojo/bytestream.t
@@ -1,7 +1,6 @@
use Mojo::Base -strict;

use Test::More;
use Cwd 'abs_path';
use File::Basename 'dirname';
use File::Spec::Functions 'catfile';
use File::Temp 'tempdir';
Expand Down Expand Up @@ -140,7 +139,7 @@ b('te', 'st')->say($handle);
is $buffer, "test\n123\n\"123\"\n", 'right output';

# slurp
my $file = abs_path catfile(dirname(__FILE__), 'templates', 'exception.mt');
my $file = catfile dirname(__FILE__), 'templates', 'exception.mt';
$stream = b($file)->slurp;
is $stream, "test\n% die;\n123\n", 'right content';
$stream = b($file)->slurp->split("\n")->grep(qr/die/)->join;
Expand Down
27 changes: 13 additions & 14 deletions t/mojo/template.t
@@ -1,7 +1,6 @@
use Mojo::Base -strict;

use Test::More;
use Cwd 'abs_path';
use File::Basename 'dirname';
use File::Spec::Functions 'catfile';
use Mojo::Template;
Expand Down Expand Up @@ -644,21 +643,21 @@ test
EOF
isa_ok $output, 'Mojo::Exception', 'right exception';
like $output->message, qr/ohoh/, 'right message';
is $output->lines_before->[0][0], 16, 'right number';
is $output->lines_before->[0][0], 15, 'right number';
is $output->lines_before->[0][1], '}', 'right line';
is $output->lines_before->[1][0], 17, 'right number';
is $output->lines_before->[1][0], 16, 'right number';
is $output->lines_before->[1][1], '', 'right line';
is $output->lines_before->[2][0], 18, 'right number';
is $output->lines_before->[2][0], 17, 'right number';
is $output->lines_before->[2][1], 'package MyTemplateException;', 'right line';
is $output->lines_before->[3][0], 19, 'right number';
is $output->lines_before->[3][0], 18, 'right number';
is $output->lines_before->[3][1], 'use Mojo::Base -strict;', 'right line';
is $output->lines_before->[4][0], 20, 'right number';
is $output->lines_before->[4][0], 19, 'right number';
is $output->lines_before->[4][1], '', 'right line';
is $output->line->[0], 21, 'right number';
is $output->line->[0], 20, 'right number';
is $output->line->[1], "sub exception { die 'ohoh' }", 'right line';
is $output->lines_after->[0][0], 22, 'right number';
is $output->lines_after->[0][0], 21, 'right number';
is $output->lines_after->[0][1], '', 'right line';
is $output->lines_after->[1][0], 23, 'right number';
is $output->lines_after->[1][0], 22, 'right number';
is $output->lines_after->[1][1], 'package main;', 'right line';
like "$output", qr/ohoh/, 'right result';

Expand Down Expand Up @@ -1076,13 +1075,13 @@ EOF

# File
$mt = Mojo::Template->new;
my $file = abs_path catfile(dirname(__FILE__), 'templates', 'test.mt');
my $file = catfile dirname(__FILE__), 'templates', 'test.mt';
$output = $mt->render_file($file, 3);
like $output, qr/23\nHello World!/, 'file';

# Exception in file
$mt = Mojo::Template->new;
$file = abs_path catfile(dirname(__FILE__), 'templates', 'exception.mt');
$file = catfile dirname(__FILE__), 'templates', 'exception.mt';
$output = $mt->render_file($file);
isa_ok $output, 'Mojo::Exception', 'right exception';
like $output->message, qr/exception\.mt line 2/, 'message contains filename';
Expand All @@ -1109,8 +1108,8 @@ is $output->lines_after->[0][1], '123', 'right line';
like "$output", qr/foo\.mt from DATA section line 2/, 'right result';

# Exception with UTF-8 context
$mt = Mojo::Template->new;
$file = abs_path catfile(dirname(__FILE__), 'templates', 'utf8_exception.mt');
$mt = Mojo::Template->new;
$file = catfile dirname(__FILE__), 'templates', 'utf8_exception.mt';
$output = $mt->render_file($file);
isa_ok $output, 'Mojo::Exception', 'right exception';
is $output->lines_before->[0][1], '', 'right line';
Expand All @@ -1129,7 +1128,7 @@ is $output->lines_after->[0], undef, 'no lines after';

# Different encodings
$mt = Mojo::Template->new(encoding => 'shift_jis');
$file = abs_path catfile(dirname(__FILE__), 'templates', 'utf8_exception.mt');
$file = catfile dirname(__FILE__), 'templates', 'utf8_exception.mt';
ok !eval { $mt->render_file($file) }, 'file not rendered';
like $@, qr/invalid encoding/, 'right error';

Expand Down
3 changes: 1 addition & 2 deletions t/mojo/util.t
Expand Up @@ -4,7 +4,6 @@ use FindBin;
use lib "$FindBin::Bin/lib";

use Test::More;
use Cwd 'abs_path';
use File::Basename 'dirname';
use File::Spec::Functions 'catfile';
use File::Temp 'tempdir';
Expand Down Expand Up @@ -411,7 +410,7 @@ is xor_encode('hello', '123456789'), "\x59\x57\x5f\x58\x5a", 'right result';
is xor_encode("\x59\x57\x5f\x58\x5a", '123456789'), 'hello', 'right result';

# slurp
is slurp(abs_path catfile(dirname(__FILE__), 'templates', 'exception.mt')),
is slurp(catfile(dirname(__FILE__), 'templates', 'exception.mt')),
"test\n% die;\n123\n", 'right content';

# spurt
Expand Down

0 comments on commit 49978de

Please sign in to comment.