diff options
| author | Abigail <abigail@abigail.be> | 2020-10-11 13:45:17 +0200 |
|---|---|---|
| committer | Abigail <abigail@abigail.be> | 2020-10-11 13:45:17 +0200 |
| commit | 4349abc09357350a8212f95e27c3000aee78adbc (patch) | |
| tree | 022ebc7ac9f5b554a8cb1c484992be3495fe3240 | |
| parent | a21f55bc31e9694a366c75c5f4bd9c450dc6b788 (diff) | |
| download | perlweeklychallenge-club-4349abc09357350a8212f95e27c3000aee78adbc.tar.gz perlweeklychallenge-club-4349abc09357350a8212f95e27c3000aee78adbc.tar.bz2 perlweeklychallenge-club-4349abc09357350a8212f95e27c3000aee78adbc.zip | |
Copied test program from week 80.
| -rwxr-xr-x | challenge-081/abigail/test.pl | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/challenge-081/abigail/test.pl b/challenge-081/abigail/test.pl new file mode 100755 index 0000000000..310382b62b --- /dev/null +++ b/challenge-081/abigail/test.pl @@ -0,0 +1,77 @@ +#!/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 $got = `$perl_exe -ple '$filter' $input |\ + $exe @args ./$solution`; + + s/\h+$//gm for $exp, $got; + is $got, $exp, $input; + } + } + } + } +} + +done_testing; + + +__END__ |
