Fix purging of standings
[gruntmaster-daemon.git] / t / 01-jobs.t
CommitLineData
5c5cd38a
MG
1#!/usr/bin/perl -w
2use v5.14;
3use strict;
4use warnings;
5
6use Gruntmaster::Daemon;
7
fe29da7c 8use Cwd qw/getcwd/;
10c4f6f5
MG
9use File::Basename qw/fileparse/;
10use File::Slurp qw/read_file/;
5c5cd38a 11use File::Temp qw/tempdir/;
b8f7001a 12use File::Which qw/which/;
7be5f054 13use Hash::Merge qw/merge/;
5c5cd38a
MG
14use List::Util qw/sum/;
15use Log::Log4perl;
16use Test::More;
64871a33 17use YAML::Tiny qw/LoadFile/;
5c5cd38a
MG
18
19##################################################
20
b8f7001a 21use constant COMPILER => {
fb85e61f
S
22 qw/BRAINFUCK bfc
23 C gcc
b8f7001a 24 CPP g++
49b65824 25 D dmd
f8b954a9 26 GOLFSCRIPT golfscript
b8f7001a
MG
27 MONO gmcs
28 JAVA javac
6d1f2d94 29 JULIA julia
b8f7001a
MG
30 PASCAL fpc
31 GOLANG go
32 GCCGO gccgo
33 HASKELL ghc
34 PERL perl
8473542d 35 PHP php
92fbf933 36 PYTHON python2.7
cd0623f0 37 RUBY ruby
27be8560 38 RUST rustc
0220f51a 39 OBERON obc
34e16771 40 OCAML ocaml
c88da74d 41 SBCL sbcl/};
b8f7001a 42
6d1f2d94 43my %needs_fork = map { $_ => 1 } qw/GOLANG GOLFSCRIPT GCCGO JAVA JULIA RUBY/;
f8b954a9 44
d5200925 45my $loglevel = $ENV{TEST_LOG_LEVEL} // ($ENV{TEST_VERBOSE} ? 'TRACE' : 'OFF');
5c5cd38a
MG
46my $log_conf = <<CONF;
47log4perl.category.Gruntmaster.Daemon = $loglevel, stderr
48
49log4perl.appender.stderr = Log::Log4perl::Appender::Screen
50log4perl.appender.stderr.layout = Log::Log4perl::Layout::PatternLayout
51log4perl.appender.stderr.layout.ConversionPattern = [\%d] [\%F{1}:\%M{1}:\%L] [\%p] \%m\%n
52CONF
53Log::Log4perl->init(\$log_conf);
54
fe29da7c 55$ENV{PATH} = getcwd . ':' . $ENV{PATH};
436deb11 56umask 0022;
da905f9e 57
5c5cd38a 58sub check_job{
7be5f054 59 my $meta = shift;
197cd6a3 60 if (defined $meta->{results}) {
56187177 61 delete $meta->{results}[$_]{time} for keys @{$meta->{results}};
197cd6a3 62 }
ee638edb
MG
63 my $desc = $meta->{name} . ': ' . $meta->{test_name};
64 is $meta->{result}, $meta->{expected_result}, "Result is correct ($desc)";
65 is $meta->{result_text}, $meta->{expected_result_text}, "Result text is correct ($desc)";
66 is_deeply $meta->{results}, $meta->{expected_results}, "Results are correct ($desc)";
5c5cd38a
MG
67}
68
69my @problems = exists $ENV{TEST_PROBLEMS} ? map {"t/problems/$_"} split ' ', $ENV{TEST_PROBLEMS} : <t/problems/*>;
b8f7001a
MG
70@problems = grep { $_ !~ /hello/ } @problems unless $ENV{RELEASE_TESTING} || $ENV{TEST_PROBLEMS};
71
5c5cd38a
MG
72plan tests => 3 * sum map { my @temp = <$_/tests/*>; scalar @temp } @problems;
73note "Problems to be tested: " . join ', ', @problems;
74
23b3dc5a 75my $tempdir = tempdir "gruntmasterd-testingXXXX", TMPDIR => 1, CLEANUP => 1;
f028e0a8 76chmod 0777, $tempdir;
10c4f6f5
MG
77
78my $job = 0;
5c5cd38a
MG
79
80for my $problem (@problems) {
7be5f054
MG
81 my $pbmeta = LoadFile "$problem/meta.yml";
82 for (1 .. $pbmeta->{testcnt}) {
83 $pbmeta->{infile}[$_ - 1] = read_file "$problem/$_.in" if $pbmeta->{generator} eq 'File';
00a45f89 84 $pbmeta->{okfile}[$_ - 1] = read_file "$problem/$_.ok" if $pbmeta->{runner} && $pbmeta->{runner} eq 'File';
197cd6a3 85 }
7be5f054 86 if (exists $pbmeta->{files}) {
759d3ca5 87 $_->{content} = read_file "$problem/$_->{name}" for values %{$pbmeta->{files}}
197cd6a3 88 }
10c4f6f5 89
197cd6a3 90 TODO: {
7be5f054 91 note "Now testing problem $pbmeta->{name} ($pbmeta->{description})";
10c4f6f5 92
197cd6a3 93 for my $source (<$problem/tests/*>) {
b8f7001a
MG
94 SKIP: {
95 my $meta = LoadFile "$source/meta.yml";
fcfcfb93 96 if ($meta->{files}{prog}) {
fd807ac9
MG
97 my $format = $meta->{files}{prog}{format};
98 my $compiler = COMPILER->{$format};
fcfcfb93 99 skip "$compiler not found in path", 3 unless $ENV{GRUNTMASTER_VM} || which $compiler;
f8b954a9 100 skip "$format requires multiple processes. Set GRUNTMASTER_KILL_USER and GRUNTMASTER_SUDO to allow multiple processes.", 3 if !$ENV{GRUNTMASTER_KILL_USER} && $needs_fork{$format};
fcfcfb93
MG
101 $meta->{files}{prog}{content} = read_file "$source/$meta->{files}{prog}{name}";
102 }
b8f7001a 103 $meta = merge $meta, $pbmeta;
fd807ac9 104 local $TODO = $meta->{todo} if exists $meta->{todo};
b8f7001a 105 note "Running $meta->{test_name} ($meta->{test_description})...";
fe29da7c 106 my $savedcwd = getcwd;
b8f7001a
MG
107 chdir $tempdir;
108 Gruntmaster::Daemon::process $meta;
109 chdir $savedcwd;
110 check_job $meta;
111 }
197cd6a3 112 }
5c5cd38a 113 }
5c5cd38a 114}
This page took 0.02881 seconds and 4 git commands to generate.