NAME

My::Module::Test - Testing routines for Astro::UTDF

SYNOPSIS

use lib qw{ inc };
use My::Module::Test;
plan( 'no_plan' );
require_ok( 'Astro::UTDF' );
round_trip( router => 'ZZ' );
my $utdf = Astro::UTDF->new();
returns( $utdf, router => '  ', 'Default router is blank' );
fails( $utdf, range => 42, 'range() may not',
    'range() is not a mutator' );

DETAILS

This package extends Test::More by adding convenient (to the author) wrappers for its tests. All Test::More subroutines are also exported, and available to the user.

Each subroutine exported by this package represents one test, unless otherwise noted. The calling sequence is generally an invocant, a method name, some arguments, the expected result, and the test name.

Most of the exported subroutines are wrappers for returns().

SUBROUTINES

This package exports the following subroutines:

decode

decode( $utdf, frequency_band => 'S-band',
    'Decode frequency_band()' );

This convenience routine simply splices 'decode' into the argument list as the name of the method, and then chains to "returns". Passing an option hash after the invocant is not supported.

fails

fails( $utdf, range => 42, 'may not be used as a mutator',
    'range() is not a mutator' );

This test succeeds if the tested method throws the expected exception, and fails otherwise. The arguments are an invocant, a method name, any arguments to the method, a match string or regular expression, and a test name. If a match string is passed, it is made into a regular expression by running the results through quotemeta() and then wrapping them in qr{}.

hexify

This convenience routine simply splices { unpack => 'H*' } into the argument list after the invocant, and then chains to "returns". Passing an option hash after the invocant is not supported.

returns

returns( $utdf, router => 'AA', 'Router is AA' );

The arguments are an invocant, a method name, any arguments to the method, the expected value, and the name of the test. In the example there are no arguments. The method is called on the invocant, and a Test::More::is() test performed on the result. If the method throws an exception, the test fails.

An options hash can be given as the second argument (i.e. after the invocant but before the method name). This hash can contain the following keys:

sprintf => template

This option causes the result of the method to be formatted with sprintf() using the given template. The formatted value is compared to the expected value.

unpack => template

This option causes the result of the method to be unpacked using the given template. The unpacked value is compared to the expected value.

round_trip

round_trip( router => 'ZZ' );

This method creates an Astro::UTDF object, calls the given mutator with the given value, then calls raw_record() on the new object. The raw record thus obtained is used to generate a second object. A test of the value returned by the original method called on the new object is constructed, and chained to /returns. A test name is generated which describes the attribute and its value.

Just to be inconsistent, the optional hash for /returns can be passed as the third argument. You can use this hash to override the generated name by passing the desired name as the value of the name key:

round_trip( router => 'ZZ', { name => 'Bogus router' } );

SUPPORT

Support is by the author. Please file bug reports at https://rt.cpan.org/Public/Dist/Display.html?Name=Astro-UTDF, https://github.com/trwyant/perl-Astro-UTDF/issues, or in electronic mail to the author.

AUTHOR

Thomas R. Wyant, III wyant at cpan dot org

COPYRIGHT AND LICENSE

Copyright (C) 2010, 2012-2021 Thomas R. Wyant, III

This program is free software; you can redistribute it and/or modify it under the same terms as Perl 5.10.0. For more details, see the full text of the licenses in the directory LICENSES.

This program is distributed in the hope that it will be useful, but without any warranty; without even the implied warranty of merchantability or fitness for a particular purpose.