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