diff options
| author | Abigail <abigail@abigail.be> | 2020-10-19 14:35:32 +0200 |
|---|---|---|
| committer | Abigail <abigail@abigail.be> | 2020-10-19 14:35:32 +0200 |
| commit | c4f90a4fc0786f428e5aa1d6dab206cd5e9e01cc (patch) | |
| tree | 10ef17dc30ea318d52acdc2d3f4a810999fe3dc0 /challenge-083/abigail | |
| parent | 52ae56bdd93bb55f04ee3d75bc45365b31e80306 (diff) | |
| download | perlweeklychallenge-club-c4f90a4fc0786f428e5aa1d6dab206cd5e9e01cc.tar.gz perlweeklychallenge-club-c4f90a4fc0786f428e5aa1d6dab206cd5e9e01cc.tar.bz2 perlweeklychallenge-club-c4f90a4fc0786f428e5aa1d6dab206cd5e9e01cc.zip | |
Copy test file from previous weeks challenge.
Diffstat (limited to 'challenge-083/abigail')
| -rwxr-xr-x | challenge-083/abigail/test.pl | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/challenge-083/abigail/test.pl b/challenge-083/abigail/test.pl new file mode 100755 index 0000000000..aa84e275d5 --- /dev/null +++ b/challenge-083/abigail/test.pl @@ -0,0 +1,82 @@ +#!/opt/perl/bin/perl + +# +# Test the solutions. Either call it with the directory name you +# want to test in, or call it as "../test.pl" from within the directory. +# + +use 5.032; + +use strict; +use warnings; +no warnings 'syntax'; + +chdir ".." if -f "../test.pl"; + +use experimental 'signatures'; + +use Test::More; + + +my %languages = ( + Perl => { + exe => "/opt/perl/bin/perl", + ext => "pl", + }, + JavaScript => { + exe => "/usr/local/bin/node", + ext => "js", + dir => "node", + }, + bc => { + exe => "/usr/bin/bc", + ext => "bc", + filter => 's/.*/main($&)/', + }, + awk => { + exe => "/usr/bin/awk", + ext => "awk", + args => ["-f"], + }, +); + +my $perl_exe = $languages {Perl} {exe}; + +foreach my $challenge (1, 2) { + my @inputs = <input-$challenge-*> or next; + subtest "Challenge $challenge" => sub { + foreach my $language (sort keys %languages) { + my $info = $languages {$language}; + my $exe = $$info {exe}; + my $ext = $$info {ext}; + my $dir = $$info {dir} // lc $language; + my @args = @{$$info {args} // []}; + my $filter = $$info {filter} // ''; + my $solution = "$dir/ch-$challenge.$ext"; + next unless -r $solution; + + subtest $language => sub { + foreach my $input (@inputs) { + my $output_exp = ($input =~ s/input/output/r) . ".exp"; + my $exp = `cat $output_exp`; + + my $name = $input; + if ($exp =~ s/^\s*#\s*(.*)\n//) { + $name = $1; + } + + my $got = `$perl_exe -ple '$filter' $input |\ + $exe @args ./$solution`; + + s/\h+$//gm for $exp, $got; + is $got, $exp, $name; + } + } + } + } +} + +done_testing; + + +__END__ |
