# Copyright (C) 2006, The Perl Foundation.
# $Id: /mirror/trunk/languages/WMLScript/t/harness 14930 2006-10-11T09:57:08.034643Z fperrad  $

=head1 NAME

languages/WMLScript/t/harness - A harness for WMLScript translator

=head1 SYNOPSIS

    cd languages && perl -I../lib -IWMLScript/t WMLScript/t/harness --files

    cd languages && perl -I../lib -IWMLScript/t WMLScript/t/harness

    cd languages && perl -I../lib -IWMLScript/t WMLScript/t/harness WMLScript/t/examples.t

    cd languages/WMLScript && perl -I../../lib -It t/harness

    cd languages/WMLScript && perl -I../../lib -It t/harness t/examples.t

=head1 DESCRIPTION

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 complete suite.

Otherwise I run the tests that were passed on the command line.

=cut

use strict;
use warnings;
use lib '..';

use Cwd();
use Data::Dumper;
use File::Spec;
use Getopt::Long;
use Test::Harness();

my $opt_files;
GetOptions(
    'files' => \$opt_files,
);

my $language = 'WMLScript';

# Check that we have the WMLScript compiler.
my $check = `wmlsc -h`;
my $has_compiler = $check =~ /wmlsc/;
unless ($has_compiler) {
    warn "You need the WMLScript compiler in your path to build the test assemblies.\n";
}

if ($opt_files) {

    # Only the Makefile in 'parrot/languages' uses --files
    my $dir = File::Spec->catfile( $language, 't' );
    my @files = glob( File::Spec->catfile( $dir, 'pmc', '*.t' ) );
    push @files, glob( File::Spec->catfile( $dir, '*.t' ) )
        if ($has_compiler);
    print join( "\n", @files );
    print "\n" if scalar(@files);
}
else {
    my @files;

    if ( scalar(@ARGV) ) {

        # Someone specified tests for me to run.
        @files = grep { -f $_ } @ARGV;
    }
    else {
        ( undef, undef, my $current_dir )
            = File::Spec->splitpath( Cwd::getcwd() );
        my $dir;
        if ( $current_dir eq 'languages' ) {
            $dir = File::Spec->catfile( $language, 't' );
        }
        elsif ( $current_dir eq $language ) {
            $dir = 't';
        }
        if ($dir) {
            @files = glob( File::Spec->catfile( $dir, 'pmc', '*.t' ) );
            push @files, glob( File::Spec->catfile( $dir, '*.t' ) )
                if ($has_compiler);
        }
    }

    Test::Harness::runtests(@files) if scalar(@files);
}

=head1 HISTORY

Mostly taken from F<languages/bc/t/harness>.

=head1 SEE ALSO

F<languages/tcl/t/harness>, F<languages/scheme/t/harness>, F<languages/m4/t/harness>, F<languages/python/t/harness>, F<languages/lua/t/harness>

=head1 AUTHOR

Francois Perrad

=cut

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

