#!/usr/bin/perl
#ABSTRACT: run DAIA test suites
#PODNAME: provedaia

use strict;
use warnings;

use Getopt::Long;
use Pod::Usage;
use Plack::App::DAIA::Test::Suite;
use Test::More;

my ($help,$version,$server,$end,$combined);

GetOptions(
    'help|?'   => \$help,
    'server:s' => \$server,
    'version'  => \$version,
    'end'      => \$end,
    'combined' => \$combined,
);
pod2usage(-verbose => 1) if defined $help;

if ($version) {
    printf "This is provedaia with Plack::App::DAIA %s and DAIA %s\n",
           $PLack::App::DAIA::VERSION, $DAIA::VERSION;
    exit;
}

$end = 1 if $combined;
@ARGV = \*STDIN unless @ARGV;

foreach (@ARGV) {
    diag( $_ ) unless ref $_;
    $server = $_ if $combined;
    eval { provedaia( $_, server => $server, end => $end ); };
    fail( $@ ) if $@;
}

done_testing;


__END__
=pod

=head1 NAME

provedaia - run DAIA test suites

=head1 VERSION

version 0.44

=head1 SYNOPSIS

provedaia [<OPTIONS>] [<FILES>]

 Options:
   -?|-h|--help          show this help
   --version             show version
   --server URL-or-file  set base URL of DAIA server or load PSGI script
   --end                 skip everything until __END__ in input
   --combined            use files as both, server and test suite

=head1 DESCRIPTION

This script can be used to test DAIA servers. It is based on the package
L<Plack::App::DAIA::Test::Suite>, so the output of this script conforms to the
Test Anything Protocol (TAP). You can provide a full test script or a DAIA
server that contains its own test suite after the C<__END__> marker. If no
file is provided, it is read from standard input. See the bottom of
C<examples/daia-ubbielefeld.pl> for an example.

A typical usage scenario for this script is:

=over 4

=item

You implement a DAIA server, for instance in C<myapp.psgi> and run it, for
instance a C<http://localhost:5000/>.

=item

You write some test suites for the DAIA server, for instance in C<test1.txt>
and C<test2.txt>. These tests are sets of document identifiers and (partial)
responses which you expect your server to return. A description of the test
format is given in L<Plack::App::DAIA::Test::Suite>.

=item

You run C<provedaia> as

  provedaia --server myapp.psgi test1.txt test2.txt

or as

  provedaia --server http://localhost:5000/ test1.txt test2.txt

If you server implementation contains its own test suite, you can also call

  provedaia --combined myapp.psgi

=back

=head1 AUTHOR

Jakob Voss

=head1 COPYRIGHT AND LICENSE

This software is copyright (c) 2012 by Jakob Voss.

This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.

=cut

