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