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