Imported Upstream version 1.21

This commit is contained in:
Mario Fetka
2017-09-15 16:12:49 +02:00
commit 8879c156fb
17 changed files with 3134 additions and 0 deletions

34
t/00_require.t Normal file
View File

@@ -0,0 +1,34 @@
#!/usr/bin/perl
#
# Test script for Test::SimpleUnit (require)
# $Id: 00_require.t,v 1.2 2002/03/29 23:41:49 deveiant Exp $
#
# Before `make install' is performed this script should be runnable with
# `make test'. After `make install' it should work as `perl test.pl'
#
# Please do not commit any changes you make to the module without a
# successful 'make test'!
#
package main;
use strict;
BEGIN { $| = 1; use vars qw{$LoadedOkay} }
END { print "1..1\nnot ok 1\n" unless $LoadedOkay; }
### Load up the test framework
require Test::SimpleUnit;
### Test suite (in the order they're run)
my @testSuite = (
{
name => 'Require',
test => sub {
$LoadedOkay = 1;
},
},
);
Test::SimpleUnit::runTests( @testSuite );

36
t/01_importAll.t Normal file
View File

@@ -0,0 +1,36 @@
#!/usr/bin/perl
#
# Test script for Test::SimpleUnit (import functions)
# $Id: 01_importAll.t,v 1.2 2002/03/29 23:41:49 deveiant Exp $
#
# Before `make install' is performed this script should be runnable with
# `make test'. After `make install' it should work as `perl t/01_import.t'
#
# Please do not commit any changes you make to the module without a
# successful 'make test'!
#
package main;
use strict;
BEGIN { $| = 1; }
### Load up the test framework
use Test::SimpleUnit qw{:functions};
sub genTest {
my $functionName = shift;
return {
name => $functionName,
test => sub {
no strict 'refs';
die "$functionName() was not imported" unless defined *{"main::${functionName}"}{CODE};
},
};
}
### Generate a test suite out of the list of exported functions for the
### 'functions' tag
my @testSuite = map { s{^&}{}; genTest $_ } @{$Test::SimpleUnit::EXPORT_TAGS{functions}};
Test::SimpleUnit::runTests( @testSuite );

36
t/02_importAsserts.t Normal file
View File

@@ -0,0 +1,36 @@
#!/usr/bin/perl
#
# Test script for Test::SimpleUnit (import functions)
# $Id: 02_importAsserts.t,v 1.3 2002/03/29 23:41:49 deveiant Exp $
#
# Before `make install' is performed this script should be runnable with
# `make test'. After `make install' it should work as `perl t/01_import.t'
#
# Please do not commit any changes you make to the module without a
# successful 'make test'!
#
package main;
use strict;
BEGIN { $| = 1; }
### Load up the test framework
use Test::SimpleUnit qw{:asserts};
sub genTest {
my $functionName = shift;
return {
name => $functionName,
test => sub {
no strict 'refs';
die "$functionName() was not imported" unless defined *{"main::${functionName}"}{CODE};
},
};
}
### Generate a test suite out of the list of exported functions for the
### 'functions' tag
my @testSuite = map { s{^&}{}; genTest $_ } @{$Test::SimpleUnit::EXPORT_TAGS{asserts}};
Test::SimpleUnit::runTests( @testSuite );

36
t/03_importTfuncs.t Normal file
View File

@@ -0,0 +1,36 @@
#!/usr/bin/perl
#
# Test script for Test::SimpleUnit (import functions)
# $Id: 03_importTfuncs.t,v 1.2 2002/03/29 23:41:49 deveiant Exp $
#
# Before `make install' is performed this script should be runnable with
# `make test'. After `make install' it should work as `perl t/01_import.t'
#
# Please do not commit any changes you make to the module without a
# successful 'make test'!
#
package main;
use strict;
BEGIN { $| = 1; }
### Load up the test framework
use Test::SimpleUnit qw{:testFunctions};
sub genTest {
my $functionName = shift;
return {
name => $functionName,
test => sub {
no strict 'refs';
die "$functionName() was not imported" unless defined *{"main::${functionName}"}{CODE};
},
};
}
### Generate a test suite out of the list of exported functions for the
### 'functions' tag
my @testSuite = map { s{^&}{}; genTest $_ } @{$Test::SimpleUnit::EXPORT_TAGS{testFunctions}};
Test::SimpleUnit::runTests( @testSuite );

