Update documentation and version
[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
bc372959
MG
11our $VERSION = "5999-TRIAL";
12
5c5cd38a
MG
13##################################################
14
15sub run{
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';
ab436d78 20 my $ok = $meta->{okfile}[$test - 1];
5c5cd38a
MG
21
22 $out =~ s/^\s+//;
23 $ok =~ s/^\s+//;
24 $out =~ s/\s+/ /;
25 $ok =~ s/\s+/ /;
26 $out =~ s/\s+$//;
27 $ok =~ s/\s+$//;
28
29 die [WA, "Wrong answer"] if $out ne $ok;
30 $meta->{tests}[$test - 1] // 0
31}
32
bc372959
MG
331;
34__END__
35
36=encoding utf-8
37
38=head1 NAME
39
40Gruntmaster::Daemon::Runner::File - Compare output with static text files
41
42=head1 SYNOPSIS
43
44 use Gruntmaster::Daemon::Runner::File;
45 Gruntmaster::Daemon::Runner::File->run(5, $meta);
46
47=head1 DESCRIPTION
48
49Gruntmaster::Daemon::Runner::File is a runner which compares the program output for test C<$test> with C<< $meta->{tests}[$test - 1]>>. Before comparing, leading and trailing whitespace is removed, and sequences of whitespace are converted to a single space.
50
51=head1 AUTHOR
52
53Marius Gavrilescu E<lt>marius@ieval.roE<gt>
54
55=head1 COPYRIGHT AND LICENSE
56
57Copyright (C) 2014 by Marius Gavrilescu
58
59This library is free software: you can redistribute it and/or modify
60it under the terms of the GNU Affero General Public License as published by
61the Free Software Foundation, either version 3 of the License, or
62(at your option) any later version.
63
64
65=cut
This page took 0.013991 seconds and 4 git commands to generate.