From: Dave Rolsky Date: Fri, 10 Jul 2009 00:52:33 +0000 (-0500) Subject: Tidy and simplify this script X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=9f39aa0852fec9140ef64cef3e128d8bbb6f05fd;p=gitmo%2Fmoose-presentations.git Tidy and simplify this script --- diff --git a/moose-class/exercises/answers/test_answers.pl b/moose-class/exercises/answers/test_answers.pl index 893202e..df8f5ff 100755 --- a/moose-class/exercises/answers/test_answers.pl +++ b/moose-class/exercises/answers/test_answers.pl @@ -1,35 +1,29 @@ -#!/usr/bin/env perl +#!/usr/bin/perl + use strict; use warnings; + use FindBin; use TAP::Harness; -### construct a hash of test_filename => answer_libdir -my %test2anslib = - map { - my $answer_libdir = $_; - my ($exercise_num) = $answer_libdir =~ m!/(\d+)-! - or die "can't parse dir name '$answer_libdir'"; +my $harness = TAP::Harness->new( + { + failures => 1, + exec => sub { + my ( undef, $testfile ) = @_; - map {$_ => $answer_libdir} - glob "$FindBin::RealBin/../t/$exercise_num-*.t"; - } - # filter to find just answer libdirs - grep m!/\d+-[\w-]+/$!, - # list all dirs below this t/ dir - glob "$FindBin::RealBin/*/"; + my ($number) = $testfile =~ m{^t/(\d+)}; + return [ $^X, $testfile ] if $number eq '00'; + my ($libdir) = glob "answers/$number-*" + or die "Cannot find an answer dir for $testfile"; -my $harness = TAP::Harness->new({ - failures => 1, - exec => sub { - my ($h,$testfile) = @_; - my $ans_libdir = $test2anslib{$testfile} or die "test file $testfile not found??"; - [$^X, "-I$ans_libdir", $testfile ] - }, -}); + [ $^X, "-I$libdir", $testfile ]; + }, + } +); chdir "$FindBin::RealBin/../"; -$harness->runtests( sort keys %test2anslib ); +$harness->runtests( sort glob 't/*.t' );