#! perl

# $Id: /mirror/trunk/languages/perl6/t/harness 27171 2008-04-25T19:52:05.300025Z particle  $

use FindBin;
use File::Spec;
use lib qw( ../../lib );

our %harness_args;

BEGIN {
    our %harness_args = (
        language  => 'perl6',
        compiler  => 'perl6.pbc',
    );

    my %opts;
    while( $_ = $ARGV[0] ) {
        last unless defined && /^-/;
        shift;
        last if /^--$/;
        $opts{$_} = $_;
    }

    ##  if we aren't fudging tests, we're done here
    return unless defined delete $opts{'--fudge'};


    my $impl    = 'rakudo';
    my @tfiles = sort map { -d $_ ? all_in($_) : $_ } map glob, @ARGV;
    my $cmd = join ' ', $^X, 't/spec/fudgeall', keys(%opts), $impl, @tfiles;
    print "$cmd\n";

    $harness_args{arguments} = [ split ' ', `$cmd` ];

    # Stolen directly from 'prove'
    # adapted to return only files ending in '.t'
    sub all_in {
        my $start = shift;

        my @hits = ();

        local *DH;
        if ( opendir( DH, $start ) ) {
            my @files = sort readdir DH;
            closedir DH;
            for my $file ( @files ) {
                next if $file eq File::Spec->updir || $file eq File::Spec->curdir;
                next if $file eq ".svn";
                next if $file eq "CVS";

                my $currfile = File::Spec->catfile( $start, $file );
                if ( -d $currfile ) {
                    push( @hits, all_in( $currfile ) ) if $recurse;
                } else {
                    push( @hits, $currfile ) if $currfile =~ /\.t$/;
                }
            }
        } else {
            warn "$start: $!\n";
        }

        return @hits;
    }

}

use Parrot::Test::Harness %harness_args;

# Set up PERL6LIB environment path so the "use" tests can find libraries
$ENV{PERL6LIB} = "$Bin/01-sanity";



