« lib/App/Test/Generator/Mutation/BooleanNegation.pm
↑ Summary
lib/App/Test/Generator/Sample/Module.pm »
| 1 | package App::Test::Generator::Planner::Fixture; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 19 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 19 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 19 | ▶ | use Carp qw(croak); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 19 | ▶ | use Readonly; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | # -------------------------------------------------- | ||||||||||||||||||||||||||||
| 9 | # Isolation mode that triggers shared fixture reuse | ||||||||||||||||||||||||||||
| 10 | # -------------------------------------------------- | ||||||||||||||||||||||||||||
| 11 | 19 | Readonly my $MODE_SHARED_FIXTURE => 'shared_fixture'; | |||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | # -------------------------------------------------- | ||||||||||||||||||||||||||||
| 14 | # Fixture mode labels written to the plan output | ||||||||||||||||||||||||||||
| 15 | # -------------------------------------------------- | ||||||||||||||||||||||||||||
| 16 | 19 | Readonly my $FIXTURE_SHARED => 'shared'; | |||||||||||||||||||||||||||
| 17 | 19 | Readonly my $FIXTURE_NEW_PER_TEST => 'new_per_test'; | |||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 19 | our $VERSION = '0.50'; | |||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | =head1 VERSION | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | Version 0.50 | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | Plans fixture setup strategy for each method under test, based on the | ||||||||||||||||||||||||||||
| 28 | isolation requirements provided by | ||||||||||||||||||||||||||||
| 29 | L<App::Test::Generator::Planner::Isolation>. Methods that share state | ||||||||||||||||||||||||||||
| 30 | are assigned a shared fixture; all others get a fresh fixture per test. | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | =head2 new | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | Construct a new Fixture planner. | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | my $planner = App::Test::Generator::Planner::Fixture->new; | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | =head3 Arguments | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | None. | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | =head3 Returns | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | A blessed hashref. | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | =head3 API specification | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | =head4 input | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | {} | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | =head4 output | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | { | ||||||||||||||||||||||||||||
| 55 | type => OBJECT, | ||||||||||||||||||||||||||||
| 56 | isa => 'App::Test::Generator::Planner::Fixture', | ||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | =cut | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 34 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 62 | 34 | my $class = $_[0]; | |||||||||||||||||||||||||||
| 63 | 34 | return bless {}, $class; | |||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | =head2 plan | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | Produce a fixture plan for each method based on its isolation mode. | ||||||||||||||||||||||||||||
| 69 | Methods with isolation mode C<shared_fixture> are assigned a shared | ||||||||||||||||||||||||||||
| 70 | fixture; all other methods get a fresh fixture per test. | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | my $planner = App::Test::Generator::Planner::Fixture->new; | ||||||||||||||||||||||||||||
| 73 | my $fixture = $planner->plan($schema, $isolation); | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | for my $method (keys %{$fixture}) { | ||||||||||||||||||||||||||||
| 76 | printf "%s: %s\n", $method, $fixture->{$method}{mode}; | ||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | =head3 Arguments | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | =over 4 | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | =item * C<$schema> | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | A hashref representing the module schema. Currently unused but | ||||||||||||||||||||||||||||
| 86 | reserved for future fixture customisation based on schema metadata. | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | =item * C<$isolation> | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | A hashref mapping method names to isolation plan hashrefs, each with | ||||||||||||||||||||||||||||
| 91 | a C<fixture> key, as produced by | ||||||||||||||||||||||||||||
| 92 | L<App::Test::Generator::Planner::Isolation>. | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | =back | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | =head3 Returns | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | A hashref mapping method names to fixture plan hashrefs, each with a | ||||||||||||||||||||||||||||
| 99 | C<mode> key set to either C<shared> or C<new_per_test>. | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | =head3 API specification | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | =head4 input | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | { | ||||||||||||||||||||||||||||
| 106 | self => { type => OBJECT, isa => 'App::Test::Generator::Planner::Fixture' }, | ||||||||||||||||||||||||||||
| 107 | schema => { type => HASHREF, optional => 1 }, | ||||||||||||||||||||||||||||
| 108 | isolation => { type => HASHREF, optional => 0 }, | ||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | =head4 output | ||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | { | ||||||||||||||||||||||||||||
| 114 | type => HASHREF, | ||||||||||||||||||||||||||||
| 115 | keys => { | ||||||||||||||||||||||||||||
| 116 | '*' => { | ||||||||||||||||||||||||||||
| 117 | type => HASHREF, | ||||||||||||||||||||||||||||
| 118 | keys => { mode => { type => SCALAR } }, | ||||||||||||||||||||||||||||
| 119 | }, | ||||||||||||||||||||||||||||
| 120 | }, | ||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | =cut | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | 59 | ▶ | sub plan { | ||||||||||||||||||||||||||
|
Subroutine
plan: called CC=8 SCAR=20.8
Pod
documented
| |||||||||||||||||||||||||||||
| 126 | 59 | my ($self, $schema, $isolation) = @_; | |||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | 59 | ▶ | croak 'schema must be a hashref' if defined($schema) && ref($schema) ne 'HASH'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $schema and ref $schema ne "HASH"
MC/DC0%0/2
defined $schema and ref $schema ne "HASH"
defined $schema
ref $schema ne "HASH"
Truth table66%2/3
A and B
A= defined $schemaB= ref $schema ne "HASH"
| |||||||||||||||||||||||||||||
| 129 | 59 | ▶ | croak 'isolation must be a hashref' unless ref($isolation) eq 'HASH'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | 52 | my %fixture; | |||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | # -------------------------------------------------- | ||||||||||||||||||||||||||||
| 134 | # Assign fixture mode per method based on isolation. | ||||||||||||||||||||||||||||
| 135 | # Shared fixture mode reuses one object across tests | ||||||||||||||||||||||||||||
| 136 | # for methods that share state; all others get a | ||||||||||||||||||||||||||||
| 137 | # fresh object constructed per test case. | ||||||||||||||||||||||||||||
| 138 | # -------------------------------------------------- | ||||||||||||||||||||||||||||
| 139 | 52 | for my $method (keys %{$isolation}) { | |||||||||||||||||||||||||||
| 140 | 48 | ▶ | next unless ref($isolation->{$method}) eq 'HASH'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 141 | 28 | ▶ | my $mode = ($isolation->{$method}{fixture} // '') eq $MODE_SHARED_FIXTURE | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$isolation->{$method}{"fixture"} // ""
MC/DC100%1/1
$isolation->{$method}{"fixture"} // ""
$isolation->{$method}{"fixture"}
Truth table100%2/2
A
A= $isolation->{$method}{"fixture"}
| |||||||||||||||||||||||||||||
| 142 | ? $FIXTURE_SHARED | ||||||||||||||||||||||||||||
| 143 | : $FIXTURE_NEW_PER_TEST; | ||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | 28 | $fixture{$method} = { mode => $mode }; | |||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | 52 | return \%fixture; | |||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | 19 | 1; | |||||||||||||||||||||||||||