Move the compile and execute logic to standalone scripts
[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 Gruntmaster::Daemon;
7
8 use Cwd qw/cwd/;
9 use File::Copy qw/copy/;
10 use File::Copy::Recursive qw/dircopy/;
11 use File::Path qw/remove_tree/;
12 use File::Temp qw/tempdir/;
13 use List::Util qw/sum/;
14 use Log::Log4perl;
15 use Test::More;
16 use YAML::Any qw/LoadFile/;
17
18 ##################################################
19
20 my $loglevel = $ENV{TEST_LOG_LEVEL} // 'OFF';
21 my $log_conf = <<CONF;
22 log4perl.category.Gruntmaster.Daemon = $loglevel, stderr
23
24 log4perl.appender.stderr = Log::Log4perl::Appender::Screen
25 log4perl.appender.stderr.layout = Log::Log4perl::Layout::PatternLayout
26 log4perl.appender.stderr.layout.ConversionPattern = [\%d] [\%F{1}:\%M{1}:\%L] [\%p] \%m\%n
27 CONF
28 Log::Log4perl->init(\$log_conf);
29
30 $ENV{PATH}.=':' . cwd;
31
32 sub check_job{
33 my $job = shift;
34 my $meta = LoadFile "$job/meta.yml";
35 if (exists $meta->{results}) {
36 delete $meta->{results}[$_]{time} for keys $meta->{results};
37 }
38 is $meta->{result}, $meta->{expected_result}, "Result is correct";
39 is $meta->{result_text}, $meta->{expected_result_text}, "Result text is correct";
40 is_deeply $meta->{results}, $meta->{expected_results}, "Results are correct";
41 }
42
43 my @problems = exists $ENV{TEST_PROBLEMS} ? map {"t/problems/$_"} split ' ', $ENV{TEST_PROBLEMS} : <t/problems/*>;
44 plan tests => 3 * sum map { my @temp = <$_/tests/*>; scalar @temp } @problems;
45 note "Problems to be tested: " . join ', ', @problems;
46
47 my $tempdir = tempdir CLEANUP => 1;
48 mkdir "$tempdir/jobs";
49 dircopy 't/problems' => "$tempdir/pb";
50
51 for my $problem (@problems) {
52 my $meta = LoadFile "$problem/meta.yml";
53 TODO: {
54 local $TODO = $meta->{todo} if exists $meta->{todo};
55 note "Now testing problem $meta->{name} ($meta->{description})";
56 for my $source (<$problem/tests/*>) {
57 my $meta = LoadFile "$source/meta.yml";
58 note "Running $meta->{test_name} ($meta->{test_description})...";
59 dircopy $source => "$tempdir/jobs/job";
60 my $savedcwd = cwd;
61 Gruntmaster::Daemon::process "$tempdir/jobs/job";
62 check_job "$tempdir/log/1";
63 chdir $savedcwd;
64 remove_tree "$tempdir/log", "$tempdir/jobs", {keep_root => 1};
65 }
66 }
67 }
This page took 0.02995 seconds and 4 git commands to generate.