]>
Commit | Line | Data |
---|---|---|
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::Basename qw/fileparse/; | |
10 | use File::Slurp qw/read_file/; | |
11 | use File::Temp qw/tempdir/; | |
12 | use Hash::Merge qw/merge/; | |
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 $meta = shift; | |
34 | if (defined $meta->{results}) { | |
35 | delete $meta->{results}[$_]{time} for keys %{$meta->{results}}; | |
36 | } | |
37 | is $meta->{result}, $meta->{expected_result}, "Result is correct"; | |
38 | is $meta->{result_text}, $meta->{expected_result_text}, "Result text is correct"; | |
39 | is_deeply $meta->{results}, $meta->{expected_results}, "Results are correct"; | |
40 | } | |
41 | ||
42 | my @problems = exists $ENV{TEST_PROBLEMS} ? map {"t/problems/$_"} split ' ', $ENV{TEST_PROBLEMS} : <t/problems/*>; | |
43 | plan tests => 3 * sum map { my @temp = <$_/tests/*>; scalar @temp } @problems; | |
44 | note "Problems to be tested: " . join ', ', @problems; | |
45 | ||
46 | my $tempdir = tempdir CLEANUP => 1; | |
47 | ||
48 | my $job = 0; | |
49 | ||
50 | for my $problem (@problems) { | |
51 | my $pbmeta = LoadFile "$problem/meta.yml"; | |
52 | for (1 .. $pbmeta->{testcnt}) { | |
53 | $pbmeta->{infile}[$_ - 1] = read_file "$problem/$_.in" if $pbmeta->{generator} eq 'File'; | |
54 | $pbmeta->{okfile}[$_ - 1] = read_file "$problem/$_.ok" if $pbmeta->{runner} eq 'File'; | |
55 | } | |
56 | if (exists $pbmeta->{files}) { | |
57 | $_->{content} = read_file "$problem/$_->{name}" for values %{$pbmeta->{files}} | |
58 | } | |
59 | ||
60 | TODO: { | |
61 | local $TODO = $pbmeta->{todo} if exists $pbmeta->{todo}; | |
62 | note "Now testing problem $pbmeta->{name} ($pbmeta->{description})"; | |
63 | ||
64 | for my $source (<$problem/tests/*>) { | |
65 | my $meta = LoadFile "$source/meta.yml"; | |
66 | $meta->{files}{prog}{content} = read_file "$source/$meta->{files}{prog}{name}"; | |
67 | $meta = merge $meta, $pbmeta; | |
68 | note "Running $meta->{test_name} ($meta->{test_description})..."; | |
69 | my $savedcwd = cwd; | |
70 | chdir $tempdir; | |
71 | Gruntmaster::Daemon::process $meta; | |
72 | chdir $savedcwd; | |
73 | check_job $meta; | |
74 | } | |
75 | } | |
76 | } |