#!perl

use strict;
use warnings;

use Test::Harness qw/&runtests $verbose/;
use File::Spec;

$verbose = 0;

my $language = "tcl";

=pod

conformant to a recent post on p6i, if I'm called with a single
argument of "-files", I just return a list of files to process.
This list is one per line, and is relative to the languages dir.

If I'm called with no args, I run the suite.

=cut

my @files;

# Setting these options helps flush out issues that might otherwise
# happen to slip by.

my @required_options = qw/--gc-debug -D40/;


$ENV{TEST_PROG_ARGS} = "" unless defined($ENV{TEST_PROG_ARGS});

foreach my $option (@required_options) {
  if ( $ENV{TEST_PROG_ARGS} !~ /\b$option\b/) {
    $ENV{TEST_PROG_ARGS} .= " $option";
  }
}

my $DTotal = 0;
while ($ENV{TEST_PROG_ARGS} =~ s/-D(\d*)//) {
  $DTotal += $1;
}

if ($DTotal) {
  $ENV{TEST_PROG_ARGS} .= "-D$DTotal";
}

if ( grep { /^--files$/ } @ARGV ) {
    # I must be running out of languages/
    my $dir = File::Spec->catfile( $language, "t" );
    my @files = glob( File::Spec->catfile( $dir, "*.t" ) );
    print join("\n",@files);
    print "\n" if @files;
    exit;
} elsif (@ARGV) {
    # Someone specified tests for me to run.
    @files = grep {-f $_} @ARGV
} else {
    # I must be running out of languages/$language
    # You may want a deeper search than this.
    @files = glob( File::Spec->catfile( "t", "*.t" ) );
}

exit unless @files;
runtests(@files);

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