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