Apache-Test

 view release on metacpan or  search on metacpan

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

# 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::TestHarness;

use strict;
use warnings FATAL => 'all';

use Test::Harness ();
use Apache::Test ();
use Apache::TestSort ();
use Apache::TestTrace;
use File::Spec::Functions qw(catfile catdir);
use File::Find qw(finddepth);
use File::Basename qw(dirname);

sub inc_fixup {
    # use blib
    unshift @INC, map "blib/$_", qw(lib arch);

    # fix all relative library locations
    for (@INC) {
        $_ = "../$_" unless m,^(/)|([a-f]:),i;
    }
}

#skip tests listed in t/SKIP
sub skip {
    my($self, $file) = @_;
    $file ||= catfile Apache::Test::vars('serverroot'), 'SKIP';

    return unless -e $file;

    my $fh = Symbol::gensym();
    open $fh, $file or die "open $file: $!";
    my @skip;
    local $_;

    while (<$fh>) {
        chomp;
        s/^\s+//; s/\s+$//; s/^\#.*//;
        next unless $_;
        s/\*/.*/g;
        push @skip, $_;
    }

    close $fh;
    return join '|', @skip;
}

#test if all.t would skip tests or not
{
    my $source_lib = '';

    sub run_t {
        my($self, $file) = @_;
        my $ran = 0;

        if (Apache::TestConfig::IS_APACHE_TEST_BUILD and !length $source_lib) {
            # so we can find Apache/Test.pm from both the perl-framework/
            # and Apache-Test/

            my $top_dir = Apache::Test::vars('top_dir');
            foreach my $lib (catfile($top_dir, qw(Apache-Test lib)),
                             catfile($top_dir, qw(.. Apache-Test lib)),
                             catfile($top_dir, 'lib')) {

                if (-d $lib) {
                    info "adding source lib $lib to \@INC";
                    $source_lib = qq[-Mlib="$lib"];
                    last;
                }
            }
        }

        my $cmd = qq[$^X $source_lib $file];

        my $h = Symbol::gensym();
        open $h, "$cmd|" or die "open $cmd: $!";

        local $_;
        while (<$h>) {
            if (/^1\.\.(\d)/) {
                $ran = $1;
                last;
            }
        }

        close $h;

        $ran;
     }
}

#if a directory has an all.t test
#skip all tests in that directory if all.t prints "1..0\n"
sub prune {
    my($self, @tests) = @_;
    my(@new_tests, %skip_dirs);

    foreach my $test (@tests) {
        next if $test =~ /\.#/; # skip temp emacs files
        my $dir = dirname $test;
        if ($test =~ m:\Wall\.t$:) {
            unless (__PACKAGE__->run_t($test)) {
                $skip_dirs{$dir} = 1;
                @new_tests = grep { m:\Wall\.t$: ||
                                    not $skip_dirs{dirname $_} } @new_tests;
                push @new_tests, $test;
            }
        }
        elsif (!$skip_dirs{$dir}) {
            push @new_tests, $test;
        }
    }

    @new_tests;
}

sub get_tests {



( run in 0.947 second using v1.01-cache-2.11-cpan-e1769b4cff6 )