commit
[gruntmaster-daemon.git] / lib / Gruntmaster / Daemon / Runner / File.pm
1 package Gruntmaster::Daemon::Runner::File;
2
3 use 5.014000;
4 use strict;
5 use warnings;
6 use re '/s';
7
8 use Gruntmaster::Daemon::Constants qw/WA/;
9 use Gruntmaster::Daemon::Format qw/copy_to_vm copy_from_vm/;
10 use File::Slurp qw/slurp/;
11 use Log::Log4perl qw/get_logger/;
12
13 our $VERSION = '5999.000_005';
14
15 ##################################################
16
17 sub 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
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;
54 Gruntmaster::Daemon::Runner::File::run(5, $meta);
55
56 =head1 DESCRIPTION
57
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"]>.
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
This page took 0.025078 seconds and 4 git commands to generate.