NAME
Astro::SIMBAD::Client::Test - Provide test harness for Astro::SIMBAD::Client
SYNOPSIS
use lib qw{ inc };
use Astro::SIMBAD::Client::Test;
access; # Check access to SIMBAD web site.
# Tests here
end; # All testing complete
DETAILS
This module provides some subroutines to help test the Astro::SIMBAD::Client package. All the documented subroutines are prototyped, and are exported by default.
A test would typically consist of:
* A call to call(), to execute a method;
* A call to deref(), to select from the output structure the value to be tested;
* A call to test(), to provide the standard value and the test name, and actually perform the test.
Since many tests use the same data, the load_data() subroutine can be called to import a data structure (stored as a Data::Dumper hash), and the canned() subroutine can be used to select the standard value from the hash.
The subroutines exported are:
access
This subroutine must be called, if at all, before the first test. It checks access to the SIMBAD web site. If the web site is accessable, it simply returns. If not, it calls plan skip_all.
call
This subroutine calls an Astro::SIMBAD::Client|Astro::SIMBAD::Client method, instantiating the object if needed. The results of the call are not returned, but are made available for testing.
call_a
This subroutine is similar to call, but the method call is made inside an array constructor.
canned
This subroutine returns the content of the canned data hash loaded by the most recent call to load_data(). The arguments are the hash keys and array indices needed to navigate to the desired datum. If the desired datum is not found, an exception is thrown.
clear
This subroutine prepares for another round of testing by clearing the skip indicator and any results.
count
This subroutine counts the number of elements in the array reference returned by the most recent call(), and makes that available for testing. If the most recent call() did not return an array reference, the tested value is undef.
deref
This subroutine returns the selected datum from the result of the most recent call(), and makes it available for testing. The arguments are the hash keys and array indices needed to navigate to the desired datum. If the desired datum is not found, undef is used for testing.
deref_curr
This subroutine is like deref(), but the navigation is applied to the current value to be tested.
dumper
This subroutine loads Data::Dumper and dumps the current content of the value to be tested.
echo
This subroutine simply displays its arguments. It is implemented via the Test::More diag() method.
end
This subroutine must be called after testing is complete, to let the test harness know that testing is complete.
find
This subroutine finds a given value in the structure which is available for testing. The value to look for is the last argument; the other argumments are navigation information, such as would be passed to deref().
If structure available for testing is not an array reference, undef is made available for testing. Otherwise, the subroutine iterates over the elements in the array, performing the navigation on each in turn, and testing whether the desired value is found. If it is, the array element in which it is found becomes the value available for testing. Otherwise undef becomes available for testing.
hidden
This subroutine returns true if its argument is the name of a module hidden by Test::Without::Module. Otherwise it returns false.
load_data
This subroutine takes as its argument a file containing data to be provided via the canned() subroutine. The contents of the file will be string eval-ed.
load_module
This subroutine takes as arguments a number of Perl module names. It attempts to require these in order, stopping when the first require succeeds. If none succeeds, the internal skip indicator is set, so that subsequent tests are skipped until clear() is called.
Load status is cached, so only one eval is done per module.
module_loaded
This subroutine takes as its first argument the name of a module. The second argument is the name of one of the Astro::SIMBAD::Client::Test subroutines, and subsequent arguments are arguments for the named subroutine. If the named module has not been loaded, nothing happens. If the named module has been loaded, the named subroutine is called (as a co-routine), with the given arguments.
returned_value
This subroutine dumps the value returned by the last call as a scalar. It is intended for diagnostics only.
silent
This subroutine causes exception diagnostics displayed by call() and call_a() to be silenced if skipping is in effect. The argument is interpreted as a Perl boolean, and defaults to the negation of the current setting. If skipping is not in effect, diagnostics will be issued regardless of whether silence 1 is in effect.
This is cleared by clear.
test
This subroutine performs the actual test. It takes two arguments: the expected value, and the name of the test. The value made available by call(), count(), deref(), deref_curr(), or find() is compared to the expected value, and the test succeeds or fails based on the result of the comparison.
If the expected value is a Regexp object, the comparison is done with the Test::More like() subroutine. If it looks like a number, the comparison is done with cmp_ok for numeric equality. Otherwise, the comparison is done with is.
AUTHOR
Thomas R. Wyant, III (wyant at cpan dot org)
COPYRIGHT AND LICENSE
Copyright (C) 2011-2013 by 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.