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