Move the compile and execute logic to standalone scripts
[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
da905f9e
MG
30$ENV{PATH}.=':' . cwd;
31
5c5cd38a
MG
32sub 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
43my @problems = exists $ENV{TEST_PROBLEMS} ? map {"t/problems/$_"} split ' ', $ENV{TEST_PROBLEMS} : <t/problems/*>;
44plan tests => 3 * sum map { my @temp = <$_/tests/*>; scalar @temp } @problems;
45note "Problems to be tested: " . join ', ', @problems;
46
47my $tempdir = tempdir CLEANUP => 1;
48mkdir "$tempdir/jobs";
49dircopy 't/problems' => "$tempdir/pb";
50
51for 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.015682 seconds and 4 git commands to generate.