-#!/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' );