36
t/04_importSkips.t Normal file
View File

@@ -0,0 +1,36 @@
#!/usr/bin/perl
#
# Test script for Test::SimpleUnit (import skip functions)
# $Id: 04_importSkips.t,v 1.2 2002/03/29 23:41:49 deveiant Exp $
#
# Before `make install' is performed this script should be runnable with
# `make test'. After `make install' it should work as `perl t/01_import.t'
#
# Please do not commit any changes you make to the module without a
# successful 'make test'!
#
package main;
use strict;
BEGIN { $| = 1; }
### Load up the test framework
use Test::SimpleUnit qw{:skips};
sub genTest {
my $functionName = shift;
return {
name => $functionName,
test => sub {
no strict 'refs';
die "$functionName() was not imported" unless defined *{"main::${functionName}"}{CODE};
},
};
}
### Generate a test suite out of the list of exported functions for the
### 'functions' tag
my @testSuite = map { s{^&}{}; genTest $_ } @{$Test::SimpleUnit::EXPORT_TAGS{skips}};
Test::SimpleUnit::runTests( @testSuite );

36
t/05_importTestData.t Normal file
View File

@@ -0,0 +1,36 @@
#!/usr/bin/perl
#
# Test script for Test::SimpleUnit
# $Id: 05_importTestData.t,v 1.1 2003/01/15 20:46:44 deveiant Exp $
#
# Before `make install' is performed this script should be runnable with
# `make test'. After `make install' it should work as `perl 05_importTestData.t'
#
# Please do not commit any changes you make to the module without a
# successful 'make test'!
#
package main;
use strict;
BEGIN { $| = 1; }
### Load up the test framework
use Test::SimpleUnit qw{:testdata};
sub genTest {
my $functionName = shift;
return {
name => $functionName,
test => sub {
no strict 'refs';
die "$functionName() was not imported" unless defined *{"main::${functionName}"}{CODE};
},
};
}
### Generate a test suite out of the list of exported functions for the
### 'functions' tag
my @testSuite = map { s{^&}{}; genTest $_ } @{$Test::SimpleUnit::EXPORT_TAGS{testdata}};
Test::SimpleUnit::runTests( @testSuite );

482
t/10_asserts.t Normal file
View File

