]>
Commit | Line | Data |
---|---|---|
5c5cd38a MG |
1 | #!/usr/bin/perl -w |
2 | use v5.14; | |
3 | use strict; | |
4 | use warnings; | |
5 | ||
10c4f6f5 MG |
6 | use t::FakeData; |
7 | BEGIN { Gruntmaster::Data->import } | |
5c5cd38a MG |
8 | use Gruntmaster::Daemon; |
9 | ||
10 | use Cwd qw/cwd/; | |
10c4f6f5 MG |
11 | use File::Basename qw/fileparse/; |
12 | use File::Slurp qw/read_file/; | |
5c5cd38a MG |
13 | use File::Temp qw/tempdir/; |
14 | use List::Util qw/sum/; | |
15 | use Log::Log4perl; | |
16 | use Test::More; | |
17 | use YAML::Any qw/LoadFile/; | |
18 | ||
19 | ################################################## | |
20 | ||
21 | my $loglevel = $ENV{TEST_LOG_LEVEL} // 'OFF'; | |
22 | my $log_conf = <<CONF; | |
23 | log4perl.category.Gruntmaster.Daemon = $loglevel, stderr | |
24 | ||
25 | log4perl.appender.stderr = Log::Log4perl::Appender::Screen | |
26 | log4perl.appender.stderr.layout = Log::Log4perl::Layout::PatternLayout | |
27 | log4perl.appender.stderr.layout.ConversionPattern = [\%d] [\%F{1}:\%M{1}:\%L] [\%p] \%m\%n | |
28 | CONF | |
29 | Log::Log4perl->init(\$log_conf); | |
30 | ||
da905f9e MG |
31 | $ENV{PATH}.=':' . cwd; |
32 | ||
5c5cd38a MG |
33 | sub check_job{ |
34 | my $job = shift; | |
10c4f6f5 MG |
35 | my $jobh = get_job $job; |
36 | my $meta = job_inmeta $job; | |
37 | $meta->{result} = $jobh->{result}; | |
38 | $meta->{result_text} = $jobh->{result_text}; | |
39 | $meta->{results} = $jobh->{results}; | |
40 | if (defined $meta->{results}) { | |
5c5cd38a MG |
41 | delete $meta->{results}[$_]{time} for keys $meta->{results}; |
42 | } | |
43 | is $meta->{result}, $meta->{expected_result}, "Result is correct"; | |
44 | is $meta->{result_text}, $meta->{expected_result_text}, "Result text is correct"; | |
45 | is_deeply $meta->{results}, $meta->{expected_results}, "Results are correct"; | |
46 | } | |
47 | ||
48 | my @problems = exists $ENV{TEST_PROBLEMS} ? map {"t/problems/$_"} split ' ', $ENV{TEST_PROBLEMS} : <t/problems/*>; | |
49 | plan tests => 3 * sum map { my @temp = <$_/tests/*>; scalar @temp } @problems; | |
50 | note "Problems to be tested: " . join ', ', @problems; | |
51 | ||
52 | my $tempdir = tempdir CLEANUP => 1; | |
10c4f6f5 MG |
53 | |
54 | my $job = 0; | |
5c5cd38a MG |
55 | |
56 | for my $problem (@problems) { | |
57 | my $meta = LoadFile "$problem/meta.yml"; | |
10c4f6f5 MG |
58 | for (1 .. $meta->{testcnt}) { |
59 | $meta->{infile}[$_ - 1] = read_file "$problem/$_.in" if $meta->{generator} eq 'File'; | |
60 | $meta->{okfile}[$_ - 1] = read_file "$problem/$_.ok" if $meta->{runner} eq 'File'; | |
61 | } | |
62 | if (exists $meta->{files}) { | |
63 | $_->{content} = read_file "$problem/$_->{name}" for values $meta->{files} | |
64 | } | |
65 | set_problem_meta scalar fileparse($problem), $meta; | |
66 | ||
5c5cd38a MG |
67 | TODO: { |
68 | local $TODO = $meta->{todo} if exists $meta->{todo}; | |
69 | note "Now testing problem $meta->{name} ($meta->{description})"; | |
10c4f6f5 | 70 | |
5c5cd38a MG |
71 | for my $source (<$problem/tests/*>) { |
72 | my $meta = LoadFile "$source/meta.yml"; | |
10c4f6f5 MG |
73 | $meta->{files}{prog}{content} = read_file "$source/$meta->{files}{prog}{name}"; |
74 | $job++; | |
75 | set_job_inmeta $job, $meta; | |
76 | set_job_problem $job, scalar fileparse $problem; | |
5c5cd38a | 77 | note "Running $meta->{test_name} ($meta->{test_description})..."; |
5c5cd38a | 78 | my $savedcwd = cwd; |
10c4f6f5 MG |
79 | chdir $tempdir; |
80 | Gruntmaster::Daemon::process $job; | |
81 | check_job $job; | |
5c5cd38a | 82 | chdir $savedcwd; |
5c5cd38a MG |
83 | } |
84 | } | |
85 | } |