NAME

Test::Auto::Subtests

ABSTRACT

Testing Automation

SYNOPSIS

package main;

use Test::Auto;
use Test::Auto::Parser;
use Test::Auto::Subtests;

my $test = Test::Auto->new(
  't/Test_Auto_Subtests.t'
);

my $parser = Test::Auto::Parser->new(
  source => $test
);

my $subtests = Test::Auto::Subtests->new(
  parser => $parser
);

# execute dynamic subtests

# $subtests->standard

DESCRIPTION

This package use the Test::Auto::Parser object to execute a set of dynamic subtests.

LIBRARIES

This package uses type constraints from:

Data::Object::Library

ATTRIBUTES

This package has the following attributes:

parser

parser(InstanceOf["Test::Auto::Parser"])

This attribute is read-only, accepts (InstanceOf["Test::Auto::Parser"]) values, and is required.

METHODS

This package implements the following methods:

attributes

attributes() : Any

This method registers and executes a subtest which tests the declared attributes.

attributes example #1
# given: synopsis

$subtests->attributes;

document

document() : Any

This method registers and executes a subtest which tests the test document structure.

document example #1
# given: synopsis

$subtests->document;

evaluator

evaluator(Str $context) : Any

This method evaluates (using eval) the context given and returns the result or raises an exception.

evaluator example #1
# given: synopsis

my $context = '1 + 1';

$subtests->evaluator($context); # 2

example

example(Num $number, Str $name, Str $type, CodeRef $callback) : Any

This method finds and evaluates (using eval) the documented example and returns a Data::Object::Try object. The try object can be used to trap exceptions using the catch method, and/or execute the code and return the result using the result method.

example example #1
# given: synopsis

$subtests->example(1, 'evaluator', 'method', sub {
  my ($tryable) = @_;

  ok my $result = $tryable->result, 'result ok';
  is $result, 2, 'meta evaluator test ok';

  $result;
});

functions

functions() : Any

This method registers and executes a subtest which tests the declared functions.

functions example #1
# given: synopsis

$subtests->functions;

inherits

inherits() : Any

This method registers and executes a subtest which tests the declared inheritances.

inherits example #1
# given: synopsis

$subtests->inherits;

libraries

libraries() : Any

This method registers and executes a subtest which tests the declared type libraries.

libraries example #1
# given: synopsis

$subtests->libraries;

methods

methods() : Any

This method registers and executes a subtest which tests the declared methods.

methods example #1
# given: synopsis

$subtests->methods;

package

package() : Any

This method registers and executes a subtest which tests the declared package.

package example #1
# given: synopsis

$subtests->package;

registry

registry() : InstanceOf["Type::Registry"]

This method returns a type registry object comprised of the types declare in the declared type libraries.

registry example #1
# given: synopsis

my $registry = $subtests->registry;

routines

routines() : Any

This method registers and executes a subtest which tests the declared routines.

routines example #1
# given: synopsis

$subtests->routines;

standard

standard() : InstanceOf["Test::Auto::Subtests"]

This method is shorthand which registers and executes a series of other standard subtests.

standard example #1
# given: synopsis

# use:
$subtests->standard;

# instead of:
# $self->package;
# $self->document;
# $self->libraries;
# $self->inherits;
# $self->attributes;
# $self->methods;
# $self->routines;
# $self->functions;

synopsis

synopsis(CodeRef $callback) : Any

This method evaluates (using eval) the documented synopsis and returns a Data::Object::Try object. The try object can be used to trap exceptions using the catch method, and/or execute the code and return the result using the result method.

synopsis example #1
# given: synopsis

$subtests->synopsis(sub {
  my ($tryable) = @_;
  ok my $result = $tryable->result, 'result ok';
  is ref($result), 'Test::Auto::Subtests', 'isa ok';

  $result;
});

tryable

tryable(Any @arguments) : InstanceOf["Data::Object::Try"]

This method returns a tryable object which can be used to defer code execution with a try/catch construct.

tryable example #1
# given: synopsis

my $tryable = $subtests->tryable;

$tryable->call(sub { $_[0] + 1 });

# $tryable->result(1);
#> 2
tryable example #2
# given: synopsis

my $tryable = $subtests->tryable(1);

$tryable->call(sub { $_[0] + $_[1] });

# $tryable->result(1);
#> 2