]>
Commit | Line | Data |
---|---|---|
5c5cd38a MG |
1 | package Gruntmaster::Daemon::Runner::File; |
2 | ||
3 | use 5.014000; | |
4 | use strict; | |
5 | use warnings; | |
99d37110 | 6 | use re '/s'; |
5c5cd38a MG |
7 | |
8 | use Gruntmaster::Daemon::Constants qw/WA/; | |
9 | use File::Slurp qw/slurp/; | |
10 | use Log::Log4perl qw/get_logger/; | |
11 | ||
99d37110 | 12 | our $VERSION = '5999.000_004'; |
bc372959 | 13 | |
5c5cd38a MG |
14 | ################################################## |
15 | ||
16 | sub run{ | |
a722431b MG |
17 | my ($test, $meta) = @_; |
18 | get_logger->trace("Running on test $test..."); | |
11ddb278 | 19 | $meta->{files}{prog}{run}->($meta->{files}{prog}{name}, fds => [qw/0 input 1 >output/], map { $_ => $meta->{$_} } qw/timeout olimit mlimit/); |
a722431b MG |
20 | my $out = slurp 'output'; |
21 | my $ok; | |
146dc3a7 | 22 | if (exists $meta->{okfile}) { # uncoverable branch false |
a722431b MG |
23 | $ok = $meta->{okfile}[$test - 1] |
24 | } else { | |
146dc3a7 | 25 | $ok = slurp "/var/lib/gruntmasterd/pb/$meta->{problem}/$test.ok" # uncoverable statement |
a722431b MG |
26 | } |
27 | ||
28 | $out =~ s/^\s+//; | |
29 | $ok =~ s/^\s+//; | |
ce50c40d MG |
30 | $out =~ s/\s+/ /g; |
31 | $ok =~ s/\s+/ /g; | |
a722431b MG |
32 | $out =~ s/\s+$//; |
33 | $ok =~ s/\s+$//; | |
34 | ||
99d37110 | 35 | die [WA, 'Wrong answer'] if $out ne $ok; ## no critic (RequireCarping) |
a722431b | 36 | $meta->{tests}[$test - 1] // 0 |
5c5cd38a MG |
37 | } |
38 | ||
bc372959 MG |
39 | 1; |
40 | __END__ | |
41 | ||
42 | =encoding utf-8 | |
43 | ||
44 | =head1 NAME | |
45 | ||
46 | Gruntmaster::Daemon::Runner::File - Compare output with static text files | |
47 | ||
48 | =head1 SYNOPSIS | |
49 | ||
50 | use Gruntmaster::Daemon::Runner::File; | |
0005d3ad | 51 | Gruntmaster::Daemon::Runner::File::run(5, $meta); |
bc372959 MG |
52 | |
53 | =head1 DESCRIPTION | |
54 | ||
0005d3ad MG |
55 | Gruntmaster::Daemon::Runner::File is a runner which compares the program output for test C<$test> with a static output. Before comparing, leading and trailing whitespace is removed, and sequences of whitespace are converted to a single space. |
56 | ||
57 | If C<< $meta->{okfile} >> exists, the output is compared to C<< $meta->{okfile}[$test - 1] >>. | |
58 | Otherwise, the output is compared to F<< /var/lib/gruntmasterd/pb/$meta->{problem}/$test.ok >>. | |
59 | ||
60 | If the two strings match, the verdict is C<< $meta->{tests}[$test - 1] >>. Otherwise, the verdict is C<[WA, "Wrong answer"]>. | |
bc372959 MG |
61 | |
62 | =head1 AUTHOR | |
63 | ||
64 | Marius Gavrilescu E<lt>marius@ieval.roE<gt> | |
65 | ||
66 | =head1 COPYRIGHT AND LICENSE | |
67 | ||
68 | Copyright (C) 2014 by Marius Gavrilescu | |
69 | ||
70 | This library is free software: you can redistribute it and/or modify | |
71 | it under the terms of the GNU Affero General Public License as published by | |
72 | the Free Software Foundation, either version 3 of the License, or | |
73 | (at your option) any later version. | |
74 | ||
75 | ||
76 | =cut |