@@ -0,0 +1,482 @@
#!/usr/bin/perl
#
# Test script for Test::SimpleUnit (import functions)
# $Id: 10_asserts.t,v 1.4 2002/04/08 18:50:24 deveiant Exp $
#
# Before `make install' is performed this script should be runnable with
# `make test'. After `make install' it should work as `perl t/01_import.t'
#
# Please do not commit any changes you make to the module without a
# successful 'make test'!
#
# Packages for testing OO asserts
package ClassA;
sub new {return bless {}, $_[0]}
package ClassB;
use base qw{ClassA};
package ClassC;
use base qw{ClassB};
# Main testing package
package main;
use strict;
BEGIN { $| = 1; }
### Load up the test framework
use Test::SimpleUnit qw{:asserts};
my @testSuite = (
# Test the basic assert() function
{
name => 'Assert',
test => sub {
# Assert( true )
eval { assert(1); };
die "Failed assert(1): $@" if $@;
# Assert( false )
eval { assert(0); };
die "assert(0) unexpectedly succeeded." unless $@;
die "Unexpected error message for assert(0): $@ (expected '0')"
unless "$@" =~ m{0};
# Assert( false ) with message
eval { assert(0, "message test") };
die "assert(0,msg) unexpectedly succeeded." unless $@;
die "Unexpected error message for assert(0): $@ (expected 'message test')"
unless "$@" =~ m{message test};
},
},
# Test assertNot()
{
name => 'AssertNot',
test => sub {
# assertNot( 0 )
eval { assertNot(0); };
die "Failed assertNot(0): $@" if $@;
# assertNot( "" )
eval { assertNot(""); };
die "Failed assertNot(\"\"): $@" if $@;
# assertNot( undef )
eval { assertNot(undef); };
die "Failed assertNot(undef): $@" if $@;
# assertNot( 1 )
eval { assertNot(1); };
die "assertNot(1) unexpectedly succeeded." unless $@;
die "Unexpected error message for assertNot(1): $@ (expected 'Expected a false value, got \"1\"')"
unless "$@" =~ m{Expected a false value, got '1'};
# AssertNot( false ) with message
eval { assertNot(1, "message test") };
die "assertNot(1,msg) unexpectedly succeeded." unless $@;
die "Unexpected error message for assertNot(0): $@ (expected 'message test')"
unless "$@" =~ m{message test};
},
},
# Test assertDefined()
{
name => 'AssertDefined',
test => sub {
# assertDefined( 0 )
eval { assertDefined(0); };
die "Failed assertDefined(0): $@" if $@;
# assertDefined( "" )
eval { assertDefined(""); };
die "Failed assertDefined(\"\"): $@" if $@;
# assertDefined( undef )
eval { assertDefined(undef); };
die "assertDefined(undef) unexpectedly succeeded." unless $@;
die "Unexpected error message for assertDefined(undef): $@ ",
"(expected 'Expected a defined value, got an undef')"
unless "$@" =~ m{Expected a defined value, got an undef};
# AssertDefined( undef ) with message
eval { assertDefined(undef, "message test") };
die "assertDefined(undef,msg) unexpectedly succeeded." unless $@;
die "Unexpected error message for assertDefined(undef,msg): $@ ",
"(expected 'message test')"
unless "$@" =~ m{message test};
},
},
# Test assertUndef()
{
name => 'AssertUndef',
test => sub {
# assertUndef( undef )
eval { assertUndef(undef); };
die "Failed assertUndef(undef): $@" if $@;
# assertUndef( undef )
eval { assertUndef(1); };
die "assertUndef(1) unexpectedly succeeded." unless $@;
die "Unexpected error message for assertUndef(1): $@ ",
"(expected 'Expected an undefined value, got '1'')"
unless "$@" =~ m{Expected an undefined value, got '1'};
# AssertUndef( undef ) with message
eval { assertUndef(1, "message test") };
die "assertUndef(1,msg) unexpectedly succeeded." unless $@;
die "Unexpected error message for assertUndef(1,msg): $@ ",
"(expected 'message test')"
unless "$@" =~ m{message test};
},
},
# Test assertException()
{
name => 'AssertException',
test => sub {
my $res;
# assertException { die "test" }
$res = eval { assertException {die "test"}; };
die "Failed assertException {die \"test\"}: $@" if $@;
assert( $res );
undef $res;
# assertException { 1 }
eval { assertException {1} };
die "assertException unexpectedly succeeded" unless $@;
die "Unexpected error message for assertException {1}: $@ ",
"(expected 'No exception raised.')"
unless "$@" =~ m{No exception raised\.};
# assertException { 1 }, $msg
eval { assertException {1} "Ack! No exception?"; };
die "assertException unexpectedly succeeded" unless $@;
die "Unexpected error message for assertException {1}: $@ ",
"(expected 'Ack! No exception?')"
unless "$@" =~ m{Ack! No exception\?};
},
},
# Test assertExceptionType()
{
name => 'AssertExceptionType',
test => sub {
# assertExceptionType { die "test" }
eval { assertExceptionType {die bless ["test"], 'test'} 'test'; };
die "Failed assertExceptionType {die bless [\"test\"], 'test'} 'test': $@" if $@;
# assertExceptionType { 1 }
eval { assertExceptionType {1} 'any' };
die "assertExceptionType unexpectedly succeeded" unless $@;
die "Unexpected error message for assertExceptionType {1} 'any': $@ ",
"(expected 'Expected an exception of type 'any', but none was raised. at ",
"blib/lib/Test/SimpleUnit.pm line...')"
unless "$@" =~ m{Expected an exception of type 'any', but none was raised\.};
# assertExceptionType { 1 }, $msg
eval { assertExceptionType {1} 'any', "Ack! No exception?"; };
die "assertExceptionType unexpectedly succeeded" unless $@;
die "Unexpected error message for assertExceptionType {1} 'any', \"Ack! No exception?\": $@ ",
"(expected 'Ack! No exception?')"
unless "$@" =~ m{Ack! No exception\?};
},
},
# Test assertExceptionMatch()
{
name => 'AssertExceptionMatches',
test => sub {
# Match a die()
eval { assertExceptionMatches {die "Just testing"} qr{test}i; };
die "Failed assertExceptionMatches {die \"Just testing\"} qr{test}i: $@" if $@;
# assertExceptionMatches { 1 } 'any'
eval { assertExceptionMatches {1} qr{any} };
die "assertExceptionMatches unexpectedly succeeded" unless $@;
die "Unexpected error message for assertExceptionMatches {1} qr{any}: $@ ",
"(expected 'Expected an exception which matched /(?-xism:any)/, but none ",
"was raised.')"
unless "$@" =~ m{Expected an exception which matched \Q/(?-xism:any)/\E, but none was raised\.};
# assertExceptionMatches { 1 } 'any', $msg
eval { assertExceptionMatches {1} 'any', "Ack! No exception?"; };
die "assertExceptionMatches unexpectedly succeeded" unless $@;
die "Unexpected error message for assertExceptionMatches {1} 'any', \"Ack! No exception?\": $@ ",
"(expected 'Ack! No exception?')"
unless "$@" =~ m{Ack! No exception\?};
},
},
# Test assertNoException()
{
name => 'AssertNoException',
test => sub {
my $res;
my $file = __FILE__;
my $line;
# assertNoException { 1 }
$res = eval { assertNoException {1}; };
die "Failed assertNoException {1}: $@" if $@;
assert( $res );
undef $res;
# assertNoException { die "test" }
$line = __LINE__ + 1;
eval { assertNoException {die "test"} };
die "assertNoException unexpectedly succeeded" unless $@;
die "Unexpected error message for assertNoException {die \"test\"}: $@ ",
"(expected 'Exception raised: test at $file line $line')"
unless "$@" =~ m{Exception raised: test at $file line $line};
# assertNoException { die "test" }, $msg
eval { assertNoException {die "test"} "Ack! Exception raised!"; };
die "assertNoException unexpectedly succeeded" unless $@;
die "Unexpected error message for assertNoException {die \"test\"}: $@ ",
"(expected 'Ack! Exception raised!')"
unless "$@" =~ m{Ack! Exception raised!};
},
},
# Test assertEquals()
{
name => 'AssertEquals',
test => sub {
my $res;
# assertEquals( 1, 1 )
assertNoException { $res = assertEquals( 1, 1 ) };
assert( $res );
undef $res;
# assertEquals( 1, "1" )
assertNoException { $res = assertEquals( 1, "1" ) };
assert( $res );
undef $res;
# assertEquals( "this", "this" )
assertNoException { $res = assertEquals( "this", "this" ) };
assert( $res );
undef $res;
# assertEquals( undef, undef )
assertNoException { $res = assertEquals( undef, undef ) };
assert( $res );
undef $res;
# assertEquals( 1, 2 )
assertExceptionMatches { $res = assertEquals(1, 2) } qr{Wanted '1', got '2' instead};
assertNot( $res );
undef $res;
# assertEquals( 1, 1.1 )
assertExceptionMatches { $res = assertEquals(1, 1.1) } qr{Wanted '1', got '1.1' instead};
assertNot( $res );
undef $res;
},
},
# Test assertMatches()
{
name => 'AssertMatches',
test => sub {
my $res;
# assertMatches( '\d+', 1 )
assertNoException { $res = assertMatches( '\d+', 1 ) };
assert( $res );
undef $res;
# assertMatches( qr{\d+}, 1 )
assertNoException { $res = assertMatches( qr{\d+}, 1 ) };
assert( $res );
undef $res;
# assertMatches( qr{\s+}, " 1" )
assertNoException { $res = assertMatches( qr{\s+}, " 1" ) };
assert( $res );
undef $res;
# assertMatches( qr{\s+}, 1 )
assertExceptionMatches {
$res = assertMatches( qr{\s+}, 1 )
} qr{Tested value '1' did not match wanted regex '\Q(?-xism:\s+)\E};
assertNot( $res );
undef $res;
},
},
# Test assertRef()
{
name => 'AssertRef',
test => sub {
my $res;
assertNoException { $res = assertRef('HASH', {}) };
assert( $res );
undef $res;
assertNoException { $res = assertRef('GLOB', \*STDIN) };
assert( $res );
undef $res;
assertNoException { $res = assertRef('ARRAY', []) };
assert( $res );
undef $res;
assertNoException { $res = assertRef('SCALAR', \"something") };
assert( $res );
undef $res;
assertNoException { $res = assertRef('ClassA', ClassA->new) };
assert( $res );
undef $res;
assertException { $res = assertRef('HASH', 'something') };
assertMatches( qr{Expected a HASH value, got a scalar}, $@ );
assertNot( $res );
undef $res;
assertException { $res = assertRef('HASH', undef) };
assertMatches( qr{Expected a HASH value, got a undefined value}, $@ );
assertNot( $res );
undef $res;
assertException { $res = assertRef('HASH', []) };
assertMatches( qr{Expected a HASH value, got a ARRAY}, $@ );
assertNot( $res );
undef $res;
assertException { $res = assertRef('ClassA', []) };
assertMatches( qr{Expected a ClassA value, got a ARRAY}, $@ );
assertNot( $res );
undef $res;
},
},
# Test assertInstanceOf()
{
name => 'AssertInstanceOf',
test => sub {
my ( $res, $aInstance, $bInstance, $cInstance );
$aInstance = ClassA->new;
$bInstance = ClassB->new;
$cInstance = ClassC->new;
# aInstance should be only a ClassA object...
assertException { assertInstanceOf('ClassB', $aInstance) };
assertMatches qr{Expected an instance of 'ClassB', got an instance of 'ClassA'}, $@;
assertException { assertInstanceOf('ClassC', $aInstance) };
assertMatches qr{Expected an instance of 'ClassC', got an instance of 'ClassA'}, $@;
assertNoException { assertInstanceOf('ClassA', $aInstance) };
# bInstance should be only a ClassB object
assertException { assertInstanceOf('ClassA', $bInstance) };
assertMatches qr{Expected an instance of 'ClassA', got an instance of 'ClassB'}, $@;
assertException { assertInstanceOf('ClassC', $bInstance) };
assertMatches qr{Expected an instance of 'ClassC', got an instance of 'ClassB'}, $@;
assertNoException { assertInstanceOf('ClassB', $bInstance) };
# cInstance should be only a ClassC object
assertException { assertInstanceOf('ClassA', $cInstance) };
assertMatches qr{Expected an instance of 'ClassA', got an instance of 'ClassC'}, $@;
assertException { assertInstanceOf('ClassB', $cInstance) };
assertMatches qr{Expected an instance of 'ClassB', got an instance of 'ClassC'}, $@;
assertNoException { assertInstanceOf('ClassC', $cInstance) };
# A simple scalar shouldn't even make the ->isa() test
assertException { assertInstanceOf('ClassA', "something") };
assertMatches( qr{Expected an instance of 'ClassA', got a non-object \Q('something')\E}, $@ );
# Neither should a plain (unblessed) reference
assertException { assertInstanceOf('ClassA', []) };
assertMatches( qr{Expected an instance of 'ClassA', got a non-object \('ARRAY\(0x\w+\)'\)}, $@ );
},
},
# Test assertKindOf()
{
name => 'AssertKindOf',
test => sub {
my ( $res, $aInstance, $bInstance, $cInstance );
$aInstance = ClassA->new;
$bInstance = ClassB->new;
$cInstance = ClassC->new;
# aInstance should be an ClassA object...
assertNoException { $res = assertKindOf('ClassA', $aInstance) };
assert( $res );
undef $res;
# bInstance should be both a ClassA and a ClassB object
assertNoException { $res = assertKindOf('ClassA', $bInstance) };
assert( $res );
undef $res;
assertNoException { $res = assertKindOf('ClassB', $bInstance) };
assert( $res );
undef $res;
# cInstance should be all three
assertNoException { $res = assertKindOf('ClassA', $cInstance) };
assert( $res );
undef $res;
assertNoException { $res = assertKindOf('ClassB', $cInstance) };
assert( $res );
undef $res;
assertNoException { $res = assertKindOf('ClassC', $cInstance) };
assert( $res );
undef $res;
# But aInstance should be neither a B nor a C
assertException { $res = assertKindOf('ClassB', $aInstance) };
assertMatches( qr{Expected an instance of 'ClassB' or a subclass, got an instance of 'ClassA'}, $@ );
assertNot( $res );
undef $res;
assertException { $res = assertKindOf('ClassC', $aInstance) };
assertMatches( qr{Expected an instance of 'ClassC' or a subclass, got an instance of 'ClassA'}, $@ );
assertNot( $res );
undef $res;
# Neither should bInstance be a C
assertException { $res = assertKindOf('ClassC', $bInstance) };
assertMatches( qr{Expected an instance of 'ClassC' or a subclass, got an instance of 'ClassB'}, $@ );
assertNot( $res );
undef $res;
# A simple scalar shouldn't even make the ->isa() test
assertException { $res = assertKindOf('ClassA', "something") };
assertMatches( qr{Expected an instance of 'ClassA' or a subclass, got a non-object \Q('something')\E}, $@ );
assertNot( $res );
undef $res;
# Neither should a plain (unblessed) reference
assertException { $res = assertKindOf('ClassA', []) };
assertMatches( qr{Expected an instance of 'ClassA' or a subclass, got a non-object \('ARRAY\(0x\w+\)'\)}, $@ );
assertNot( $res );
undef $res;
},
},
);
Test::SimpleUnit::runTests( @testSuite );

97
t/11_skips.t Normal file
View File

@@ -0,0 +1,97 @@
#!/usr/bin/perl
#
# Test script for Test::SimpleUnit
# $Id: 11_skips.t,v 1.3 2002/04/15 19:54:35 deveiant Exp $
#
# Before `make install' is performed this script should be runnable with
# `make test'. After `make install' it should work as `perl 05_skip.t'
#
# Please do not commit any changes you make to the module without a
# successful 'make test'!
#
package main;
use strict;
BEGIN { $| = 1; }
### Load up the test framework
use Test::SimpleUnit qw{:functions};
### Test suite (in the order they're run)
my @testSuite = (
{
name => 'Autoskip setting',
test => sub {
# Backwards compat
assertNoException { Test::SimpleUnit->AutoskipFailedSetup(1) };
assert Test::SimpleUnit::AutoskipFailedSetup();
assertNoException { Test::SimpleUnit::AutoskipFailedSetup(0) };
assertNot Test::SimpleUnit::AutoskipFailedSetup();
},
},
{
name => 'Skip one (no message)',
test => sub {
eval { skipOne };
assertInstanceOf 'SKIPONE', $@;
},
},
{
name => 'Skip one (with message)',
test => sub {
eval { skipOne "Testing" };
assertInstanceOf 'SKIPONE', $@;
assertEquals "Testing", ${$@};
},
},
{
name => 'Real skip one',
test => sub {
skipOne "Passed.";
fail "Test wasn't skipped.";
},
},
{
name => 'Skip all (no message)',
test => sub {
eval { skipAll };
assertInstanceOf 'SKIPALL', $@;
},
},
{
name => 'Skip all (with message)',
test => sub {
eval { skipAll "Testing" };
assertInstanceOf 'SKIPALL', $@;
assertEquals "Testing", ${$@};
},
},
{
name => 'Real skip all',
test => sub {
skipAll "Passed.";
fail "Immediate test body wasn't skipped by skipAll.";
},
},
{
name => 'Should be skipped',
test => sub {
fail "Following test body wasn't skipped by skipAll.";
},
},
);
runTests( @testSuite );

87
t/12_testdata.t Normal file
View File

@@ -0,0 +1,87 @@
#!/usr/bin/perl
#
# Test script for Test::SimpleUnit
# $Id: 12_testdata.t,v 1.1 2003/01/15 20:46:44 deveiant Exp $
#
# Before `make install' is performed this script should be runnable with
# `make test'. After `make install' it should work as `perl 10_testdata.t'
#
# Please do not commit any changes you make to the module without a
# successful 'make test'!
#
package main;
use strict;
BEGIN { $| = 1; }
### Load up the test framework
use Test::SimpleUnit qw{:functions};
my (
$filename,
%testData,
);
### Test suite (in the order they're run)
my @testSuite = (
### Setup/Teardown functions
{
name => 'setup',
func => sub {
$filename = "12testdata.$$";
%testData = (
some => 'data',
for => "testing",
complex => [qw{an arrayref }],
hoh => {
more => 'keys',
and => 'vals',
another => {},
},
);
},
},
{
name => 'teardown',
func => sub {
$filename = '';
%testData = ();
},
},
### Save the test data
{
name => 'savedata',
test => sub {
Test::SimpleUnit::Debug( 1 );
assertNoException {
saveTestData( $filename, %testData );
};
assert -f $filename;
},
},
### Load the test data back up and compare it with the original
{
name => 'loaddata',
test => sub {
my $datahash;
Test::SimpleUnit::Debug( 1 );
assertNoException {
$datahash = loadTestData( $filename );
};
assertRef 'HASH', $datahash;
assertEquals \%testData, $datahash;
},
},
);
runTests( @testSuite );

230
t/15_setupteardown.t Normal file
View File

@@ -0,0 +1,230 @@
#!/usr/bin/perl
#
# Test script for Test::SimpleUnit
# $Id: 15_setupteardown.t,v 1.4 2003/01/15 20:48:07 deveiant Exp $
#
# Before `make install' is performed this script should be runnable with
# `make test'. After `make install' it should work as `perl 07_setupteardown.t'
#
# Please do not commit any changes you make to the module without a
# successful 'make test'!
#
package main;
use strict;
BEGIN { $| = 1; }
### Load up the test framework
use Test::SimpleUnit qw{:functions};
#Test::SimpleUnit::Debug( 1 );
my %setupRuns = ();
my %teardownRuns = ();
### Test suite (in the order they're run)
my @testSuite = (
### Plain setup
# First setup function
{
name => 'setup',
func => sub {
$setupRuns{first}++;
},
},
# Test to make sure the setup ran
{
name => 'test first setup',
test => sub {
assertEquals 1, $setupRuns{first};
},
},
### Overridden setup
# Override the first setup with this, the second one
{
name => 'setup',
test => sub {
$setupRuns{second}++;
},
},
# Test to be sure the two setup functions have run exactly once each
{
name => 'test second setup',
test => sub {
assertEquals 1, $setupRuns{first};
assertEquals 1, $setupRuns{second};
},
},
# Test to be sure the first setup has still only run once, but that the
# second has now run twice
{
name => 'test second setup again',
test => sub {
assertEquals 1, $setupRuns{first};
assertEquals 2, $setupRuns{second};
},
},
### Assure all setups run at least once
# Override the second setup with this, the third one, but then clobber this
# one with a fourth. This one should only be run once.
{
name => 'setup',
test => sub {
$setupRuns{third}++;
},
},
# Override the third setup with this, the fourth one.
{
name => 'setup',
test => sub {
$setupRuns{fourth}++;
},
},
# Test to be sure the first has now run once, the second twice, the third
# once, and the fourth one once.
{
name => 'test third and fourth setup (1st run)',
test => sub {
assertEquals 1, $setupRuns{first};
assertEquals 2, $setupRuns{second};
assertEquals 1, $setupRuns{third};
assertEquals 1, $setupRuns{fourth};
},
},
# Test again to be sure the first has now run once, the second twice, the
# third still only once, and the fourth two times.
{
name => 'test third and fourth setup (2nd run)',
test => sub {
assertEquals 1, $setupRuns{first};
assertEquals 2, $setupRuns{second};
assertEquals 1, $setupRuns{third};
assertEquals 2, $setupRuns{fourth};
},
},
### Now do the same thing for teardown functions
# First teardown function
{
name => 'teardown',
func => sub {
$teardownRuns{first}++;
},
},
# Test to make sure the teardown hasn't yet run, but will in the second test.
{
name => 'test first teardown (pre-run)',
test => sub {
assertNot exists $teardownRuns{first};
},
},
# Test to make sure the teardown hasn't yet run, but will in the second test.
{
name => 'test first teardown (post-run)',
test => sub {
assertEquals 1, $teardownRuns{first};
},
},
### Overridden teardown
# Override the first teardown with this, the second one
{
name => 'teardown',
test => sub {
$teardownRuns{second}++;
},
},
# Test the second teardown, pre-run
{
name => 'test second teardown',
test => sub {
assertEquals 2, $teardownRuns{first};
assertNot exists $teardownRuns{second};
},
},
# Test the second teardown, post-run
{
name => 'test second teardown',
test => sub {
assertEquals 2, $teardownRuns{first};
assertEquals 1, $teardownRuns{second};
},
},
### Assure all teardowns run at least once
# Override the second teardown with this, the third one, but then clobber this
# one with a fourth. This one should then only be run once.
{
name => 'teardown',
test => sub {
$teardownRuns{third}++;
},
},
# Override the third teardown with this, the fourth one.
{
name => 'teardown',
test => sub {
$teardownRuns{fourth}++;
},
},
# Bogus test for the third and fourth teardown, pre-run
{
name => 'test third and fourth teardown (pre-run)',
test => sub { 1 },
},
# Test to be sure the first has now run once, the second twice, and the
# third and fourth once each.
{
name => 'test third and fourth teardown (1st run)',
test => sub {
assertEquals 2, $teardownRuns{first};
assertEquals 2, $teardownRuns{second};
assertEquals 1, $teardownRuns{third};
assertEquals 1, $teardownRuns{fourth};
},
},
# Now make sure the third test has still only run once, but the fourth
# should have run a second time.
{
name => 'test third and fourth teardown (2nd run)',
test => sub {
assertEquals 2, $teardownRuns{first};
assertEquals 2, $teardownRuns{second};
assertEquals 1, $teardownRuns{third};
assertEquals 2, $teardownRuns{fourth};
},
},
);
runTests( @testSuite );

40
t/20_emptysuite.t Normal file
View File

@@ -0,0 +1,40 @@
#!/usr/bin/perl
#
# Test script for Test::SimpleUnit
# $Id: 20_emptysuite.t,v 1.1 2002/04/23 22:01:34 deveiant Exp $
#
# Before `make install' is performed this script should be runnable with
# `make test'. After `make install' it should work as `perl 08_emptysuite.t'
#
# Please do not commit any changes you make to the module without a
# successful 'make test'!
#
package main;
use strict;
BEGIN { $| = 1; }
### Load up the test framework
use Test::SimpleUnit qw{:functions};
### Test an empty test suite -- used to fail because the setup and teardown
### tests are spliced out. Should now just skip gracefully.
my @testSuite = (
{
name => 'setup',
func => sub {
},
},
{
name => 'teardown',
func => sub {
},
},
);
runTests( @testSuite );

60
t/30_bugs.t Normal file
View File

@@ -0,0 +1,60 @@
#!/usr/bin/perl
#
# Test script for fixed bugs that don't need their own suite
# $Id: 30_bugs.t,v 1.1 2002/05/14 02:59:02 deveiant Exp $
#
# Before `make install' is performed this script should be runnable with
# `make test'. After `make install' it should work as `perl 09_bugs.t'
#
# Please do not commit any changes you make to the module without a
# successful 'make test'!
#
package main;
use strict;
BEGIN { $| = 1; }
### Load up the test framework
use Test::SimpleUnit qw{:functions};
use IO::Handle;
use IO::File;
#$Test::SimpleUnit::Debug = 1;
# Get a reference to stdout so we can switch it off for recursive tests
my $Stdout = IO::Handle->new_from_fd( fileno STDOUT, 'w' )
or die "Ack: STDOUT doesn't exist";
my $DummyIO = new IO::File '/dev/null', 'w';
### Test suite (in the order they're run)
my @testSuite = (
# Can't use string ("") as a subroutine ref while "strict refs" in use at
# /usr/lib/perl5/site_perl/5.6.1/Test/SimpleUnit.pm line 665.
{
name => 'Missing "test" key-val pair',
test => sub {
assertNoException {
Test::SimpleUnit::OutputHandle( $DummyIO );
runTests({ name => 'subtest' });
Test::SimpleUnit::OutputHandle();
};
},
},
# Error related to the above one: Test isn't a coderef.
{
name => 'non-coderef value in "test" key-val pair',
test => sub {
assertNoException {
Test::SimpleUnit::OutputHandle( $DummyIO );
runTests({ name => 'subtest', test => {} });
Test::SimpleUnit::OutputHandle();
};
},
},
);
runTests( @testSuite );