The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.
#!/usr/bin/perl

# Copyright 2002-2013, Paul Johnson (paul@pjcj.net)

# This software is free.  It is licensed under the same terms as Perl itself.

# The latest version of this software should be available from my homepage:
# http://www.pjcj.net

require 5.6.1;

use strict;
use warnings;

# VERSION

use blib;

use Config;
exit if $Config{useithreads};

use Devel::Cover::Test;

my @tests = @ARGV;

mkdir "test_output"       unless -d "test_output";
mkdir "test_output/cover" unless -d "test_output/cover";

unless (@tests)
{
    opendir D, "tests" or die "Cannot opendir tests: $!";
    for my $t (sort readdir D)
    {
        next unless -f "tests/$t";
        next if $t =~ /\.(pm|pl|uncoverable|version|org|bak)$/;
        next if $t =~ /~$/;

        push @tests, $t;
    }
    closedir D or die "Cannot closedir tests: $!";
}

for my $test (@tests)
{
    my $e      = "t/e2e";
    my ($file) = grep -e, "$e/$test", "$e/a$test.t";
    $file    ||= $test;
    print STDERR "creating golden results for $test: ";
    my $t;
    {
        no warnings "redefine";
        local *Devel::Cover::Test::run_test = sub {};
        $t = require $file or die "Can't require $file: $!";
    }
    $t->create_gold;
    print "\n";
}