init
This commit is contained in:
4
wcmtools/lib/Danga-Exceptions/MANIFEST
Executable file
4
wcmtools/lib/Danga-Exceptions/MANIFEST
Executable file
@@ -0,0 +1,4 @@
|
||||
lib/Danga/Exceptions.pm
|
||||
Makefile.PL
|
||||
MANIFEST
|
||||
t/basic.t
|
||||
11
wcmtools/lib/Danga-Exceptions/MANIFEST.SKIP
Executable file
11
wcmtools/lib/Danga-Exceptions/MANIFEST.SKIP
Executable file
@@ -0,0 +1,11 @@
|
||||
^#
|
||||
\bCVS\b
|
||||
^MANIFEST\.
|
||||
^Makefile$
|
||||
~$
|
||||
\.html$
|
||||
\.old$
|
||||
^blib/
|
||||
_blib$
|
||||
^MakeMaker-\d
|
||||
^\.exists
|
||||
33
wcmtools/lib/Danga-Exceptions/Makefile.PL
Executable file
33
wcmtools/lib/Danga-Exceptions/Makefile.PL
Executable file
@@ -0,0 +1,33 @@
|
||||
#!/usr/bin/perl
|
||||
#
|
||||
# Perl Makefile for Danga-Exceptions
|
||||
# $Id: Makefile.PL,v 1.1 2004/06/04 22:06:28 deveiant Exp $
|
||||
#
|
||||
# Invoke with 'perl Makefile.PL'
|
||||
#
|
||||
# See ExtUtils::MakeMaker (3) for more information on how to influence
|
||||
# the contents of the Makefile that is written
|
||||
#
|
||||
|
||||
use ExtUtils::MakeMaker;
|
||||
|
||||
WriteMakefile(
|
||||
NAME => 'Danga::Exceptions',
|
||||
VERSION_FROM => 'lib/Danga/Exceptions.pm', # finds $VERSION
|
||||
AUTHOR => 'Michael Granger <ged@danga.com>',
|
||||
ABSTRACT => 'Exception library',
|
||||
PREREQ_PM => {
|
||||
Scalar::Util => 0,
|
||||
Carp => 0,
|
||||
overload => 0,
|
||||
},
|
||||
dist => {
|
||||
CI => "cvs commit",
|
||||
RCS_LABEL => 'cvs tag RELEASE_$(VERSION_SYM)',
|
||||
SUFFIX => ".bz2",
|
||||
DIST_DEFAULT => 'all tardist',
|
||||
COMPRESS => "bzip2",
|
||||
},
|
||||
|
||||
);
|
||||
|
||||
1131
wcmtools/lib/Danga-Exceptions/lib/Danga/Exceptions.pm
Executable file
1131
wcmtools/lib/Danga-Exceptions/lib/Danga/Exceptions.pm
Executable file
File diff suppressed because it is too large
Load Diff
166
wcmtools/lib/Danga-Exceptions/t/basic.t
Executable file
166
wcmtools/lib/Danga-Exceptions/t/basic.t
Executable file
@@ -0,0 +1,166 @@
|
||||
#!/usr/bin/perl -w
|
||||
#
|
||||
# Test script for Danga::Exceptions
|
||||
# $Id: basic.t,v 1.1 2004/06/04 22:06:28 deveiant Exp $
|
||||
#
|
||||
# Before `make install' is performed this script should be runnable with
|
||||
# `make test'. After `make install' it should work as `perl 02_exceptions.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::AutoskipFailedSetup( 1 );
|
||||
|
||||
use Danga::Exceptions qw{:syntax};
|
||||
|
||||
### Imported-symbol test-generation function
|
||||
sub genTest {
|
||||
my $functionName = shift;
|
||||
return {
|
||||
name => "Import $functionName",
|
||||
test => sub {
|
||||
no strict 'refs';
|
||||
assertDefined *{"main::${functionName}"}{CODE},
|
||||
"$functionName() was not imported";
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
### Test functions for throwing
|
||||
sub simple_throw {
|
||||
throw Danga::Exception "Simple throw exception.";
|
||||
}
|
||||
sub methoderror_throw {
|
||||
throw Danga::MethodError "Method error.";
|
||||
}
|
||||
|
||||
### Build tests for imported syntax functions
|
||||
my @synFuncTests = map { s{^&}{}; genTest $_ } @{$Danga::Exception::EXPORT_TAGS{syntax}};
|
||||
|
||||
|
||||
### Main test suite (in the order they're run)
|
||||
my @testSuite = (
|
||||
|
||||
# Test for imported symbols first
|
||||
@synFuncTests,
|
||||
|
||||
# try + throw + catch
|
||||
{
|
||||
name => 'Simple throw',
|
||||
test => sub {
|
||||
try {
|
||||
simple_throw();
|
||||
} catch Danga::Exception with {
|
||||
my $except = shift;
|
||||
assertInstanceOf 'Danga::Exception', $except;
|
||||
};
|
||||
},
|
||||
},
|
||||
|
||||
# try + throw subclass + catch general class
|
||||
{
|
||||
name => 'Subclass throw - general handler',
|
||||
test => sub {
|
||||
try {
|
||||
methoderror_throw();
|
||||
} catch Danga::Exception with {
|
||||
my $except = shift;
|
||||
assertInstanceOf 'Danga::MethodError', $except;
|
||||
};
|
||||
},
|
||||
},
|
||||
|
||||
# try + throw subclass + catch subclass + catch general class(skipped)
|
||||
{
|
||||
name => 'Subclass throw - specific and general handlers',
|
||||
test => sub {
|
||||
my ( $sawSpecificHandler, $sawGeneralHandler );
|
||||
|
||||
try {
|
||||
methoderror_throw();
|
||||
} catch Danga::MethodError with {
|
||||
$sawSpecificHandler = 1;
|
||||
} catch Danga::Exception with {
|
||||
$sawGeneralHandler = 1;
|
||||
};
|
||||
|
||||
assertNot $sawGeneralHandler, "Saw general handler with preceeding specific handler";
|
||||
assert $sawSpecificHandler, "Didn't see specific handler";
|
||||
},
|
||||
},
|
||||
|
||||
# try + throw subclass + catch subclass + rethrow + catch general class
|
||||
{
|
||||
name => 'Subclass throw - specific handler with keeptrying',
|
||||
test => sub {
|
||||
my ( $sawSpecificHandler, $sawGeneralHandler );
|
||||
|
||||
try {
|
||||
methoderror_throw();
|
||||
} catch Danga::MethodError with {
|
||||
my ( $e, $keepTrying ) = @_;
|
||||
assertRef 'SCALAR', $keepTrying;
|
||||
$sawSpecificHandler = 1;
|
||||
$$keepTrying = 1;
|
||||
} catch Danga::Exception with {
|
||||
$sawGeneralHandler = 1;
|
||||
};
|
||||
|
||||
assert $sawGeneralHandler,
|
||||
"Didn't see general handler after setting \$keeptrying from ".
|
||||
"preceeding specific handler";
|
||||
assert $sawSpecificHandler,
|
||||
"Didn't see specific handler";
|
||||
},
|
||||
},
|
||||
|
||||
# try + catch + with + otherwise
|
||||
{
|
||||
name => "Throw with otherwise",
|
||||
test => sub {
|
||||
my ( $seenCatch, $seenOtherwise );
|
||||
try {
|
||||
simple_throw();
|
||||
} catch Danga::MethodError with {
|
||||
$seenCatch = 1;
|
||||
} otherwise {
|
||||
$seenOtherwise = 1;
|
||||
};
|
||||
|
||||
assert $seenOtherwise;
|
||||
assertNot $seenCatch;
|
||||
},
|
||||
},
|
||||
|
||||
|
||||
### finally
|
||||
{
|
||||
name => "Throw with finally",
|
||||
test => sub {
|
||||
my ( $sawHandler, $sawFinally );
|
||||
|
||||
try {
|
||||
simple_throw();
|
||||
} catch Danga::Exception with {
|
||||
$sawHandler = 1;
|
||||
} finally {
|
||||
$sawFinally = 1;
|
||||
};
|
||||
|
||||
assert $sawHandler, "Didn't see handler";
|
||||
assert $sawFinally, "Didn't see finally clause.";
|
||||
},
|
||||
},
|
||||
|
||||
|
||||
);
|
||||
|
||||
runTests( @testSuite );
|
||||
|
||||
Reference in New Issue
Block a user