]> iEval git - gruntmaster-daemon.git/blame_incremental - t/01-jobs.t
Add ruby
[gruntmaster-daemon.git] / t / 01-jobs.t
... / ...
CommitLineData
1#!/usr/bin/perl -w
2use v5.14;
3use strict;
4use warnings;
5
6use Gruntmaster::Daemon;
7
8use Cwd qw/getcwd/;
9use File::Basename qw/fileparse/;
10use File::Slurp qw/read_file/;
11use File::Temp qw/tempdir/;
12use File::Which qw/which/;
13use Hash::Merge qw/merge/;
14use List::Util qw/sum/;
15use Log::Log4perl;
16use Test::More;
17use YAML::Tiny qw/LoadFile/;
18
19##################################################
20
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
31 PYTHON python
32 SBCL sbcl/};
33
34my $loglevel = $ENV{TEST_LOG_LEVEL} // ($ENV{TEST_VERBOSE} ? 'TRACE' : 'OFF');
35my $log_conf = <<CONF;
36log4perl.category.Gruntmaster.Daemon = $loglevel, stderr
37
38log4perl.appender.stderr = Log::Log4perl::Appender::Screen
39log4perl.appender.stderr.layout = Log::Log4perl::Layout::PatternLayout
40log4perl.appender.stderr.layout.ConversionPattern = [\%d] [\%F{1}:\%M{1}:\%L] [\%p] \%m\%n
41CONF
42Log::Log4perl->init(\$log_conf);
43
44$ENV{PATH} = getcwd . ':' . $ENV{PATH};
45umask 0022;
46
47sub check_job{
48 my $meta = shift;
49 if (defined $meta->{results}) {
50 delete $meta->{results}[$_]{time} for keys @{$meta->{results}};
51 }
52 my $desc = $meta->{name} . ': ' . $meta->{test_name};
53 is $meta->{result}, $meta->{expected_result}, "Result is correct ($desc)";
54 is $meta->{result_text}, $meta->{expected_result_text}, "Result text is correct ($desc)";
55 is_deeply $meta->{results}, $meta->{expected_results}, "Results are correct ($desc)";
56}
57
58my @problems = exists $ENV{TEST_PROBLEMS} ? map {"t/problems/$_"} split ' ', $ENV{TEST_PROBLEMS} : <t/problems/*>;
59@problems = grep { $_ !~ /hello/ } @problems unless $ENV{RELEASE_TESTING} || $ENV{TEST_PROBLEMS};
60
61plan tests => 3 * sum map { my @temp = <$_/tests/*>; scalar @temp } @problems;
62note "Problems to be tested: " . join ', ', @problems;
63
64my $tempdir = tempdir "gruntmasterd-testingXXXX", TMPDIR => 1, CLEANUP => 1;
65chmod 0777, $tempdir;
66
67my $job = 0;
68
69for my $problem (@problems) {
70 my $pbmeta = LoadFile "$problem/meta.yml";
71 for (1 .. $pbmeta->{testcnt}) {
72 $pbmeta->{infile}[$_ - 1] = read_file "$problem/$_.in" if $pbmeta->{generator} eq 'File';
73 $pbmeta->{okfile}[$_ - 1] = read_file "$problem/$_.ok" if $pbmeta->{runner} && $pbmeta->{runner} eq 'File';
74 }
75 if (exists $pbmeta->{files}) {
76 $_->{content} = read_file "$problem/$_->{name}" for values %{$pbmeta->{files}}
77 }
78
79 TODO: {
80 note "Now testing problem $pbmeta->{name} ($pbmeta->{description})";
81
82 for my $source (<$problem/tests/*>) {
83 SKIP: {
84 my $meta = LoadFile "$source/meta.yml";
85 if ($meta->{files}{prog}) {
86 my $format = $meta->{files}{prog}{format};
87 my $compiler = COMPILER->{$format};
88 skip "$compiler not found in path", 3 unless $ENV{GRUNTMASTER_VM} || which $compiler;
89 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';
90 $meta->{files}{prog}{content} = read_file "$source/$meta->{files}{prog}{name}";
91 }
92 $meta = merge $meta, $pbmeta;
93 local $TODO = $meta->{todo} if exists $meta->{todo};
94 note "Running $meta->{test_name} ($meta->{test_description})...";
95 my $savedcwd = getcwd;
96 chdir $tempdir;
97 Gruntmaster::Daemon::process $meta;
98 chdir $savedcwd;
99 check_job $meta;
100 }
101 }
102 }
103}
This page took 0.022924 seconds and 4 git commands to generate.