So, I've been merrily hacking away on PerlUnit trying to make things a
little easier to follow. This means I'm attempting to make things use
some standard CPAN modules, and also eliminating stuff like backtraces
which tend to supply a whole load of misleading information.

Check out the new Test::Unit::TestCase::run_bare. There's a small
amount of ugliness to do with reblessing an exception and rethrowing,
but everything else is cute...

sub run_bare {
    my $self = shift;
    print ref($self) . "::run_bare() called\n" if DEBUG;
    try {
        $self->set_up();
        $self->run_test;
    }
    catch Error::Simple with {
        my $E = shift;
        bless $E, 'Test::Unit::ExceptionError';
        $E->add_object($self);
        $E->throw;
    }
    finally {
        $self->tear_down;
    };
}

Note that, by using Error, we're hopefully reducing clashes with
objects that use Error themselves. (Design guideline for people using
Error.pm, for ghod's sake don't use Error::Simple as a basis for
anything internally because it makes catch clauses a complete bitch to
write...)

Also, while we're about it, check out a possible refactoring of
Test::Unit.pm, to use Devel::Symdump and Class::Inner (an Inner class
type tool, which uses coderefs not strings for methods, and which I've
sort of released to CPAN by itself...).

sub create_suite {
    my ($test_package_name) = @_;
    $test_package_name = caller() unless defined($test_package_name);
    add_to_suites($test_package_name);
    
    my @funcs = $sym_tree->functions;
    my $setup_func = $test_package_name->can('set_up') || sub {};
    my $teardown_func = $test_package_name->can('tear_down') || sub {};
    
    my $sym_tree = Devel::Symdump->new($test_package_name);
    
    # Should probably do
    #     grep /^test.*/, 
    #     map /$test_package_name\::(.*)/,
    #     $sym_tree->functions
    # But I'm not entirely sure it's any clearer anyway.
        
    for my $test (map {/$test_package_name\::(test.*)/i || ()}
                  $sym_tree->functions)
    {
        my $test_case =
            Class::Inner->new(
                parent => 'Test::Unit::TestCase',
                methods => {set_up    => $setup_func,
                            tear_down => $teardown_func,
                            $test     => $test_package_name->can($test);
                           },);
            $suites{$test_package_name}->add_test($test_case);
        }
}

-- 
Piers Cawley
www.iterative-software.com


_______________________________________________
Perlunit-devel mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/perlunit-devel

Reply via email to