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