Test-Data-1.24/000755 000765 000024 00000000000 12261570573 013474 5ustar00brianstaff000000 000000 Test-Data-1.24/Changes000644 000765 000024 00000005141 12261570571 014766 0ustar00brianstaff000000 000000 # $Id$ 1.24 - Fri Jan 3 12:20:49 2014 * Get rid of MYMETA 1.22 - Wed Jul 18 18:06:51 2012 * Rearrange the modules so I don't have to specify manpage locations (RT #46835) 1.21 - Sat Oct 27 20:48:15 2007 * distro cleanups after moving from CVS to SVN 1.20 - Tue Jan 9 22:45:37 2007 * updated copyright and license info * no code changes, so no need to upgrade 1.19 - Wed May 17 21:59:28 2006 * Updates for the distro and kwalitee. There's no need to upgrade. 1.18 - Wed Jul 6 17:07:28 2005 * fixed some error messages in t/array.t. No need to upgrade it you already have this module. 1.17 - Tue Mar 8 17:46:44 2005 * Added POD coverage tests: no need to upgrade 1.02 - Thu Sep 2 21:06:33 2004 * fixed a documentation grammar bug * cleaned up the distro a bit and added a README * you don't need to upgrade if you already have this module 1.01 - Mon May 31 01:16:58 2004 * fixed array_once_ok, thanks to Tom Heady * bumped the version past 1.01 0.96 - Thu Apr 22 15:02:25 2004 * functions in Test::Data::Scalar now return the result of ok() rather than something else. Thanks to Andy Lester for spotting the problem 0.95 - Sat Feb 28 08:09:48 2004 * added four functions to Test::Data::Array to check if an array is sorted (up or down, string or number) 0.94 - Mon Dec 1 20:57:11 CST 2003 * No changes. Tests should run on Windows now. 0.93 - Sat Nov 29 19:18:34 CST 2003 * Added new META.yml * pod.t uses new Test::Pod technology. * Removed TODO test on undef_ok() catching an empty list passed in. The prototype means that C<()> will get passed as a scalar, not an empty list. 0.92 - Sun May 11, 2003 21:26:00 2003 * Fixed hash_value_false_ok(), which was never defined. * Fixed incorrect $VERSION in each package. * Removed requirements on Test::Manifest and Test::Prereq. Test::Pod can get used on the install, but it's OK if not. 0.91 - Fri Dec 20 16:48:58 2002 * functions from Scalar::Util need full package specification since i do not import them. this fixes all of the functions based on Scalar::Util. * removed dualvar test. it does not work, and i need to figure out how to make it work * cleaned up the Pod which had some extra whitespace in places 0.9 Mon Nov 4 19:41:52 CST 2002 + fixed some calls to ok() that were missing name parameter + man pages install correctly 0.8 Wed Oct 23 13:35:22 CDT 2002 + all functions can take optional name arguments + added not_exists_ok, hash_value_undef_ok, hash_value_false_ok 0.7 Mon Sep 30 17:01:10 PDT 2002 + added number_bewteen_ok, string_between_ok + added array_empty_ok, array_length_ok Test-Data-1.24/examples/000755 000765 000024 00000000000 12261570573 015312 5ustar00brianstaff000000 000000 Test-Data-1.24/lib/000755 000765 000024 00000000000 12261570573 014242 5ustar00brianstaff000000 000000 Test-Data-1.24/LICENSE000644 000765 000024 00000000073 12261570571 014477 0ustar00brianstaff000000 000000 You can use Test::Data under the same terms as Perl itself.Test-Data-1.24/Makefile.PL000644 000765 000024 00000001216 12261570571 015444 0ustar00brianstaff000000 000000 use ExtUtils::MakeMaker 6.48; require 5.008; eval "use Test::Manifest 1.21"; WriteMakefile ( 'NAME' => 'Test::Data', 'ABSTRACT' => 'Test data type properties and values', 'VERSION_FROM' => 'lib/Test/Data.pm', 'LICENSE' => 'perl', 'AUTHOR' => 'brian d foy ', 'PREREQ_PM' => { 'List::Util' => '0', 'Scalar::Util' => '0', 'Test::Builder' => '0', 'Test::Builder::Tester' => '0', 'Test::More' => '0.95', }, META_MERGE => { resources => { repository => 'https://github.com/briandfoy/test-data', } }, clean => { FILES => 'Test-Data-*' }, ); Test-Data-1.24/MANIFEST000644 000765 000024 00000000752 12261570573 014631 0ustar00brianstaff000000 000000 Changes examples/README lib/Test/Data.pm lib/Test/Data/Array.pm lib/Test/Data/Function.pm lib/Test/Data/Hash.pm lib/Test/Data/Scalar.pm LICENSE Makefile.PL MANIFEST This list of files MANIFEST.SKIP README t/array.t t/function.t t/hash.t t/import.t t/load.t t/pod.t t/pod_coverage.t t/prereq.t t/scalar.t t/test_manifest META.yml Module YAML meta-data (added by MakeMaker) META.json Module JSON meta-data (added by MakeMaker) Test-Data-1.24/MANIFEST.SKIP000644 000765 000024 00000002006 12261570571 015366 0ustar00brianstaff000000 000000 #!start included /usr/local/perls/perl-5.18.1/lib/5.18.1/ExtUtils/MANIFEST.SKIP # Avoid version control files. \bRCS\b \bCVS\b \bSCCS\b ,v$ \B\.svn\b \B\.git\b \B\.gitignore\b \b_darcs\b \B\.cvsignore$ # Avoid VMS specific MakeMaker generated files \bDescrip.MMS$ \bDESCRIP.MMS$ \bdescrip.mms$ # Avoid Makemaker generated and utility files. \bMANIFEST\.bak \bMakefile$ \bblib/ \bMakeMaker-\d \bpm_to_blib\.ts$ \bpm_to_blib$ \bblibdirs\.ts$ # 6.18 through 6.25 generated this # Avoid Module::Build generated and utility files. \bBuild$ \b_build/ \bBuild.bat$ \bBuild.COM$ \bBUILD.COM$ \bbuild.com$ # Avoid temp and backup files. ~$ \.old$ \#$ \b\.# \.bak$ \.tmp$ \.# \.rej$ # Avoid OS-specific files/dirs # Mac OSX metadata \B\.DS_Store # Mac OSX SMB mount metadata files \B\._ # Avoid Devel::Cover and Devel::CoverX::Covered files. \bcover_db\b \bcovered\b # Avoid MYMETA files ^MYMETA\. #!end included /usr/local/perls/perl-5.18.1/lib/5.18.1/ExtUtils/MANIFEST.SKIP \.travis\.yml \.releaserc \.lwpcookies Test-.* Test-Data-1.24/META.json000664 000765 000024 00000002146 12261570573 015122 0ustar00brianstaff000000 000000 { "abstract" : "Test data type properties and values", "author" : [ "brian d foy " ], "dynamic_config" : 1, "generated_by" : "ExtUtils::MakeMaker version 6.62, CPAN::Meta::Converter version 2.112150", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : "2" }, "name" : "Test-Data", "no_index" : { "directory" : [ "t", "inc" ] }, "prereqs" : { "build" : { "requires" : { "ExtUtils::MakeMaker" : 0 } }, "configure" : { "requires" : { "ExtUtils::MakeMaker" : 0 } }, "runtime" : { "requires" : { "List::Util" : 0, "Scalar::Util" : 0, "Test::Builder" : 0, "Test::Builder::Tester" : 0, "Test::More" : "0.95" } } }, "release_status" : "stable", "resources" : { "repository" : { "url" : "https://github.com/briandfoy/test-data" } }, "version" : "1.24" } Test-Data-1.24/META.yml000664 000765 000024 00000001174 12261570573 014752 0ustar00brianstaff000000 000000 --- abstract: 'Test data type properties and values' author: - 'brian d foy ' build_requires: ExtUtils::MakeMaker: 0 configure_requires: ExtUtils::MakeMaker: 0 dynamic_config: 1 generated_by: 'ExtUtils::MakeMaker version 6.62, CPAN::Meta::Converter version 2.112150' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: 1.4 name: Test-Data no_index: directory: - t - inc requires: List::Util: 0 Scalar::Util: 0 Test::Builder: 0 Test::Builder::Tester: 0 Test::More: 0.95 resources: repository: https://github.com/briandfoy/test-data version: 1.24 Test-Data-1.24/README000644 000765 000024 00000000760 12261570571 014355 0ustar00brianstaff000000 000000 You can install this using in the usual Perl fashion perl Makefile.PL make make test make install The documentation is in the module file. You can read the documentation with perldoc (in the same way before or after you install it). perldoc Test::Data Before you install the module, you can look at the documentation directly from the module files. perldoc lib/Test/Data.pm This source is in Github: https://github.com/briandfoy/test-data Enjoy, brian d foy, bdfoy@cpan.org Test-Data-1.24/t/000755 000765 000024 00000000000 12261570573 013737 5ustar00brianstaff000000 000000 Test-Data-1.24/t/array.t000644 000765 000024 00000007160 12261570571 015244 0ustar00brianstaff000000 000000 use Test::Builder::Tester tests => 3; use Test::More; use Test::Data qw(Array); #use Carp; #$SIG{__WARN__} = \&confess; my %line; TEST_ARRAY_FUNCS: { my @array = 4..6; my @empty = (); test_err(); array_any_ok( 5, @array ); test_out( "ok 1 - Array contains item" ); array_any_ok( 9, @array, "Array does not contain 9, go fish" ); $line{'9x0'} = __LINE__; test_out( "not ok 2 - Array does not contain 9, go fish" ); array_once_ok( 5, @array, "Array contains 5 once" ); test_out( "ok 3 - Array contains 5 once" ); { my @array = (5, 5); array_once_ok( 5, @array, "Array has 5 twice, not once" ); $line{'5x2'} = __LINE__; test_out( "not ok 4 - Array has 5 twice, not once" ); @array = (); array_once_ok( 5, @array, "Array has no items" ); $line{'5x0'} = __LINE__; test_out( "not ok 5 - Array has no items" ); @array = ( 6, 6 ); array_once_ok( 5, @array, "Array has no 5's, but two 6's" ); $line{'6x2'} = __LINE__; test_out( "not ok 6 - Array has no 5's, but two 6's" ); } array_none_ok( 7, @array ); array_sum_ok( 15, @array ); array_max_ok( 6, @array ); array_min_ok( 3, @array ); array_empty_ok( @empty ); array_length_ok( @array, 3 ); test_out( "ok 7 - Array does not contain item", "ok 8 - Array sum is correct", "ok 9 - Array maximum is okay", "ok 10 - Array minimum is okay", "ok 11 - Array is empty", "ok 12 - Array length is correct", ); test_err( "# Failed test ($0 at line $line{'9x0'})", "# Failed test ($0 at line $line{'5x2'})", "# Failed test ($0 at line $line{'5x0'})", "# Failed test ($0 at line $line{'6x2'})" ); test_test('Array functions work'); } TEST_STR_SORTS: { my @array = 'a' .. 'f'; my @reverse = reverse @array; test_err(); array_sortedstr_ascending_ok( @array ); array_sortedstr_descending_ok( @reverse ); test_out( "ok 1 - Array is in ascending order", "ok 2 - Array is in descending order", ); array_sortedstr_ascending_ok( @reverse ); $line{'up'} = __LINE__; array_sortedstr_descending_ok( @array ); $line{'down'} = __LINE__; test_out( 'not ok 3 - Array is in ascending order', 'not ok 4 - Array is in descending order', ); test_err( "# Failed test ($0 at line $line{up})", "# Failed test ($0 at line $line{down})", ); my @bad = ( 'a' .. 'f', 'b' ); my @bad_reverse = reverse @bad; array_sortedstr_ascending_ok( @bad ); $line{'up'} = __LINE__; array_sortedstr_descending_ok( @bad_reverse ); $line{'down'} = __LINE__; test_out( 'not ok 5 - Array is in ascending order', 'not ok 6 - Array is in descending order', ); test_err( "# Failed test ($0 at line $line{up})", "# Failed test ($0 at line $line{down})", ); test_test('Sort comparisons work'); } TEST_NUM_SORTS: { my @array = 1 .. 5; my @reverse = reverse @array; test_err(); array_sorted_ascending_ok( @array ); array_sorted_descending_ok( @reverse ); test_out( "ok 1 - Array is in ascending order", "ok 2 - Array is in descending order", ); array_sorted_ascending_ok( @reverse ); $line{up} = __LINE__; array_sorted_descending_ok( @array ); $line{down} = __LINE__; test_out( 'not ok 3 - Array is in ascending order', 'not ok 4 - Array is in descending order', ); test_err( "# Failed test ($0 at line $line{up})", "# Failed test ($0 at line $line{down})", ); my @bad = ( 1 .. 5, 3 ); my @bad_reverse = reverse @bad; array_sorted_ascending_ok( @bad ); $line{up} = __LINE__; array_sorted_descending_ok( @bad_reverse ); $line{down} = __LINE__; test_out( 'not ok 5 - Array is in ascending order', 'not ok 6 - Array is in descending order', ); test_err( "# Failed test ($0 at line $line{up})", "# Failed test ($0 at line $line{down})", ); test_test('Sort comparisons work'); } Test-Data-1.24/t/function.t000644 000765 000024 00000000242 12261570571 015745 0ustar00brianstaff000000 000000 use Test::More tests => 2; use Test::Data qw(Function); sub fooey($$) { 1 } prototype_ok( &fooey, '$$', 'Double scalar fooey' ); prototype_ok( &fooey, '$$' ); Test-Data-1.24/t/hash.t000644 000765 000024 00000000165 12261570571 015047 0ustar00brianstaff000000 000000 use Test::More tests => 1; use Test::Data qw(Hash); TODO: { local $TODO = "No tests for Hash yet"; ok( 0 ); } Test-Data-1.24/t/import.t000644 000765 000024 00000003416 12261570571 015440 0ustar00brianstaff000000 000000 use Test::More; require Test::Data; Test::Data->import( qw(Scalar Array Hash Function) ); my @scalar_functions = qw( blessed_ok defined_ok greater_than length_ok less_than maxlength_ok minlength_ok number_ok readonly_ok ref_ok ref_type_ok strong_ok tainted_ok untainted_ok weak_ok undef_ok number_between_ok string_between_ok ); my @hash_functions = qw(exists_ok not_exists_ok hash_value_defined_ok hash_value_undef_ok hash_value_true_ok hash_value_false_ok); my @array_functions = qw(array_any_ok array_none_ok array_once_ok array_multiple_ok array_max_ok array_min_ok array_maxstr_ok array_minstr_ok array_sum_ok array_length_ok array_empty_ok array_sortedstr_ascending_ok array_sortedstr_descending_ok array_sorted_ascending_ok array_sorted_descending_ok ); my @function_functions = qw(prototype_ok); plan tests => @scalar_functions + @hash_functions + @array_functions + @function_functions; # Scalar test_functions( "Scalar", @scalar_functions ); # Array test_functions( "Array", @array_functions ); # Hashes test_functions( "Hash", @hash_functions ); # Functions test_functions( "Function", @function_functions ); # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # sub test_functions { my( $package, @function_names ) = @_; foreach my $function ( @function_names ) { check_function( $function, $package ); } } sub check_function { my( $function, $package ) = @_; my $ok = sub_defined( $function ); unless( $ok ) { diag( "\tFunction [$function] not defined in main::" ); $a = sub_defined( "Test\::Data\::$package\::$function" ); diag( "\tFunction is defined in $package, though" ) if $a; } ok( $ok, "$package package exported $function" ); } sub sub_defined { my $function = shift; eval( "defined \&$function" ); } Test-Data-1.24/t/load.t000644 000765 000024 00000000437 12261570571 015045 0ustar00brianstaff000000 000000 use Test::More; my @modules = qw( Test::Data Test::Data::Array Test::Data::Function Test::Data::Hash Test::Data::Function ); foreach $module ( @modules ) { use_ok( $module ); my $var = '$' . $module . '::VERSION'; my $ver = eval $var; cmp_ok( $ver, '>', 0 ); } done_testing(); Test-Data-1.24/t/pod.t000644 000765 000024 00000000201 12261570571 014675 0ustar00brianstaff000000 000000 use Test::More; eval "use Test::Pod 1.00"; plan skip_all => "Test::Pod 1.00 required for testing POD" if $@; all_pod_files_ok(); Test-Data-1.24/t/pod_coverage.t000644 000765 000024 00000000602 12261570571 016555 0ustar00brianstaff000000 000000 use Test::More; eval "use Test::Pod::Coverage"; if( $@ ) { plan skip_all => "Test::Pod::Coverage required for testing POD"; } else { my @modules = qw( Test::Data Test::Data::Array Test::Data::Function Test::Data::Hash Test::Data::Scalar ); plan tests => scalar @modules; pod_coverage_ok( $_, { trustme => [ qr/VERSION/ ] } ) foreach ( @modules ); } Test-Data-1.24/t/prereq.t000644 000765 000024 00000000217 12261570571 015420 0ustar00brianstaff000000 000000 local $^W = 0; use Test::More; eval "use Test::Prereq 0.51"; plan skip_all => "Test::Prereq required to test dependencies" if $@; prereq_ok(); Test-Data-1.24/t/scalar.t000644 000765 000024 00000012407 12261570571 015373 0ustar00brianstaff000000 000000 use Test::Builder::Tester tests => 58; use Test::More; use_ok( 'Test::Data', 'Scalar' ); # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # foreach my $value ( [], {} ) { my $object = bless $value; test_out('ok 1 - Scalar is blessed'); blessed_ok( $object ); test_test('blessed_ok'); } foreach my $value ( [], {}, "Hello", undef, '', 1, 0 ) { my $ref = ref $value; test_diag("Expected a blessed value, but didn't get it", qq|\tReference type is "$ref"|, " Failed test ($0 at line " . line_num(+4) . ")",); test_out('not ok 1 - Scalar is blessed'); blessed_ok( $value ); test_test('blessed_ok catches non-reference'); } # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # test_out('ok 1 - Scalar is defined'); defined_ok( "defined" ); test_test('defined_ok'); test_diag("Expected a defined value, got an undefined one", "Scalar is defined", " Failed test ($0 at line " . line_num(+4) . ")",); test_out('not ok 1 - Scalar is defined'); defined_ok( undef ); test_test('defined_ok catches undef'); { my $test; test_out( map { "ok $_ - Scalar is undefined" } 1 .. 2 ); undef_ok( undef ); undef_ok( $test ); test_test('undef_ok'); } foreach my $value ( 'foo', '', 0, '0' ) { my $test = 'foo'; test_diag("Expected an undefined value, got a defined one", " Failed test ($0 at line " . line_num(+3) . ")",); test_out( 'not ok 1 - Scalar is undefined' ); undef_ok( 'foo' ); test_test('undef_ok catches defined value'); } # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # foreach my $pair ( ( [2,1], [4,2], [0,-1], [-1,-2] ) ) { test_out('ok 1 - Scalar is greater than bound'); greater_than( $pair->[0], $pair->[1] ); test_test('greater_than'); test_diag("Number is greater than the bound.", "\tExpected a number less than [$$pair[1]]", "\tGot [$$pair[0]]", " Failed test ($0 at line " . line_num(+6) . ")", ); test_out('not ok 1 - Scalar is less than bound'); less_than( $pair->[0], $pair->[1] ); test_test('less than catches out-of-bonds'); test_out('ok 1 - Scalar is less than bound'); less_than( $pair->[1], $pair->[0] ); test_test('less_than'); test_diag("Number is less than the bound.", "\tExpected a number greater than [$$pair[0]]", "\tGot [$$pair[1]]", " Failed test ($0 at line " . line_num(+6) . ")", ); test_out('not ok 1 - Scalar is greater than bound'); greater_than( $pair->[1], $pair->[0] ); test_test('greater_than catches out-of-bonds'); } # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # foreach my $string ( ( '', '123', ' ', 'Roscoe' ) ) { my $length = length $string; test_out( "ok 1 - Scalar has right length", "ok 2 - Scalar length is less than bound", "ok 3 - Scalar length is less than bound", "ok 4 - Scalar length is greater than bound", "ok 5 - Scalar length is greater than bound", "ok 6 - Scalar length is greater than bound", ); length_ok( $string, $length ); maxlength_ok( $string, $length ); maxlength_ok( $string, $length + 1 ); minlength_ok( $string, $length ); minlength_ok( $string, $length - 1 ); minlength_ok( $string, 0 ); test_test('length_ok, maxlength_ok, minlength_ok'); foreach my $bad ( $length - 1, $length + 1, -1, 0 ) { next if $bad == $length; test_diag("Length of value not within bounds", "\tExpected length=[$bad]", "\tGot [$length]", " Failed test ($0 at line " . line_num(+6) . ")", ); test_out('not ok 1 - Scalar has right length'); length_ok( $string, $bad ); test_test('length_ok catches errors'); } } # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # test_out( "ok 1 - Scalar is a reference", "ok 2 - Scalar is not a weak reference", "ok 3 - Scalar is a reference", "ok 4 - Scalar is not a weak reference", ); foreach my $value ( ( {}, [] ) ) { ref_ok( $value ); strong_ok( $value ); } test_test('ref_ok, strong_ok'); # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # test_out( map { "ok $_ - Scalar is in numerical range" } 1 .. 4 ); number_between_ok( 5, 5, 6 ); number_between_ok( 6, 5, 6 ); number_between_ok( 5, 4, 6 ); number_between_ok( 5.5, 5, 6 ); test_test('number_between_ok'); test_diag("Number [4] was not within bounds", "\tExpected lower bound [5]", "\tExpected upper bound [6]", " Failed test ($0 at line " . line_num(+5) . ")",); test_out( "not ok 1 - Scalar is in numerical range" ); number_between_ok( 4, 5, 6 ); test_test('number_between_ok catches failures'); # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # test_out( map { "ok $_ - Scalar is in string range" } 1 .. 5 ); string_between_ok( 5, 5, 6 ); string_between_ok( 6, 5, 6 ); string_between_ok( 5, 4, 6 ); string_between_ok( 'dino', 'barney', 'fred' ); string_between_ok( 11, 1, 2 ); test_test('string_between_ok'); test_diag("String [wilma] was not within bounds", "\tExpected lower bound [fred]", "\tExpected upper bound [pebbles]", " Failed test ($0 at line " . line_num(+5) . ")",); test_out( "not ok 1 - Scalar is in string range" ); string_between_ok( 'wilma', 'fred', 'pebbles' ); test_test('string_between_ok catches failures'); # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # test_out( map { "ok $_ - Scalar is not tainted" } 1 .. 1 ); untainted_ok( 'Foo' ); test_test('untainted_ok'); Test-Data-1.24/t/test_manifest000644 000765 000024 00000000121 12261570571 016517 0ustar00brianstaff000000 000000 load.t pod.t pod_coverage.t prereq.t import.t scalar.t array.t hash.t function.t Test-Data-1.24/lib/Test/000755 000765 000024 00000000000 12261570573 015161 5ustar00brianstaff000000 000000 Test-Data-1.24/lib/Test/Data/000755 000765 000024 00000000000 12261570573 016032 5ustar00brianstaff000000 000000 Test-Data-1.24/lib/Test/Data.pm000644 000765 000024 00000004164 12261570571 016373 0ustar00brianstaff000000 000000 package Test::Data; use strict; use vars qw($VERSION); $VERSION = '1.24'; use Carp qw(carp); use Test::Builder; my $Test = Test::Builder->new(); =encoding utf8 =head1 NAME Test::Data -- test functions for particular variable types =head1 SYNOPSIS use Test::Data qw(Scalar Array Hash Function); =head1 DESCRIPTION Test::Data provides utility functions to check properties and values of data and variables. =cut $Exporter::Verbose = 0; sub import { my $self = shift; my $caller = caller; foreach my $package ( @_ ) { my $full_package = "Test::Data::$package"; eval{ eval "require $full_package" }; if( $@ ) { carp "Could not require Test::Data::$package: $@"; } $full_package->export($caller); } } sub VERSION { return $VERSION } =head2 Functions Plug-in modules define functions for each data type. See the appropriate module. =head2 How it works The Test::Data module simply emports functions from Test::Data::* modules. Each module defines a self-contained function, and puts that function name into @EXPORT. Test::Data defines its own import function, but that does not matter to the plug-in modules. If you want to write a plug-in module, follow the example of one that already exists. Name the module Test::Data::Foo, where you replace Foo with the right name. Test::Data should automatically find it. =head1 BUGS I'm not a very good Windows Perler, so some things don't work as they should on Windows. I recently got a Windows box so I can test things, but if you run into problems, I can use all the patches or advice you care to send. =head1 SEE ALSO L, L, L, L, L =head1 SOURCE AVAILABILITY This source is in Github: https://github.com/briandfoy/test-data =head1 AUTHOR brian d foy, C<< >> =head1 COPYRIGHT AND LICENSE Copyright (c) 2002-2012 brian d foy. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut "Now is the time for all good men to come to the aid of their country"; Test-Data-1.24/lib/Test/Data/Array.pm000644 000765 000024 00000015660 12261570571 017454 0ustar00brianstaff000000 000000 package Test::Data::Array; use strict; use base qw(Exporter); use vars qw(@EXPORT $VERSION); $VERSION = '1.24'; @EXPORT = qw( array_any_ok array_none_ok array_once_ok array_multiple_ok array_max_ok array_min_ok array_maxstr_ok array_minstr_ok array_sum_ok array_length_ok array_empty_ok array_sortedstr_ascending_ok array_sortedstr_descending_ok array_sorted_ascending_ok array_sorted_descending_ok ); use List::Util qw(sum min max minstr maxstr); use Test::Builder; my $Test = Test::Builder->new(); =encoding utf8 =head1 NAME Test::Data::Array -- test functions for array variables =head1 SYNOPSIS use Test::Data qw(Array); =head1 DESCRIPTION =head2 Functions =over 4 =item array_any_ok( ITEM, ARRAY [, NAME] ) Ok if any element of ARRAY is ITEM. =cut sub array_any_ok($\@;$) { my $element = shift; my $array = shift; my $name = shift || 'Array contains item'; foreach my $try ( @$array ) { next unless $try eq $element; $Test->ok( 1, $name ); return; } $Test->ok( 0, $name ); } =item array_none_ok( ITEM, ARRAY [, NAME] ) Ok if no element of ARRAY is ITEM. =cut sub array_none_ok($\@;$) { my $element = shift; my $array = shift; my $name = shift || 'Array does not contain item'; foreach my $try ( @$array ) { next unless $try eq $element; $Test->ok( 0, $name ); return; } $Test->ok( 1, $name ); } =item array_once_ok( ITEM, ARRAY [, NAME] ) Ok if only one element of ARRAY is ITEM. =cut sub array_once_ok($\@;$) { my $element = shift; my $array = shift; my $name = shift || 'Array contains item only once'; my %seen = (); my $ok = 0; foreach my $item ( @$array ) { ++$seen{$item} } $ok = 1 if( defined $seen{$element} and $seen{$element} == 1 ); $Test->ok( $ok, $name ); } =item array_multiple_ok( ITEM, ARRAY [, NAME] ) Ok if more than one element of ARRAY is ITEM. =cut sub array_multiple_ok($\@;$) { my $element = shift; my $array = shift; my $name = shift || 'Array contains item at least once'; my %seen = (); foreach my $item ( @$array ) { $seen{$item}++; } $seen{$element} > 1 ? $Test->ok( 1, $name ) : $Test->ok( 0, $name ); } =item array_max_ok( NUMBER, ARRAY [, NAME] ) Ok if all elements of ARRAY are numerically less than or equal to NUMBER. =cut sub array_max_ok($\@;$) { my $item = shift; my $array = shift; my $name = shift || 'Array maximum is okay'; my $actual = max( @$array ); $actual <= $item ? $Test->ok( 1, $name ) : $Test->ok( 0, $name ); } =item array_min_ok( NUMBER, ARRAY [, NAME] ) Ok if all elements of ARRAY are numerically greater than or equal to NUMBER. =cut sub array_min_ok($\@;$) { my $item = shift; my $array = shift; my $name = shift || 'Array minimum is okay'; my $actual = min( @$array ); $actual >= $item ? $Test->ok( 1, $name ) : $Test->ok( 0, $name ); } =item array_maxstr_ok( ITEM, ARRAY [, NAME] ) Ok if all elements of ARRAY are asciibetically less than or equal to MAX. =cut sub array_maxstr_ok($\@;$) { my $item = shift; my $array = shift; my $name = shift || 'Array maximum string is okay'; my $actual = maxstr( @$array ); $actual ge $item ? $Test->ok( 1, $name ) : $Test->ok( 0, $name ); } =item array_minstr_ok( ITEM, ARRAY [, NAME] ) Ok if all elements of ARRAY are asciibetically greater than or equal to MAX. =cut sub array_minstr_ok($\@;$) { my $item = shift; my $array = shift; my $name = shift || 'Array minimum string is okay'; my $actual = minstr( @$array ); $actual le $item ? $Test->ok( 1, $name ) : $Test->ok( 0, $name ); } =item array_sum_ok( SUM, ARRAY [, NAME] ) Ok if the numerical sum of ARRAY is SUM. =cut sub array_sum_ok($\@;$) { my $sum = shift; my $array = shift; my $name = shift || 'Array sum is correct'; my $actual = sum( @$array ); $sum == $actual ? $Test->ok( 1, $name ) : $Test->ok( 0, $name ); } =item array_empty_ok( ARRAY [, NAME] ) Ok if the array contains no elements. =cut sub array_empty_ok(\@;$) { my $array = shift; my $name = shift || 'Array is empty'; $#$array == -1 ? $Test->ok( 1, $name ) : $Test->ok( 0, $name ); } =item array_length_ok( ARRAY, LENGTH [, NAME] ) Ok if the array contains LENGTH number of elements. =cut sub array_length_ok(\@$;$) { my $array = shift; my $length = shift; my $name = shift || 'Array length is correct'; $#$array == $length - 1 ? $Test->ok( 1, $name ) : $Test->ok( 0, $name ); } =item array_sortedstr_ascending_ok( ARRAY, [, NAME] ) Ok if each succeeding element is asciibetically greater than or equal to the one before. =cut sub array_sortedstr_ascending_ok(\@;$) { my $array = shift; my $name = shift || 'Array is in ascending order'; my $last_seen = 0; ELEMENT: foreach my $index ( 1 .. $#$array ) { if( $array->[ $index ] ge $array->[ $index - 1 ] ) { $last_seen = $index; next; } last; } $last_seen == $#$array ? $Test->ok( 1, $name ) : $Test->ok( 0, $name ); } =item array_sortedstr_descending_ok( ARRAY, [, NAME] ) Ok if each succeeding element is asciibetically less than or equal to the one before. =cut sub array_sortedstr_descending_ok(\@;$) { my $array = shift; my $name = shift || 'Array is in descending order'; my $last_seen = 0; ELEMENT: foreach my $index ( 1 .. $#$array ) { if( $array->[ $index ] le $array->[ $index - 1 ] ) { $last_seen = $index; next; } last; } $last_seen == $#$array ? $Test->ok( 1, $name ) : $Test->ok( 0, $name ); } =item array_sorted_ascending_ok( ARRAY, [, NAME] ) Ok if each succeeding element is numerically greater than or equal to the one before. =cut sub array_sorted_ascending_ok(\@;$) { my $array = shift; my $name = shift || 'Array is in ascending order'; my $last_seen = 0; ELEMENT: foreach my $index ( 1 .. $#$array ) { if( $array->[ $index ] >= $array->[ $index - 1 ] ) { $last_seen = $index; next; } last; } $last_seen == $#$array ? $Test->ok( 1, $name ) : $Test->ok( 0, $name ); } =item array_sorted_descending_ok( ARRAY, [, NAME] ) Ok if each succeeding element is numerically less than or equal to the one before. =cut sub array_sorted_descending_ok(\@;$) { my $array = shift; my $name = shift || 'Array is in descending order'; my $last_seen = 0; ELEMENT: foreach my $index ( 1 .. $#$array ) { if( $array->[ $index ] <= $array->[ $index - 1 ] ) { $last_seen = $index; next; } last; } $last_seen == $#$array ? $Test->ok( 1, $name ) : $Test->ok( 0, $name ); } =back =head1 SEE ALSO L, L, L, L, L =head1 SOURCE AVAILABILITY This source is in Github: https://github.com/briandfoy/test-data =head1 AUTHOR brian d foy, C<< >> =head1 COPYRIGHT AND LICENSE Copyright (c) 2002-2012 brian d foy. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut "bumble bee"; Test-Data-1.24/lib/Test/Data/Function.pm000644 000765 000024 00000002570 12261570571 020157 0ustar00brianstaff000000 000000 package Test::Data::Function; use strict; use base qw(Exporter); use vars qw(@EXPORT $VERSION); @EXPORT = qw(prototype_ok); $VERSION = '1.24'; use Test::Builder; my $Test = Test::Builder->new(); =encoding utf8 =head1 NAME Test::Data::Function -- test functions for functions =head1 SYNOPSIS use Test::Data qw(Function); =head1 DESCRIPTION This module provides test functions for subroutine sorts of things. =head2 Functions =over 4 =item prototype_ok( PROTOTYPE, SUB [, NAME ] ) =cut sub prototype_ok(\&$;$) { my $sub = shift; my $prototype = shift; my $name = shift || 'function prototype is correct'; my $actual = prototype( $sub ); my $test = $actual eq $prototype; unless( $test ) { $Test->diag( "Subroutine has prototype [$actual]; expected [$prototype]" ); $Test->ok(0, $name); } else { $Test->ok( $test, $name ); } } =back =head1 SEE ALSO L, L, L, L, L =head1 SOURCE AVAILABILITY This source is in Github: https://github.com/briandfoy/test-data =head1 AUTHOR brian d foy, C<< >> =head1 COPYRIGHT AND LICENSE Copyright (c) 2002-2012 brian d foy. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut "red leather yellow leather"; Test-Data-1.24/lib/Test/Data/Hash.pm000644 000765 000024 00000005650 12261570571 017257 0ustar00brianstaff000000 000000 package Test::Data::Hash; use strict; use base qw(Exporter); use vars qw(@EXPORT $VERSION); @EXPORT = qw(exists_ok not_exists_ok hash_value_defined_ok hash_value_undef_ok hash_value_true_ok hash_value_false_ok); $VERSION = '1.24'; use Test::Builder; my $Test = Test::Builder->new(); =encoding utf8 =head1 NAME Test::Data::Hash -- test functions for hash variables =head1 SYNOPSIS use Test::Data qw(Hash); =head1 DESCRIPTION This modules provides a collection of test utilities for hash variables. Load the module through Test::Data. =head2 Functions =over 4 =item exists_ok( KEY, HASH [, NAME] ) Ok if the value for KEY in HASH exists. The function does not create KEY in HASH. =cut sub exists_ok($\%;$) { my $key = shift; my $hash = shift; my $name = shift || "Hash key [$key] exists"; $Test->ok( exists $hash->{$key}, $name ); } =item not_exists_ok( KEY, HASH [, NAME] ) Ok if the value for KEY in HASH does not exist. The function does not create KEY in HASH. =cut sub not_exists_ok($\%;$) { my $key = shift; my $hash = shift; my $name = shift || "Hash key [$key] does not exist"; $Test->ok( exists $hash->{$key} ? 0 : 1, $name ); } =item hash_value_defined_ok( KEY, HASH [, NAME] ) Ok if the value for KEY in HASH is defined. The function does not create KEY in HASH. =cut sub hash_value_defined_ok($\%;$) { my $key = shift; my $hash = shift; my $name = shift || "Hash value for key [$key] is defined"; $Test->ok( defined $hash->{$key}, $name ); } =item hash_value_undef_ok( KEY, HASH [, NAME] ) Ok if the value for KEY in HASH is undefined. The function does not create KEY in HASH. =cut sub hash_value_undef_ok($\%;$) { my $key = shift; my $hash = shift; my $name = shift || "Hash value for key [$key] is undef"; $Test->ok( defined $hash->{$key} ? 0 : 1, $name ); } =item hash_value_true_ok( KEY, HASH [, NAME] ) Ok if the value for KEY in HASH is true. The function does not create KEY in HASH. =cut sub hash_value_true_ok($\%;$) { my $key = shift; my $hash = shift; my $name = shift || "Hash value for key [$key] is true"; $Test->ok( $hash->{$key}, $name ); } =item hash_value_false_ok( KEY, HASH [, NAME] ) Ok if the value for KEY in HASH is false. The function does not create KEY in HASH. =cut sub hash_value_false_ok($\%;$) { my $key = shift; my $hash = shift; my $name = shift || "Hash value for key [$key] is false"; $Test->ok( $hash->{$key} ? 0 : 1, $name ); } =back =head1 SEE ALSO L, L, L, L, L =head1 SOURCE AVAILABILITY This source is in Github: https://github.com/briandfoy/test-data =head1 AUTHOR brian d foy, C<< >> =head1 COPYRIGHT AND LICENSE Copyright (c) 2002-2012 brian d foy. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut "red leather yellow leather"; Test-Data-1.24/lib/Test/Data/Scalar.pm000644 000765 000024 00000022150 12261570571 017573 0ustar00brianstaff000000 000000 package Test::Data::Scalar; use strict; use base qw(Exporter); use vars qw(@EXPORT $VERSION); @EXPORT = qw( blessed_ok defined_ok dualvar_ok greater_than length_ok less_than maxlength_ok minlength_ok number_ok readonly_ok ref_ok ref_type_ok strong_ok tainted_ok untainted_ok weak_ok undef_ok number_between_ok string_between_ok ); $VERSION = '1.24'; use Scalar::Util; use Test::Builder; my $Test = Test::Builder->new(); =encoding utf8 =head1 NAME Test::Data::Scalar -- test functions for scalar variables =head1 SYNOPSIS use Test::Data qw(Scalar); =head1 DESCRIPTION This modules provides a collection of test utilities for scalar variables. Load the module through Test::Data. =head2 Functions =over 4 =item blessed_ok( SCALAR ) Ok if the SCALAR is a blessed reference. =cut sub blessed_ok ($;$) { my $ref = ref $_[0]; my $ok = Scalar::Util::blessed($_[0]); my $name = $_[1] || 'Scalar is blessed'; $Test->diag("Expected a blessed value, but didn't get it\n\t" . qq|Reference type is "$ref"\n| ) unless $ok; $Test->ok( $ok, $name ); } =item defined_ok( SCALAR ) Ok if the SCALAR is defined. =cut sub defined_ok ($;$) { my $ok = defined $_[0]; my $name = $_[1] || 'Scalar is defined'; $Test->diag("Expected a defined value, got an undefined one\n", $name ) unless $ok; $Test->ok( $ok, $name ); } =item undef_ok( SCALAR ) Ok if the SCALAR is undefined. =cut sub undef_ok ($;$) { my $name = $_[1] || 'Scalar is undefined'; if( @_ > 0 ) { my $ok = not defined $_[0]; $Test->diag("Expected an undefined value, got a defined one\n") unless $ok; $Test->ok( $ok, $name ); } else { $Test->diag("Expected an undefined value, but got no arguments\n"); $Test->ok( 0, $name ); } } =item dualvar_ok( SCALAR ) Ok if the scalar is a dualvar. How do I test this? sub dualvar_ok ($;$) { my $ok = Scalar::Util::dualvar( $_[0] ); my $name = $_[1] || 'Scalar is a dualvar'; $Test->ok( $ok, $name ); $Test->diag("Expected a dualvar, didn't get it\n") unless $ok; } =cut =item greater_than( SCALAR, BOUND ) Ok if the SCALAR is numerically greater than BOUND. =cut sub greater_than ($$;$) { my $value = shift; my $bound = shift; my $name = shift || 'Scalar is greater than bound'; my $ok = $value > $bound; $Test->diag("Number is less than the bound.\n\t" . "Expected a number greater than [$bound]\n\t" . "Got [$value]\n") unless $ok; $Test->ok( $ok, $name ); } =item length_ok( SCALAR, LENGTH ) Ok if the length of SCALAR is LENGTH. =cut sub length_ok ($$;$) { my $string = shift; my $length = shift; my $name = shift || 'Scalar has right length'; my $actual = length $string; my $ok = $length == $actual; $Test->diag("Length of value not within bounds\n\t" . "Expected length=[$length]\n\t" . "Got [$actual]\n") unless $ok; $Test->ok( $ok, $name ); } =item less_than( SCALAR, BOUND ) Ok if the SCALAR is numerically less than BOUND. =cut sub less_than ($$;$) { my $value = shift; my $bound = shift; my $name = shift || 'Scalar is less than bound'; my $ok = $value < $bound; $Test->diag("Number is greater than the bound.\n\t" . "Expected a number less than [$bound]\n\t" . "Got [$value]\n") unless $ok; $Test->ok( $ok, $name ); } =item maxlength_ok( SCALAR, LENGTH ) Ok is the length of SCALAR is less than or equal to LENGTH. =cut sub maxlength_ok($$;$) { my $string = shift; my $length = shift; my $name = shift || 'Scalar length is less than bound'; my $actual = length $string; my $ok = $actual <= $length; $Test->diag("Length of value longer than expected\n\t" . "Expected max=[$length]\n\tGot [$actual]\n") unless $ok; $Test->ok( $ok, $name ); } =item minlength_ok( SCALAR, LENGTH ) Ok is the length of SCALAR is greater than or equal to LENGTH. =cut sub minlength_ok($$;$) { my $string = shift; my $length = shift; my $name = shift || 'Scalar length is greater than bound'; my $actual = length $string; my $ok = $actual >= $length; $Test->diag("Length of value shorter than expected\n\t" . "Expected min=[$length]\n\tGot [$actual]\n") unless $ok; $Test->ok( $ok, $name ); } =item number_ok( SCALAR ) Ok if the SCALAR is a number ( or a string that represents a number ). At the moment, a number is just a string of digits. This needs work. =cut sub number_ok($;$) { my $number = shift; my $name = shift || 'Scalar is a number'; $number =~ /\D/ ? $Test->ok( 0, $name ) : $Test->ok( 1, $name ); } =item number_between_ok( SCALAR, LOWER, UPPER ) Ok if the number in SCALAR sorts between the number in LOWER and the number in UPPER, numerically. If you put something that isn't a number into UPPER or LOWER, Perl will try to make it into a number and you may get unexpected results. =cut sub number_between_ok($$$;$) { my $number = shift; my $lower = shift; my $upper = shift; my $name = shift || 'Scalar is in numerical range'; unless( defined $lower and defined $upper ) { $Test->diag("You need to define LOWER and UPPER bounds " . "to use number_between_ok" ); $Test->ok( 0, $name ); } elsif( $upper < $lower ) { $Test->diag( "Upper bound [$upper] is lower than lower bound [$lower]" ); $Test->ok( 0, $name ); } elsif( $number >= $lower and $number <= $upper ) { $Test->ok( 1, $name ); } else { $Test->diag( "Number [$number] was not within bounds\n", "\tExpected lower bound [$lower]\n", "\tExpected upper bound [$upper]\n" ); $Test->ok( 0, $name ); } } =item string_between_ok( SCALAR, LOWER, UPPER ) Ok if the string in SCALAR sorts between the string in LOWER and the string in UPPER, ASCII-betically. =cut sub string_between_ok($$$;$) { my $string = shift; my $lower = shift; my $upper = shift; my $name = shift || 'Scalar is in string range'; unless( defined $lower and defined $upper ) { $Test->diag("You need to define LOWER and UPPER bounds " . "to use string_between_ok" ); $Test->ok( 0, $name ); } elsif( $upper lt $lower ) { $Test->diag( "Upper bound [$upper] is lower than lower bound [$lower]" ); $Test->ok( 0, $name ); } elsif( $string ge $lower and $string le $upper ) { $Test->ok( 1, $name ); } else { $Test->diag( "String [$string] was not within bounds\n", "\tExpected lower bound [$lower]\n", "\tExpected upper bound [$upper]\n" ); $Test->ok( 0, $name ); } } =item readonly_ok( SCALAR ) Ok is the SCALAR is read-only. =cut sub readonly_ok($;$) { my $ok = not Scalar::Util::readonly( $_[0] ); my $name = $_[1] || 'Scalar is read-only'; $Test->diag("Expected readonly reference, got writeable one\n") unless $ok; $Test->ok( $ok, $name ); } =item ref_ok( SCALAR ) Ok if the SCALAR is a reference. =cut sub ref_ok($;$) { my $ok = ref $_[0]; my $name = $_[1] || 'Scalar is a reference'; $Test->diag("Expected reference, didn't get it\n") unless $ok; $Test->ok( $ok, $name ); } =item ref_type_ok( REF1, REF2 ) Ok if REF1 is the same reference type as REF2. =cut sub ref_type_ok($$;$) { my $ref1 = ref $_[0]; my $ref2 = ref $_[1]; my $ok = $ref1 eq $ref2; my $name = $_[2] || 'Scalar is right reference type'; $Test->diag("Expected references to match\n\tGot $ref1\n\t" . "Expected $ref2\n") unless $ok; ref $_[0] eq ref $_[1] ? $Test->ok( 1, $name ) : $Test->ok( 0, $name ); } =item strong_ok( SCALAR ) Ok is the SCALAR is not a weak reference. =cut sub strong_ok($;$) { my $ok = not Scalar::Util::isweak( $_[0] ); my $name = $_[1] || 'Scalar is not a weak reference'; $Test->diag("Expected strong reference, got weak one\n") unless $ok; $Test->ok( $ok, $name ); } =item tainted_ok( SCALAR ) Ok is the SCALAR is tainted. (Tainted values may seem like a not-Ok thing, but remember, when you use taint checking, you want Perl to taint data, so you should have a test to make sure it happens.) =cut sub tainted_ok($;$) { my $ok = Scalar::Util::tainted( $_[0] ); my $name = $_[1] || 'Scalar is tainted'; $Test->diag("Expected tainted data, got untainted data\n") unless $ok; $Test->ok( $ok, $name ); } =item untainted_ok( SCALAR ) Ok if the SCALAR is not tainted. =cut sub untainted_ok($;$) { my $ok = not Scalar::Util::tainted( $_[0] ); my $name = $_[1] || 'Scalar is not tainted'; $Test->diag("Expected untainted data, got tainted data\n") unless $ok; $Test->ok( $ok, $name ); } =item weak_ok( SCALAR ) Ok if the SCALAR is a weak reference. =cut sub weak_ok($;$) { my $ok = Scalar::Util::isweak( $_[0] ); my $name = $_[1] || 'Scalar is a weak reference'; $Test->diag("Expected weak reference, got stronge one\n") unless $ok; $Test->ok( $ok, $name ); } =back =head1 TO DO * add is_a_filehandle test * add is_vstring test =head1 SEE ALSO L, L, L, L, L, L =head1 SOURCE AVAILABILITY This source is in Github: https://github.com/briandfoy/test-data =head1 AUTHOR brian d foy, C<< >> =head1 COPYRIGHT AND LICENSE Copyright (c) 2002-2012 brian d foy. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut "The quick brown fox jumped over the lazy dog"; Test-Data-1.24/examples/README000644 000765 000024 00000000105 12261570571 016164 0ustar00brianstaff000000 000000 See the tests in the t/ directory for examples until I add some more.