]>
Commit | Line | Data |
---|---|---|
5c5cd38a MG |
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/; | |
10c4f6f5 MG |
9 | use File::Basename qw/fileparse/; |
10 | use File::Slurp qw/read_file/; | |
5c5cd38a | 11 | use File::Temp qw/tempdir/; |
7be5f054 | 12 | use Hash::Merge qw/merge/; |
5c5cd38a MG |
13 | use List::Util qw/sum/; |
14 | use Log::Log4perl; | |
15 | use Test::More; | |
16 | use YAML::Any qw/LoadFile/; | |
17 | ||
18 | ################################################## | |
19 | ||
d5200925 | 20 | my $loglevel = $ENV{TEST_LOG_LEVEL} // ($ENV{TEST_VERBOSE} ? 'TRACE' : 'OFF'); |
5c5cd38a MG |
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 | ||
59fd7176 | 30 | $ENV{PATH} = cwd . ':' . $ENV{PATH}; |
436deb11 | 31 | umask 0022; |
da905f9e | 32 | |
5c5cd38a | 33 | sub check_job{ |
7be5f054 | 34 | my $meta = shift; |
197cd6a3 | 35 | if (defined $meta->{results}) { |
56187177 | 36 | delete $meta->{results}[$_]{time} for keys @{$meta->{results}}; |
197cd6a3 MG |
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"; | |
5c5cd38a MG |
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 | ||
1b82f62b | 47 | my $tempdir = tempdir "gruntmaster-daemon-testingXXXX", TMPDIR => 1, CLEANUP => 1; |
f028e0a8 | 48 | chmod 0777, $tempdir; |
10c4f6f5 MG |
49 | |
50 | my $job = 0; | |
5c5cd38a MG |
51 | |
52 | for my $problem (@problems) { | |
7be5f054 MG |
53 | my $pbmeta = LoadFile "$problem/meta.yml"; |
54 | for (1 .. $pbmeta->{testcnt}) { | |
55 | $pbmeta->{infile}[$_ - 1] = read_file "$problem/$_.in" if $pbmeta->{generator} eq 'File'; | |
56 | $pbmeta->{okfile}[$_ - 1] = read_file "$problem/$_.ok" if $pbmeta->{runner} eq 'File'; | |
197cd6a3 | 57 | } |
7be5f054 | 58 | if (exists $pbmeta->{files}) { |
759d3ca5 | 59 | $_->{content} = read_file "$problem/$_->{name}" for values %{$pbmeta->{files}} |
197cd6a3 | 60 | } |
10c4f6f5 | 61 | |
197cd6a3 | 62 | TODO: { |
7be5f054 MG |
63 | local $TODO = $pbmeta->{todo} if exists $pbmeta->{todo}; |
64 | note "Now testing problem $pbmeta->{name} ($pbmeta->{description})"; | |
10c4f6f5 | 65 | |
197cd6a3 MG |
66 | for my $source (<$problem/tests/*>) { |
67 | my $meta = LoadFile "$source/meta.yml"; | |
68 | $meta->{files}{prog}{content} = read_file "$source/$meta->{files}{prog}{name}"; | |
7be5f054 | 69 | $meta = merge $meta, $pbmeta; |
197cd6a3 MG |
70 | note "Running $meta->{test_name} ($meta->{test_description})..."; |
71 | my $savedcwd = cwd; | |
72 | chdir $tempdir; | |
7be5f054 | 73 | Gruntmaster::Daemon::process $meta; |
197cd6a3 | 74 | chdir $savedcwd; |
7be5f054 | 75 | check_job $meta; |
197cd6a3 | 76 | } |
5c5cd38a | 77 | } |
5c5cd38a | 78 | } |