| 1 | package Module::Setup::Test::Flavor; | ||||||||||
| 2 | 2 | ▶ | use Module::Setup::Test::Utils; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 2 | ▶ | use Carp (); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 2 | ▶ | use File::Find::Rule; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 2 | ▶ | use Test::More; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | sub import { | ||||||||||
| 8 | 2 | ▶ | my $class = shift; | ||||||||
|
Subroutine
import: called CC=3 SCAR=11.0
| |||||||||||
| 9 | 2 | my $caller = caller; | |||||||||
| 10 | 2 | my %args = @_; | |||||||||
| 11 | |||||||||||
| 12 | 2 | ▶ | if ($args{for_test}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 13 | 2 | ▶ | no strict 'refs'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | 2 | ▶ | no warnings 'redefine'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 15 | 1 | ▶ | *ok = sub ($;$) { 1 }; | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 16 | 1 | ▶ | *like = sub ($$;$) { 1 }; | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 17 | 1 | ▶ | *plan = sub {}; | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 18 | } | ||||||||||
| 19 | |||||||||||
| 20 | 2 | for my $func (qw/ run_flavor_test name flavor files file dirs options default_dialog dialog /) { | |||||||||
| 21 | 2 | ▶ | no strict 'refs'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 22 | 18 | *{"$caller\::$func"} = \&{ $func }; | |||||||||
| 23 | } | ||||||||||
| 24 | |||||||||||
| 25 | 2 | strict->import; | |||||||||
| 26 | 2 | warnings->import; | |||||||||
| 27 | } | ||||||||||
| 28 | |||||||||||
| 29 | 2 | my $tests = {}; | |||||||||
| 30 | sub name ($) { | ||||||||||
| 31 | 4 | ▶ | $tests->{module} = shift; | ||||||||
|
Subroutine
name: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 32 | } | ||||||||||
| 33 | sub flavor ($) { | ||||||||||
| 34 | 1 | ▶ | $tests->{flavor_class} = shift; | ||||||||
|
Subroutine
flavor: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 35 | } | ||||||||||
| 36 | |||||||||||
| 37 | sub files (@) { | ||||||||||
| 38 | 5 | ▶ | push @{ $tests->{files} }, @_; | ||||||||
|
Subroutine
files: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 39 | } | ||||||||||
| 40 | |||||||||||
| 41 | sub file (@) { | ||||||||||
| 42 | 12 | ▶ | my $file = shift; | ||||||||
|
Subroutine
file: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 43 | 12 | push @{ $tests->{files} }, { | |||||||||
| 44 | file => $file, | ||||||||||
| 45 | likes => [ @_ ], | ||||||||||
| 46 | }; | ||||||||||
| 47 | } | ||||||||||
| 48 | |||||||||||
| 49 | sub dirs (@) { | ||||||||||
| 50 | 5 | ▶ | push @{ $tests->{dirs} }, @_; | ||||||||
|
Subroutine
dirs: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 51 | } | ||||||||||
| 52 | |||||||||||
| 53 | sub options ($) { | ||||||||||
| 54 | 1 | ▶ | $tests->{options} = shift; | ||||||||
|
Subroutine
options: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 55 | } | ||||||||||
| 56 | |||||||||||
| 57 | |||||||||||
| 58 | sub run_flavor_test (&) { | ||||||||||
| 59 | 6 | ▶ | my $code = shift; | ||||||||
|
Subroutine
run_flavor_test: called CC=11 SCAR=24.0
Pod
undocumented
| |||||||||||
| 60 | 6 | $tests = { | |||||||||
| 61 | module => 'Default', | ||||||||||
| 62 | files => [], | ||||||||||
| 63 | dirs => [], | ||||||||||
| 64 | options => {}, | ||||||||||
| 65 | flavor_class => 'Default', | ||||||||||
| 66 | }; | ||||||||||
| 67 | 6 | $code->(); | |||||||||
| 68 | 6 | my $module = delete $tests->{module}; | |||||||||
| 69 | 6 | my $options = delete $tests->{options}; | |||||||||
| 70 | 6 | $options->{target} = 1; | |||||||||
| 71 | 6 | $options->{flavor_class} = delete $tests->{flavor_class}; | |||||||||
| 72 | |||||||||||
| 73 | # test count | ||||||||||
| 74 | 6 | my $count = 2; | |||||||||
| 75 | 6 | $count += scalar(@{ $tests->{dirs} }); | |||||||||
| 76 | 6 | for my $test (@{ $tests->{files} }) { | |||||||||
| 77 | 44 | $count++; | |||||||||
| 78 | 44 | ▶ | if (ref($test) eq 'HASH') { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 79 | 12 | $count += @{ $test->{likes} }; | |||||||||
| 80 | } | ||||||||||
| 81 | } | ||||||||||
| 82 | |||||||||||
| 83 | 6 | plan tests => $count; | |||||||||
| 84 | 6 | module_setup $options, $module; | |||||||||
| 85 | |||||||||||
| 86 | 6 | my $base_path = context->distribute->dist_path; | |||||||||
| 87 | 6 | ok -d $base_path, 'base_path'; | |||||||||
| 88 | |||||||||||
| 89 | 6 | my %files = map { $_ => 1 } File::Find::Rule->new->relative->in( context->distribute->dist_path ); | |||||||||
| 90 | |||||||||||
| 91 | 6 | for my $path (@{ $tests->{dirs} }) { | |||||||||
| 92 | 12 | ▶ | Carp::croak "$path directory was missing" unless $files{$path}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 93 | 11 | my $dir = $base_path->subdir( split '/', $path ); | |||||||||
| 94 | 11 | ok -d $dir, "dir: $dir"; | |||||||||
| 95 | 11 | delete $files{$path}; | |||||||||
| 96 | } | ||||||||||
| 97 | |||||||||||
| 98 | 5 | for my $data (@{ $tests->{files} }) { | |||||||||
| 99 | 44 | my $likes = []; | |||||||||
| 100 | 44 | my $path = $data; | |||||||||
| 101 | 44 | ▶ | if (ref($data) eq 'HASH') { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 102 | 12 | $path = $data->{file}; | |||||||||
| 103 | 12 | $likes = $data->{likes}; | |||||||||
| 104 | } | ||||||||||
| 105 | 44 | ▶ | Carp::croak "$path file was missing" unless $files{$path}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 106 | 43 | my $file = $base_path->file( split '/', $path ); | |||||||||
| 107 | 43 | ok -f $file, "file: $file"; | |||||||||
| 108 | |||||||||||
| 109 | 43 | ▶ | if (@{ $likes }) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 110 | 12 | my $slurp = $file->slurp; | |||||||||
| 111 | 12 | for my $re (@{ $likes }) { | |||||||||
| 112 | 13 | like $slurp, $re, "like $re"; | |||||||||
| 113 | } | ||||||||||
| 114 | } | ||||||||||
| 115 | |||||||||||
| 116 | 43 | delete $files{$path}; | |||||||||
| 117 | } | ||||||||||
| 118 | |||||||||||
| 119 | 4 | my $is_ok = !scalar(keys %files); | |||||||||
| 120 | 4 | ok $is_ok, "is all ok"; | |||||||||
| 121 | 4 | ▶ | unless ($is_ok) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 122 | 2 | my $files = join ', ', keys %files; | |||||||||
| 123 | 2 | Carp::croak "missing tests for $files"; | |||||||||
| 124 | } | ||||||||||
| 125 | |||||||||||
| 126 | 2 | return 1; | |||||||||
| 127 | } | ||||||||||
| 128 | |||||||||||
| 129 | |||||||||||
| 130 | 2 | 1; | |||||||||
| 131 | |||||||||||
| 132 | =head1 NAME | ||||||||||
| 133 | |||||||||||
| 134 | Module::Setup::Test::Flavor - Test for flavor | ||||||||||
| 135 | |||||||||||
| 136 | =cut | ||||||||||
| 137 | |||||||||||
| 138 | |||||||||||