]>
Commit | Line | Data |
---|---|---|
5c5cd38a MG |
1 | package Gruntmaster::Daemon::Runner::File; |
2 | ||
3 | use 5.014000; | |
4 | use strict; | |
5 | use warnings; | |
6 | ||
7 | use Gruntmaster::Daemon::Constants qw/WA/; | |
8 | use File::Slurp qw/slurp/; | |
9 | use Log::Log4perl qw/get_logger/; | |
10 | ||
a5522656 | 11 | our $VERSION = "5999.000_001"; |
bc372959 | 12 | |
5c5cd38a MG |
13 | ################################################## |
14 | ||
15 | sub run{ | |
16 | my ($test, $meta) = @_; | |
17 | get_logger->trace("Running on test $test..."); | |
18 | $meta->{files}{prog}{run}->($meta->{files}{prog}{name}, fds => [qw/0 input 1 >output/], map {defined $meta->{$_} ? ($_ => $meta->{$_}) : () } qw/timeout olimit mlimit/); | |
19 | my $out = slurp 'output'; | |
8a8d1a82 MG |
20 | my $ok; |
21 | if (exists $meta->{okfile}) { | |
22 | $ok = $meta->{okfile}[$test - 1] | |
23 | } else { | |
07d71f40 MG |
24 | my $ct = defined $Gruntmaster::Data::contest ? "ct/$Gruntmaster::Data::contest" : ''; |
25 | $ok = slurp "/var/lib/gruntmasterd/$ct/pb/$meta->{problem}/$test.ok" | |
8a8d1a82 | 26 | } |
5c5cd38a MG |
27 | |
28 | $out =~ s/^\s+//; | |
29 | $ok =~ s/^\s+//; | |
30 | $out =~ s/\s+/ /; | |
31 | $ok =~ s/\s+/ /; | |
32 | $out =~ s/\s+$//; | |
33 | $ok =~ s/\s+$//; | |
34 | ||
35 | die [WA, "Wrong answer"] if $out ne $ok; | |
36 | $meta->{tests}[$test - 1] // 0 | |
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; | |
51 | Gruntmaster::Daemon::Runner::File->run(5, $meta); | |
52 | ||
53 | =head1 DESCRIPTION | |
54 | ||
593a8e6f | 55 | Gruntmaster::Daemon::Runner::File is a runner which compares the program output for test C<$test> with C<< $meta->{tests}[$test - 1] >>. Before comparing, leading and trailing whitespace is removed, and sequences of whitespace are converted to a single space. |
bc372959 MG |
56 | |
57 | =head1 AUTHOR | |
58 | ||
59 | Marius Gavrilescu E<lt>marius@ieval.roE<gt> | |
60 | ||
61 | =head1 COPYRIGHT AND LICENSE | |
62 | ||
63 | Copyright (C) 2014 by Marius Gavrilescu | |
64 | ||
65 | This library is free software: you can redistribute it and/or modify | |
66 | it under the terms of the GNU Affero General Public License as published by | |
67 | the Free Software Foundation, either version 3 of the License, or | |
68 | (at your option) any later version. | |
69 | ||
70 | ||
71 | =cut |