Fix keys/values on reference experimental warnings
[gruntmaster-daemon.git] / t / 01-jobs.t
CommitLineData
5c5cd38a
MG
1#!/usr/bin/perl -w
2use v5.14;
3use strict;
4use warnings;
5
6use Gruntmaster::Daemon;
7
8use Cwd qw/cwd/;
10c4f6f5
MG
9use File::Basename qw/fileparse/;
10use File::Slurp qw/read_file/;
5c5cd38a 11use File::Temp qw/tempdir/;
7be5f054 12use Hash::Merge qw/merge/;
5c5cd38a
MG
13use List::Util qw/sum/;
14use Log::Log4perl;
15use Test::More;
16use YAML::Any qw/LoadFile/;
17
18##################################################
19
20my $loglevel = $ENV{TEST_LOG_LEVEL} // 'OFF';
21my $log_conf = <<CONF;
22log4perl.category.Gruntmaster.Daemon = $loglevel, stderr
23
24log4perl.appender.stderr = Log::Log4perl::Appender::Screen
25log4perl.appender.stderr.layout = Log::Log4perl::Layout::PatternLayout
26log4perl.appender.stderr.layout.ConversionPattern = [\%d] [\%F{1}:\%M{1}:\%L] [\%p] \%m\%n
27CONF
28Log::Log4perl->init(\$log_conf);
29
da905f9e
MG
30$ENV{PATH}.=':' . cwd;
31
5c5cd38a 32sub check_job{
7be5f054 33 my $meta = shift;
197cd6a3 34 if (defined $meta->{results}) {
759d3ca5 35 delete $meta->{results}[$_]{time} for keys %{$meta->{results}};
197cd6a3
MG
36 }
37 is $meta->{result}, $meta->{expected_result}, "Result is correct";
38 is $meta->{result_text}, $meta->{expected_result_text}, "Result text is correct";
39 is_deeply $meta->{results}, $meta->{expected_results}, "Results are correct";
5c5cd38a
MG
40}
41
42my @problems = exists $ENV{TEST_PROBLEMS} ? map {"t/problems/$_"} split ' ', $ENV{TEST_PROBLEMS} : <t/problems/*>;
43plan tests => 3 * sum map { my @temp = <$_/tests/*>; scalar @temp } @problems;
44note "Problems to be tested: " . join ', ', @problems;
45
46my $tempdir = tempdir CLEANUP => 1;
10c4f6f5
MG
47
48my $job = 0;
5c5cd38a
MG
49
50for my $problem (@problems) {
7be5f054
MG
51 my $pbmeta = LoadFile "$problem/meta.yml";
52 for (1 .. $pbmeta->{testcnt}) {
53 $pbmeta->{infile}[$_ - 1] = read_file "$problem/$_.in" if $pbmeta->{generator} eq 'File';
54 $pbmeta->{okfile}[$_ - 1] = read_file "$problem/$_.ok" if $pbmeta->{runner} eq 'File';
197cd6a3 55 }
7be5f054 56 if (exists $pbmeta->{files}) {
759d3ca5 57 $_->{content} = read_file "$problem/$_->{name}" for values %{$pbmeta->{files}}
197cd6a3 58 }
10c4f6f5 59
197cd6a3 60 TODO: {
7be5f054
MG
61 local $TODO = $pbmeta->{todo} if exists $pbmeta->{todo};
62 note "Now testing problem $pbmeta->{name} ($pbmeta->{description})";
10c4f6f5 63
197cd6a3
MG
64 for my $source (<$problem/tests/*>) {
65 my $meta = LoadFile "$source/meta.yml";
66 $meta->{files}{prog}{content} = read_file "$source/$meta->{files}{prog}{name}";
7be5f054 67 $meta = merge $meta, $pbmeta;
197cd6a3
MG
68 note "Running $meta->{test_name} ($meta->{test_description})...";
69 my $savedcwd = cwd;
70 chdir $tempdir;
7be5f054 71 Gruntmaster::Daemon::process $meta;
197cd6a3 72 chdir $savedcwd;
7be5f054 73 check_job $meta;
197cd6a3 74 }
5c5cd38a 75 }
5c5cd38a 76}
This page took 0.018559 seconds and 4 git commands to generate.