Debian Codegraph @

t/engine.t

raw
1 use strict;
2 use warnings;
3 use Test::More;
4 use Test::Fatal;
5 use Dancer2::Core::App;
6 use Dancer2::Template::Tiny;
7
8 {
9 my $f = Dancer2::Template::Tiny->new();
10 isa_ok( $f, 'Dancer2::Template::Tiny' );
11 ok(
12 $f->does('Dancer2::Core::Role::Engine'),
13 'Consumed Role::Engine',
14 );
15
16 ok(
17 $f->does('Dancer2::Core::Role::Template'),
18 'Consumed Role::Template',
19 );
20
21 is( $f->name, 'Tiny', 'Correct engine name' );
22 }
23
24 # checks for validity of engine names
25
26 my $app = Dancer2::Core::App->new();
27 isa_ok( $app, 'Dancer2::Core::App' );
28
29 {
30 no warnings qw<redefine once>;
31 *Dancer2::Core::Factory::create = sub { $_[1] };
32 }
33
34 foreach my $engine_type ( qw<logger session template> ) {
35 note($engine_type);
36 my $engine;
37 my $build_method = "_build_${engine_type}_engine";
38
39 is(
40 exception {
41 $engine = $app->$build_method(
42 undef, { $engine_type => 'Fake43Thing' }
43 );
44 },
45 undef,
46 "Built $engine_type successfully with proper name",
47 );
48
49 like(
50 exception {
51 $engine = $app->$build_method(
52 undef, { $engine_type => '7&&afail' }
53 );
54 },
55 qr/^Cannot load $engine_type engine '7&&afail': illegal module name/,
56 "Failed creating $engine_type with illegal name",
57 );
58
59 is( $engine, $engine_type, 'Correct response from override' );
60 }
61
62 done_testing;