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;

plugin

  plugin(Str $name) : Object

This method builds, tests, and returns a plugin object based on the name provided.

plugin example #1
  # given: synopsis

  $subtests->plugin('ShortDescription');

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;

scenario

  scenario(Str $name, CodeRef $callback) : Any

This method finds and evaluates (using eval) the documented scenario 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.

scenario example #1
  package main;

  use Test::Auto;

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

  my $subtests = $test->subtests;

  $subtests->scenario('testauto', sub {
    my ($tryable) = @_;

    ok my $result = $tryable->result, 'result ok';

    $result;
  });

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;
  # $self->types;

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

AUTHOR

Al Newkirk, awncorp@cpan.org

LICENSE

Copyright (C) 2011-2019, Al Newkirk, et al.

This is free software; you can redistribute it and/or modify it under the terms of the The Apache License, Version 2.0, as elucidated in the "license file".

PROJECT

Wiki

Project

Initiatives

Milestones

Issues