Initial commit
[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/;
9use File::Copy qw/copy/;
10use File::Copy::Recursive qw/dircopy/;
11use File::Path qw/remove_tree/;
12use File::Temp qw/tempdir/;
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
30sub check_job{
31 my $job = shift;
32 my $meta = LoadFile "$job/meta.yml";
33 if (exists $meta->{results}) {
34 delete $meta->{results}[$_]{time} for keys $meta->{results};
35 }
36 is $meta->{result}, $meta->{expected_result}, "Result is correct";
37 is $meta->{result_text}, $meta->{expected_result_text}, "Result text is correct";
38 is_deeply $meta->{results}, $meta->{expected_results}, "Results are correct";
39}
40
41my @problems = exists $ENV{TEST_PROBLEMS} ? map {"t/problems/$_"} split ' ', $ENV{TEST_PROBLEMS} : <t/problems/*>;
42plan tests => 3 * sum map { my @temp = <$_/tests/*>; scalar @temp } @problems;
43note "Problems to be tested: " . join ', ', @problems;
44
45my $tempdir = tempdir CLEANUP => 1;
46mkdir "$tempdir/jobs";
47dircopy 't/problems' => "$tempdir/pb";
48
49for my $problem (@problems) {
50 my $meta = LoadFile "$problem/meta.yml";
51 TODO: {
52 local $TODO = $meta->{todo} if exists $meta->{todo};
53 note "Now testing problem $meta->{name} ($meta->{description})";
54 for my $source (<$problem/tests/*>) {
55 my $meta = LoadFile "$source/meta.yml";
56 note "Running $meta->{test_name} ($meta->{test_description})...";
57 dircopy $source => "$tempdir/jobs/job";
58 my $savedcwd = cwd;
59 Gruntmaster::Daemon::process "$tempdir/jobs/job";
60 check_job "$tempdir/log/1";
61 chdir $savedcwd;
62 remove_tree "$tempdir/log", "$tempdir/jobs", {keep_root => 1};
63 }
64 }
65}
This page took 0.028142 seconds and 4 git commands to generate.