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