Apache-Test

 view release on metacpan or  search on metacpan

lib/Apache/TestMB.pm  view on Meta::CPAN

# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License.  You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

package Apache::TestMB;

use strict;
use vars qw(@ISA);
use Module::Build 0.18;
use Apache::Test ();
use Apache::TestConfig ();
@ISA = qw(Module::Build);

sub new {
    my $pkg = shift;
    my($argv, $vars) =
        Apache::TestConfig::filter_args(\@ARGV, \%Apache::TestConfig::Usage);
    @ARGV = @$argv;
    my $self = $pkg->SUPER::new(@_);
    $self->{properties}{apache_test_args} = $vars;
    $self->{properties}{apache_test_script} ||= 't/TEST';
    $self->generate_script;
    return $self;
}

sub valid_property {
    return 1 if defined $_[1] &&
        ($_[1] eq 'apache_test_args' || $_[1] eq 'apache_test_script');
    shift->SUPER::valid_property(@_);
}

sub apache_test_args {
    my $self = shift;
    $self->{properties}{apache_test_args} = shift if @_;
    return $self->{properties}{apache_test_args};
}

sub apache_test_script {
    my $self = shift;
    $self->{properties}{apache_test_script} = shift if @_;
    return $self->{properties}{apache_test_script};
}

sub ACTION_test_clean {
    my $self = shift;
    # XXX I'd love to do this without t/TEST.
    $self->do_system( $self->perl, $self->_bliblib,
                      $self->localize_file_path($self->apache_test_script),
                      '-clean');
}

sub ACTION_clean {
    my $self = shift;
    $self->depends_on('test_clean');
    $self->SUPER::ACTION_clean(@_);
}

sub ACTION_run_tests {
    my $self = shift;
    $self->depends_on('test_clean');
    # XXX I'd love to do this without t/TEST.
    $self->do_system($self->perl, $self->_bliblib,
                     $self->localize_file_path($self->apache_test_script),
                     '-bugreport', '-verbose=' . ($self->verbose || 0));
}

sub ACTION_testcover {
    my $self = shift;

    unless ($self->find_module_by_name('Devel::Cover', \@INC)) {
        warn("Cannot run testcover action unless Devel::Cover "
             . "is installed.\n" .
             "Don't forget to rebuild your Makefile after "
             . "installing Devel::Cover\n");
        return;
    }

    $self->add_to_cleanup('coverage', 'cover_db');

    my $atdir = $self->localize_file_path("$ENV{HOME}/.apache-test");
    local $Test::Harness::switches    =
    local $Test::Harness::Switches    =
    local $ENV{HARNESS_PERL_SWITCHES} = "-MDevel::Cover=+inc,'$atdir'";
    local $ENV{APACHE_TEST_EXTRA_ARGS} = "-one-process";

    $self->depends_on('test');
    $self->do_system('cover');
}

sub ACTION_test_config {
    my $self = shift;
    $self->do_system($self->perl, $self->_bliblib,
                     $self->localize_file_path($self->apache_test_script),
                     '-conf', '-verbose=' . ($self->verbose || 0));
}

sub _bliblib {
    my $self = shift;
    return (
        '-I', File::Spec->catdir($self->base_dir, $self->blib, 'lib'),
        '-I', File::Spec->catdir($self->base_dir, $self->blib, 'arch'),
    );
}

sub ACTION_test {
    my $self = shift;
    $self->depends_on('code');
    $self->depends_on('run_tests');
    $self->depends_on('test_clean');
}

sub _cmodules {
    my ($self, $action) = @_;
    die "The cmodules" . ( $action ne 'all' ? "_$action" : '')
      . " action is not yet implemented";



( run in 1.028 second using v1.01-cache-2.11-cpan-5a3173703d6 )