| 1 | 2 | ▶ | use 5.10.0; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 2 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | |||||||||||
| 5 | package Stenciller::Plugin::ToMojoliciousTest; | ||||||||||
| 6 | |||||||||||
| 7 | 2 | our $VERSION = '0.0103'; | |||||||||
| 8 | # ABSTRACT: Create Mojolicious tests from text files parsed with Stenciller | ||||||||||
| 9 | 2 | our $AUTHORITY = 'cpan:CSSON'; # AUTHORITY | |||||||||
| 10 | |||||||||||
| 11 | 2 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | 2 | ▶ | use Types::Path::Tiny qw/Path/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | 2 | with 'Stenciller::Transformer'; | |||||||||
| 14 | |||||||||||
| 15 | 2 | has template => ( | |||||||||
| 16 | is => 'ro', | ||||||||||
| 17 | isa => Path, | ||||||||||
| 18 | required => 1, | ||||||||||
| 19 | coerce => 1, | ||||||||||
| 20 | ); | ||||||||||
| 21 | |||||||||||
| 22 | 1 | ▶ | sub transform { | ||||||||
|
Subroutine
transform: called CC=6 SCAR=17.9
Pod
undocumented
| |||||||||||
| 23 | 1 | my $self = shift; | |||||||||
| 24 | 1 | my $transform_args = shift; | |||||||||
| 25 | |||||||||||
| 26 | 1 | my @out = $self->init_out($self->stenciller, $transform_args); | |||||||||
| 27 | |||||||||||
| 28 | 1 | my @stencils = (); | |||||||||
| 29 | |||||||||||
| 30 | STENCIL: | ||||||||||
| 31 | 1 | for my $i (0 .. $self->stenciller->max_stencil_index) { | |||||||||
| 32 | |||||||||||
| 33 | 1 | ▶ | next STENCIL if $self->should_skip_stencil_by_index($i, $transform_args); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 34 | |||||||||||
| 35 | 1 | my $stencil = $self->stenciller->get_stencil($i); | |||||||||
| 36 | 1 | ▶ | next STENCIL if $self->should_skip_stencil($stencil, $transform_args); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 37 | |||||||||||
| 38 | 1 | push @stencils => $stencil; | |||||||||
| 39 | } | ||||||||||
| 40 | |||||||||||
| 41 | 1 | foreach my $stencil (@stencils) { | |||||||||
| 42 | |||||||||||
| 43 | 1 | my $expected_var = sprintf '$expected_%s', $stencil->stencil_name; | |||||||||
| 44 | |||||||||||
| 45 | 1 | push @out => sprintf "# test from line %s in %s", $stencil->line_number, $self->stenciller->filepath->basename; | |||||||||
| 46 | |||||||||||
| 47 | #warn "-------\n" . $stencil->all_output . "\n-----------<<"; | ||||||||||
| 48 | 1 | push @out => sprintf 'my %s = qq{%s};', $expected_var, join ("\n" => $stencil->all_output); | |||||||||
| 49 | |||||||||||
| 50 | 1 | push @out => sprintf q{get '/%s' => '%s';}, $stencil->stencil_name, $stencil->stencil_name; | |||||||||
| 51 | |||||||||||
| 52 | 1 | my $test_comment = sprintf q{Matched trimmed content in %s, line %s} => $self->stenciller->filepath->basename, $stencil->line_number; | |||||||||
| 53 | 1 | push @out => sprintf q{$test->get_ok('/%s')->status_is(200)->trimmed_content_is(%s, '%s');} => $stencil->stencil_name, $expected_var, $test_comment; | |||||||||
| 54 | |||||||||||
| 55 | } | ||||||||||
| 56 | |||||||||||
| 57 | 1 | push @out => 'done_testing();'; | |||||||||
| 58 | 1 | push @out => '__DATA__'; | |||||||||
| 59 | |||||||||||
| 60 | 1 | foreach my $stencil (@stencils) { | |||||||||
| 61 | 1 | push @out => sprintf '@@ %s.html.ep' => $stencil->stencil_name; | |||||||||
| 62 | 1 | push @out => $stencil->all_input; | |||||||||
| 63 | } | ||||||||||
| 64 | |||||||||||
| 65 | 1 | my $content = join "\n\n" => '', @out, ''; | |||||||||
| 66 | 1 | $content =~s{\v{2,}}{\n\n}g; | |||||||||
| 67 | |||||||||||
| 68 | 1 | my $template = $self->template->slurp_utf8; | |||||||||
| 69 | 1 | return $template.$content; | |||||||||
| 70 | } | ||||||||||
| 71 | |||||||||||
| 72 | 2 | 1; | |||||||||
| 73 | |||||||||||
| 74 | __END__ | ||||||||||