]>
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 | ||
fe29da7c | 8 | use Cwd qw/getcwd/; |
10c4f6f5 MG |
9 | use File::Basename qw/fileparse/; |
10 | use File::Slurp qw/read_file/; | |
5c5cd38a | 11 | use File::Temp qw/tempdir/; |
b8f7001a | 12 | use File::Which qw/which/; |
7be5f054 | 13 | use Hash::Merge qw/merge/; |
5c5cd38a MG |
14 | use List::Util qw/sum/; |
15 | use Log::Log4perl; | |
16 | use Test::More; | |
64871a33 | 17 | use YAML::Tiny qw/LoadFile/; |
5c5cd38a MG |
18 | |
19 | ################################################## | |
20 | ||
b8f7001a MG |
21 | use constant COMPILER => { |
22 | qw/C gcc | |
23 | CPP g++ | |
24 | MONO gmcs | |
25 | JAVA javac | |
26 | PASCAL fpc | |
27 | GOLANG go | |
28 | GCCGO gccgo | |
29 | HASKELL ghc | |
30 | PERL perl | |
31 | PYTHON python/}; | |
32 | ||
d5200925 | 33 | my $loglevel = $ENV{TEST_LOG_LEVEL} // ($ENV{TEST_VERBOSE} ? 'TRACE' : 'OFF'); |
5c5cd38a MG |
34 | my $log_conf = <<CONF; |
35 | log4perl.category.Gruntmaster.Daemon = $loglevel, stderr | |
36 | ||
37 | log4perl.appender.stderr = Log::Log4perl::Appender::Screen | |
38 | log4perl.appender.stderr.layout = Log::Log4perl::Layout::PatternLayout | |
39 | log4perl.appender.stderr.layout.ConversionPattern = [\%d] [\%F{1}:\%M{1}:\%L] [\%p] \%m\%n | |
40 | CONF | |
41 | Log::Log4perl->init(\$log_conf); | |
42 | ||
fe29da7c | 43 | $ENV{PATH} = getcwd . ':' . $ENV{PATH}; |
436deb11 | 44 | umask 0022; |
da905f9e | 45 | |
5c5cd38a | 46 | sub check_job{ |
7be5f054 | 47 | my $meta = shift; |
197cd6a3 | 48 | if (defined $meta->{results}) { |
56187177 | 49 | delete $meta->{results}[$_]{time} for keys @{$meta->{results}}; |
197cd6a3 MG |
50 | } |
51 | is $meta->{result}, $meta->{expected_result}, "Result is correct"; | |
52 | is $meta->{result_text}, $meta->{expected_result_text}, "Result text is correct"; | |
53 | is_deeply $meta->{results}, $meta->{expected_results}, "Results are correct"; | |
5c5cd38a MG |
54 | } |
55 | ||
56 | my @problems = exists $ENV{TEST_PROBLEMS} ? map {"t/problems/$_"} split ' ', $ENV{TEST_PROBLEMS} : <t/problems/*>; | |
b8f7001a MG |
57 | @problems = grep { $_ !~ /hello/ } @problems unless $ENV{RELEASE_TESTING} || $ENV{TEST_PROBLEMS}; |
58 | ||
5c5cd38a MG |
59 | plan tests => 3 * sum map { my @temp = <$_/tests/*>; scalar @temp } @problems; |
60 | note "Problems to be tested: " . join ', ', @problems; | |
61 | ||
23b3dc5a | 62 | my $tempdir = tempdir "gruntmasterd-testingXXXX", TMPDIR => 1, CLEANUP => 1; |
f028e0a8 | 63 | chmod 0777, $tempdir; |
10c4f6f5 MG |
64 | |
65 | my $job = 0; | |
5c5cd38a MG |
66 | |
67 | for my $problem (@problems) { | |
7be5f054 MG |
68 | my $pbmeta = LoadFile "$problem/meta.yml"; |
69 | for (1 .. $pbmeta->{testcnt}) { | |
70 | $pbmeta->{infile}[$_ - 1] = read_file "$problem/$_.in" if $pbmeta->{generator} eq 'File'; | |
71 | $pbmeta->{okfile}[$_ - 1] = read_file "$problem/$_.ok" if $pbmeta->{runner} eq 'File'; | |
197cd6a3 | 72 | } |
7be5f054 | 73 | if (exists $pbmeta->{files}) { |
759d3ca5 | 74 | $_->{content} = read_file "$problem/$_->{name}" for values %{$pbmeta->{files}} |
197cd6a3 | 75 | } |
10c4f6f5 | 76 | |
197cd6a3 | 77 | TODO: { |
7be5f054 MG |
78 | local $TODO = $pbmeta->{todo} if exists $pbmeta->{todo}; |
79 | note "Now testing problem $pbmeta->{name} ($pbmeta->{description})"; | |
10c4f6f5 | 80 | |
197cd6a3 | 81 | for my $source (<$problem/tests/*>) { |
b8f7001a MG |
82 | SKIP: { |
83 | my $meta = LoadFile "$source/meta.yml"; | |
84 | my $compiler = COMPILER->{$meta->{files}{prog}{format}}; | |
85 | skip "$compiler not found in path", 3 unless $ENV{GRUNTMASTER_VM} || which $compiler; | |
86 | local $TODO = $meta->{todo} if exists $meta->{todo}; | |
87 | $meta->{files}{prog}{content} = read_file "$source/$meta->{files}{prog}{name}"; | |
88 | $meta = merge $meta, $pbmeta; | |
89 | note "Running $meta->{test_name} ($meta->{test_description})..."; | |
fe29da7c | 90 | my $savedcwd = getcwd; |
b8f7001a MG |
91 | chdir $tempdir; |
92 | Gruntmaster::Daemon::process $meta; | |
93 | chdir $savedcwd; | |
94 | check_job $meta; | |
95 | } | |
197cd6a3 | 96 | } |
5c5cd38a | 97 | } |
5c5cd38a | 98 | } |