#!/usr/bin/perl use strict; use warnings; use File::Find; use Cwd; use Text::Reform qw( form ); use Data::Dumper; use Getopt::Long; use Pod::Usage; use Test::Harness::Straps; my $strap = Test::Harness::Straps->new(); our( @status, @filename, @expected, @run, @passed, @skipped, @todo, @todo_skipped ); our( $opt_help, $opt_path, $opt_email, $opt_noprint ); GetOptions( "help|h" => \$opt_help, "path|p=s" => \$opt_path, "email|e=s" => \$opt_email, "noprint|n" => \$opt_noprint, ); pod2usage( -verbose => 2 ) if $opt_help; my $path = getcwd unless $opt_path; find( { wanted => \&test_found, no_chdir => 1 }, $path ); my $report_date = localtime( time ); my $alert = form '', "Test suite at $path", "Report Date: $report_date", '', ' ====================================================', ' Tests ', ' ====================================================', 'Status Filename Expected Run Passed Skipped TODO TODO Skipped', '----------------------------------------------------------------------------------------------', '|||| [[[[[[[[[[[[[[[[[[[[[[[[[[[[[[ ||| ||| ||| ||| ||| |||', \@status, \@filename, \@expected, \@run, \@passed, \@skipped, \@todo, \@todo_skipped; print $alert unless $opt_noprint; send_mail( $alert, "Test Suite: $path", $opt_email ) if $opt_email; sub send_mail{ my ( $alert, $subject, $to_email ) = @_; # Send email here } sub test_found{ return unless m/\.t$/; return if $File::Find::name =~ m/exclude_tests/i; my %results = $strap->analyze_file( $File::Find::name ); my $status = 'FAIL'; $status = ' OK ' if $results{'max'} == $results{'seen'} && $results{'seen'} == $results{'ok'}; my ( $file ) = $File::Find::name; $file =~ s/$path//;; push @status, $status; push @filename, $file; push @expected, $results{'max'}; push @run, $results{'seen'}; push @passed, $results{'ok'}; push @skipped, $results{'skip'}; push @todo, $results{'todo'}; push @todo_skipped, $results{'bonus'}; } 1; __END__ =head1 NAME test_harness.pl - Main test harness script. =head1 SYNOPSIS test_harness.pl --path --help --path, -p: Path to look for tests - will run all tests found. Defaults to ./t. --email, -e: Email address to send report to. If ommitted, no report is sent. --noprint, n: Suppress printing report to STDOUT. --help, -h: This message. =head1 AUTHOR Troy Denkinger (tdenkinger at gmail.com) =head1 VERSION Version 1.0 =head1 COPYRIGHT Copyright (c) 2005 by Troy Denkinger. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut