#! perl -w
# Copyright: 2001-2003 The Perl Foundation.  All Rights Reserved.
# $Id: harness,v 1.21 2004/03/01 08:48:16 leo Exp $

=head1 NAME

t/harness - Parrot Test Harness

=head1 SYNOPSIS

    % perl t/harness [options] [testfiles]

=head1 DESCRIPTION

Command-line options are:

=over 4

=item C<-w>

Turn warnings on.

=item C<-g>

Run the C<CGoto> core.

=item C<-j>

Run with JIT enabled.

=item C<-P>

Run the C<Prederef> core.

=item C<-C>

Run the C<CGP> core.

=item C<-S>

Run Switched.

=item C<-b>

Run bounds checking enabled.

=item C<-d>

Run with debugging enabled.

=item C<-r>

assemble to Parrot bytecode and then run the bytecode.

=item C<-O[012]>

Run optimized to the specified level.

=back

=cut

use strict;
use lib qw(lib imcc);

use Getopt::Std;
use Test::Harness qw(runtests);

# handle the long options
$ENV{RUNNING_MAKE_TEST} = grep { $_ eq '--running-make-test' } @ARGV;
@ARGV = grep { $_ ne '--running-make-test' } @ARGV;
$ENV{PARROT_QUICKTEST} = grep { $_ eq 'quick' } @ARGV;
@ARGV = grep { $_ ne 'quick' } @ARGV;
my $gc_debug = grep { $_ eq '--gc-debug' } @ARGV;
@ARGV = grep { $_ ne '--gc-debug' } @ARGV;
my $run_pbc = grep { $_ eq '--run-pbc' } @ARGV;
@ARGV = grep { $_ ne '--run-pbc' } @ARGV;

# Suck the short options into the TEST_PROG_ARGS evar:
my %opts;
getopts('wgjPCSbvdr?hO:', \%opts);
if ($opts{'?'} || $opts{h}) {
    print <<"EOF";
perl t/harness [options] [testfiles]
    -w ... warnings on
    -g ... run CGoto
    -j ... run JIT
    -P ... run Prederef
    -C ... run CGP
    -S ... run Switched
    -b ... run bounds checked
    -v ... run verbose
    -d ... run debug
    -r ... assemble to PBC run PBC
    -O[012] optimize
EOF
    exit;
}

my $args = join(' ', map { "-$_" } keys %opts );
$args =~ s/-O/-O$opts{O}/ if ($opts{O});
$args .= ' --gc-debug'    if $gc_debug;
$args .= ' --run-pbc'     if $run_pbc;
$ENV{TEST_PROG_ARGS} = $args;

# Pass in a list of tests to run on the command line, else run all the tests.
my @default_tests = ( ( map { glob( "t/$_/*.t" ) } qw(op pmc native_pbc) ),
                      glob( "imcc/t/*/*.t" ),
                      glob( "t/src/*.t" ),
                    );
my @tests = @ARGV ? map { glob( $_ ) } @ARGV : @default_tests;
runtests(@tests);

=head1 HISTORY

Mike Lambert stole F<t/harness> for F<languages/perl6/t/harness>.

Leo Toetsch stole F<languages/perl6/t/harness> for F<imcc/t/harness>.

Bernhard Schmalhofer merged F<imcc/t/harness> back into F<t/harness>.

=cut
