#!perl
# Copyright (C) 2001-2008, The Perl Foundation.
# $Id: harness 26411 2008-03-16 10:30:41Z bernhard $

use strict;
use warnings;
use lib qw( lib );

use Getopt::Std;
use Test::Harness ();
use Parrot::Harness::DefaultTests;
use Parrot::Harness::Options qw(
    handle_long_options
    get_test_prog_args
    Usage
);
use Parrot::Harness::Smoke qw(
    generate_html_smoke_report
);

local @ARGV = @ARGV;
(my $longopts, @ARGV) = handle_long_options(@ARGV);

$ENV{RUNNING_MAKE_TEST} = $longopts->{running_make_test};

# Suck the short options into the TEST_PROG_ARGS 
# environmental variable.
my %opts;
getopts('wgjPCSefbvdr?hO:D:', \%opts);

if ($opts{'?'} || $opts{h} || $longopts->{help}) {
    Usage();
    exit;
}

# add -D40;  merge it with any existing -D argument
$opts{D} = sprintf( '%x', hex(40) | (exists $opts{D} ? hex($opts{D}) : 0));

my $args = get_test_prog_args(
    \%opts, $longopts->{gc_debug}, $longopts->{run_exec}
);
$ENV{TEST_PROG_ARGS} = $args;

# now build the list of tests to run, either from the command
# line or from @default tests
my @default_tests = get_default_tests(
    $longopts->{core_tests_only},
    $longopts->{runcore_tests_only}
);

my @tests = map { glob( $_ ) } (@ARGV ? @ARGV : @default_tests);

if ( ! $longopts->{html} ) {
    Test::Harness::runtests(@tests);
}
else {
    generate_html_smoke_report ( {
        tests       => \@tests,
        args        => $args,
        file        => 'smoke.html',
    } );
}

=head1 NAME

t/harness - Parrot Test Harness

=head1 SYNOPSIS

    % perl t/harness [options] [testfiles]

=head1 DESCRIPTION

The short 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<-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<-f>

Run fast core.

=item C<-r>

compile to Parrot bytecode and then run the bytecode.

=item C<-O[012]>

Run optimized to the specified level.

=item C<-D[number]>

Pass the specified debug bits to the parrot interpreter.  Note that 
C<-D40> (fill I, N registers with garbage) is always enabled.  
See 'parrot --help-debug' for available flags.

=back

There are also long command line options:

=over 4

=item C<--running-make-test>

Some test scripts run more quickly when this is set.

=item C<--gc-debug>

Invoke parrot with '--gc-debug'.

=item C<--html>

Emit a C<smoke.html> file instead of displaying results.

=back

=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


# Local Variables:
#   mode: cperl
#   cperl-indent-level: 4
#   fill-column: 100
# End:
# vim: expandtab shiftwidth=4:
