Reindent t/01-jobs.t
[gruntmaster-daemon.git] / t / 01-jobs.t
1 #!/usr/bin/perl -w
2 use v5.14;
3 use strict;
4 use warnings;
5
6 use t::FakeData;
7 BEGIN { Gruntmaster::Data->import }
8 use Gruntmaster::Daemon;
9
10 use Cwd qw/cwd/;
11 use File::Basename qw/fileparse/;
12 use File::Slurp qw/read_file/;
13 use File::Temp qw/tempdir/;
14 use List::Util qw/sum/;
15 use Log::Log4perl;
16 use Test::More;
17 use YAML::Any qw/LoadFile/;
18
19 ##################################################
20
21 my $loglevel = $ENV{TEST_LOG_LEVEL} // 'OFF';
22 my $log_conf = <<CONF;
23 log4perl.category.Gruntmaster.Daemon = $loglevel, stderr
24
25 log4perl.appender.stderr = Log::Log4perl::Appender::Screen
26 log4perl.appender.stderr.layout = Log::Log4perl::Layout::PatternLayout
27 log4perl.appender.stderr.layout.ConversionPattern = [\%d] [\%F{1}:\%M{1}:\%L] [\%p] \%m\%n
28 CONF
29 Log::Log4perl->init(\$log_conf);
30
31 $ENV{PATH}.=':' . cwd;
32
33 sub check_job{
34 my $job = shift;
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}) {
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
48 my @problems = exists $ENV{TEST_PROBLEMS} ? map {"t/problems/$_"} split ' ', $ENV{TEST_PROBLEMS} : <t/problems/*>;
49 plan tests => 3 * sum map { my @temp = <$_/tests/*>; scalar @temp } @problems;
50 note "Problems to be tested: " . join ', ', @problems;
51
52 my $tempdir = tempdir CLEANUP => 1;
53
54 my $job = 0;
55
56 for my $problem (@problems) {
57 my $meta = LoadFile "$problem/meta.yml";
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
67 TODO: {
68 local $TODO = $meta->{todo} if exists $meta->{todo};
69 note "Now testing problem $meta->{name} ($meta->{description})";
70
71 for my $source (<$problem/tests/*>) {
72 my $meta = LoadFile "$source/meta.yml";
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;
77 note "Running $meta->{test_name} ($meta->{test_description})...";
78 my $savedcwd = cwd;
79 chdir $tempdir;
80 Gruntmaster::Daemon::process $job;
81 check_job $job;
82 chdir $savedcwd;
83 }
84 }
85 }
This page took 0.032399 seconds and 5 git commands to generate.