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