Add Rust
[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
MG
21use constant COMPILER => {
22 qw/C gcc
23 CPP g++
f8b954a9 24 GOLFSCRIPT golfscript
b8f7001a
MG
25 MONO gmcs
26 JAVA javac
27 PASCAL fpc
28 GOLANG go
29 GCCGO gccgo
30 HASKELL ghc
31 PERL perl
c88da74d 32 PYTHON python
cd0623f0 33 RUBY ruby
27be8560 34 RUST rustc
c88da74d 35 SBCL sbcl/};
b8f7001a 36
f8b954a9
MG
37my %needs_fork = map { $_ => 1 } qw/GOLANG GOLFSCRIPT GCCGO JAVA RUBY/;
38
d5200925 39my $loglevel = $ENV{TEST_LOG_LEVEL} // ($ENV{TEST_VERBOSE} ? 'TRACE' : 'OFF');
5c5cd38a
MG
40my $log_conf = <<CONF;
41log4perl.category.Gruntmaster.Daemon = $loglevel, stderr
42
43log4perl.appender.stderr = Log::Log4perl::Appender::Screen
44log4perl.appender.stderr.layout = Log::Log4perl::Layout::PatternLayout
45log4perl.appender.stderr.layout.ConversionPattern = [\%d] [\%F{1}:\%M{1}:\%L] [\%p] \%m\%n
46CONF
47Log::Log4perl->init(\$log_conf);
48
fe29da7c 49$ENV{PATH} = getcwd . ':' . $ENV{PATH};
436deb11 50umask 0022;
da905f9e 51
5c5cd38a 52sub check_job{
7be5f054 53 my $meta = shift;
197cd6a3 54 if (defined $meta->{results}) {
56187177 55 delete $meta->{results}[$_]{time} for keys @{$meta->{results}};
197cd6a3 56 }
ee638edb
MG
57 my $desc = $meta->{name} . ': ' . $meta->{test_name};
58 is $meta->{result}, $meta->{expected_result}, "Result is correct ($desc)";
59 is $meta->{result_text}, $meta->{expected_result_text}, "Result text is correct ($desc)";
60 is_deeply $meta->{results}, $meta->{expected_results}, "Results are correct ($desc)";
5c5cd38a
MG
61}
62
63my @problems = exists $ENV{TEST_PROBLEMS} ? map {"t/problems/$_"} split ' ', $ENV{TEST_PROBLEMS} : <t/problems/*>;
b8f7001a
MG
64@problems = grep { $_ !~ /hello/ } @problems unless $ENV{RELEASE_TESTING} || $ENV{TEST_PROBLEMS};
65
5c5cd38a
MG
66plan tests => 3 * sum map { my @temp = <$_/tests/*>; scalar @temp } @problems;
67note "Problems to be tested: " . join ', ', @problems;
68
23b3dc5a 69my $tempdir = tempdir "gruntmasterd-testingXXXX", TMPDIR => 1, CLEANUP => 1;
f028e0a8 70chmod 0777, $tempdir;
10c4f6f5
MG
71
72my $job = 0;
5c5cd38a
MG
73
74for my $problem (@problems) {
7be5f054
MG
75 my $pbmeta = LoadFile "$problem/meta.yml";
76 for (1 .. $pbmeta->{testcnt}) {
77 $pbmeta->{infile}[$_ - 1] = read_file "$problem/$_.in" if $pbmeta->{generator} eq 'File';
00a45f89 78 $pbmeta->{okfile}[$_ - 1] = read_file "$problem/$_.ok" if $pbmeta->{runner} && $pbmeta->{runner} eq 'File';
197cd6a3 79 }
7be5f054 80 if (exists $pbmeta->{files}) {
759d3ca5 81 $_->{content} = read_file "$problem/$_->{name}" for values %{$pbmeta->{files}}
197cd6a3 82 }
10c4f6f5 83
197cd6a3 84 TODO: {
7be5f054 85 note "Now testing problem $pbmeta->{name} ($pbmeta->{description})";
10c4f6f5 86
197cd6a3 87 for my $source (<$problem/tests/*>) {
b8f7001a
MG
88 SKIP: {
89 my $meta = LoadFile "$source/meta.yml";
fcfcfb93 90 if ($meta->{files}{prog}) {
fd807ac9
MG
91 my $format = $meta->{files}{prog}{format};
92 my $compiler = COMPILER->{$format};
fcfcfb93 93 skip "$compiler not found in path", 3 unless $ENV{GRUNTMASTER_VM} || which $compiler;
f8b954a9 94 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
95 $meta->{files}{prog}{content} = read_file "$source/$meta->{files}{prog}{name}";
96 }
b8f7001a 97 $meta = merge $meta, $pbmeta;
fd807ac9 98 local $TODO = $meta->{todo} if exists $meta->{todo};
b8f7001a 99 note "Running $meta->{test_name} ($meta->{test_description})...";
fe29da7c 100 my $savedcwd = getcwd;
b8f7001a
MG
101 chdir $tempdir;
102 Gruntmaster::Daemon::process $meta;
103 chdir $savedcwd;
104 check_job $meta;
105 }
197cd6a3 106 }
5c5cd38a 107 }
5c5cd38a 108}
This page took 0.023563 seconds and 4 git commands to generate.