added little test_answers.pl script to run the exercise tests on the answers in a...
[gitmo/moose-presentations.git] / moose-class / exercises / answers / test_answers.pl
1 #!/usr/bin/env perl
2 use strict;
3 use warnings;
4 use FindBin;
5 use TAP::Harness;
6
7
8 ### construct a hash of test_filename => answer_libdir
9 my %test2anslib =
10     map {
11         my $answer_libdir = $_;
12         my ($exercise_num) = $answer_libdir =~ m!/(\d+)-!
13             or die "can't parse dir name '$answer_libdir'";
14
15         map {$_ => $answer_libdir}
16         glob "$FindBin::RealBin/../t/$exercise_num-*.t";
17     }
18     # filter to find just answer libdirs
19     grep m!/\d+-[\w-]+/$!,
20     # list all dirs below this t/ dir
21     glob "$FindBin::RealBin/*/"; 
22
23
24
25 my $harness = TAP::Harness->new({
26     failures => 1,
27     exec => sub {
28         my ($h,$testfile) = @_;
29         my $ans_libdir = $test2anslib{$testfile} or die "test file $testfile not found??";
30         [$^X, "-I$ans_libdir", $testfile ]
31     },
32 });
33
34 chdir "$FindBin::RealBin/../";
35 $harness->runtests( sort keys %test2anslib );