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