scaleway commit
[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;
99d37110 6use re '/s';
5c5cd38a
MG
7
8use Gruntmaster::Daemon::Constants qw/WA/;
1cebb7de 9use Gruntmaster::Daemon::Format qw/copy_to_vm copy_from_vm/;
5c5cd38a
MG
10use File::Slurp qw/slurp/;
11use Log::Log4perl qw/get_logger/;
12
3fa65372 13our $VERSION = '5999.000_005';
bc372959 14
5c5cd38a
MG
15##################################################
16
17sub run{
a722431b
MG
18 my ($test, $meta) = @_;
19 get_logger->trace("Running on test $test...");
1cebb7de 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/);
1cebb7de 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
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;
0005d3ad 54 Gruntmaster::Daemon::Runner::File::run(5, $meta);
bc372959
MG
55
56=head1 DESCRIPTION
57
0005d3ad
MG
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"]>.
bc372959
MG
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.023956 seconds and 4 git commands to generate.