VERSION

Version 0.34

applies_to

Returns true if the document contains any comparison operators that this mutator can target (>, <, >=, <=, ==, !=).

mutate

Walk a PPI document and generate one mutant for each comparison operator that can be flipped to reveal a boundary condition not caught by the test suite. For example, >= is flipped to >, <, and <= in turn, producing three independent mutants.

my $mutation = App::Test::Generator::Mutation::NumericBoundary->new;
my $doc      = PPI::Document->new(\$source);
my @mutants  = $mutation->mutate($doc);

for my $m (@mutants) {
    print $m->id, ': ', $m->description, "\n";
}

Arguments

  • $self

    An instance of App::Test::Generator::Mutation::NumericBoundary.

  • $doc

    A PPI::Document object representing the parsed source file to mutate. The document is not modified by this method.

Returns

A list of App::Test::Generator::Mutant objects, one per (operator, flip) pair found in the document. Returns an empty list if no qualifying comparison operators are found.

Each mutant carries a transform closure that when called with a fresh PPI::Document copy will replace the targeted operator with its flipped equivalent, targeting the exact operator by line and column number to ensure that multiple comparison operators on the same source line are each mutated independently.

Notes

The following operators and their flips are supported:

>   flips to  <  >=  <=
<   flips to  >  <=  >=
>=  flips to  >  <   <=
<=  flips to  <  >   >=
==  flips to  !=
!=  flips to  ==

Mutant IDs include line number, column number, and the flip target to ensure uniqueness even when multiple operators share a source line.

API specification

input

{
    self => {
        type => OBJECT,
        isa  => 'App::Test::Generator::Mutation::NumericBoundary',
    },
    doc => {
        type => OBJECT,
        isa  => 'PPI::Document',
    },
}

output

{
    type     => ARRAYREF,
    elements => {
        type => OBJECT,
        isa  => 'App::Test::Generator::Mutant',
    },
}