]> iEval git - gruntmaster-daemon.git/blame - lib/Gruntmaster/Daemon/Runner/File.pm
Move some Format.pm code to gruntmaster-exec
[gruntmaster-daemon.git] / lib / Gruntmaster / Daemon / Runner / File.pm
CommitLineData
5c5cd38a
MG
1package Gruntmaster::Daemon::Runner::File;
2
3use 5.014000;
4use strict;
5use warnings;
6
7use Gruntmaster::Daemon::Constants qw/WA/;
8use File::Slurp qw/slurp/;
9use Log::Log4perl qw/get_logger/;
10
3e7fd903 11our $VERSION = "5999.000_004";
bc372959 12
5c5cd38a
MG
13##################################################
14
15sub run{
a722431b
MG
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';
20 my $ok;
21 if (exists $meta->{okfile}) {
22 $ok = $meta->{okfile}[$test - 1]
23 } else {
0005d3ad 24 $ok = slurp "/var/lib/gruntmasterd/pb/$meta->{problem}/$test.ok"
a722431b
MG
25 }
26
27 $out =~ s/^\s+//;
28 $ok =~ s/^\s+//;
ce50c40d
MG
29 $out =~ s/\s+/ /g;
30 $ok =~ s/\s+/ /g;
a722431b
MG
31 $out =~ s/\s+$//;
32 $ok =~ s/\s+$//;
33
34 die [WA, "Wrong answer"] if $out ne $ok;
35 $meta->{tests}[$test - 1] // 0
5c5cd38a
MG
36}
37
bc372959
MG
381;
39__END__
40
41=encoding utf-8
42
43=head1 NAME
44
45Gruntmaster::Daemon::Runner::File - Compare output with static text files
46
47=head1 SYNOPSIS
48
49 use Gruntmaster::Daemon::Runner::File;
0005d3ad 50 Gruntmaster::Daemon::Runner::File::run(5, $meta);
bc372959
MG
51
52=head1 DESCRIPTION
53
0005d3ad
MG
54Gruntmaster::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.
55
56If C<< $meta->{okfile} >> exists, the output is compared to C<< $meta->{okfile}[$test - 1] >>.
57Otherwise, the output is compared to F<< /var/lib/gruntmasterd/pb/$meta->{problem}/$test.ok >>.
58
59If the two strings match, the verdict is C<< $meta->{tests}[$test - 1] >>. Otherwise, the verdict is C<[WA, "Wrong answer"]>.
bc372959
MG
60
61=head1 AUTHOR
62
63Marius Gavrilescu E<lt>marius@ieval.roE<gt>
64
65=head1 COPYRIGHT AND LICENSE
66
67Copyright (C) 2014 by Marius Gavrilescu
68
69This library is free software: you can redistribute it and/or modify
70it under the terms of the GNU Affero General Public License as published by
71the Free Software Foundation, either version 3 of the License, or
72(at your option) any later version.
73
74
75=cut
This page took 0.045895 seconds and 4 git commands to generate.