use strict;
use warnings;
+use t::FakeData;
+BEGIN { Gruntmaster::Data->import }
use Gruntmaster::Daemon;
use Cwd qw/cwd/;
-use File::Copy qw/copy/;
-use File::Copy::Recursive qw/dircopy/;
-use File::Path qw/remove_tree/;
+use File::Basename qw/fileparse/;
+use File::Slurp qw/read_file/;
use File::Temp qw/tempdir/;
use List::Util qw/sum/;
use Log::Log4perl;
sub check_job{
my $job = shift;
- my $meta = LoadFile "$job/meta.yml";
- if (exists $meta->{results}) {
+ my $jobh = get_job $job;
+ my $meta = job_inmeta $job;
+ $meta->{result} = $jobh->{result};
+ $meta->{result_text} = $jobh->{result_text};
+ $meta->{results} = $jobh->{results};
+ if (defined $meta->{results}) {
delete $meta->{results}[$_]{time} for keys $meta->{results};
}
is $meta->{result}, $meta->{expected_result}, "Result is correct";
note "Problems to be tested: " . join ', ', @problems;
my $tempdir = tempdir CLEANUP => 1;
-mkdir "$tempdir/jobs";
-dircopy 't/problems' => "$tempdir/pb";
+
+my $job = 0;
for my $problem (@problems) {
my $meta = LoadFile "$problem/meta.yml";
+ for (1 .. $meta->{testcnt}) {
+ $meta->{infile}[$_ - 1] = read_file "$problem/$_.in" if $meta->{generator} eq 'File';
+ $meta->{okfile}[$_ - 1] = read_file "$problem/$_.ok" if $meta->{runner} eq 'File';
+ }
+ if (exists $meta->{files}) {
+ $_->{content} = read_file "$problem/$_->{name}" for values $meta->{files}
+ }
+ set_problem_meta scalar fileparse($problem), $meta;
+
TODO: {
local $TODO = $meta->{todo} if exists $meta->{todo};
note "Now testing problem $meta->{name} ($meta->{description})";
+
for my $source (<$problem/tests/*>) {
my $meta = LoadFile "$source/meta.yml";
+ $meta->{files}{prog}{content} = read_file "$source/$meta->{files}{prog}{name}";
+ $job++;
+ set_job_inmeta $job, $meta;
+ set_job_problem $job, scalar fileparse $problem;
note "Running $meta->{test_name} ($meta->{test_description})...";
- dircopy $source => "$tempdir/jobs/job";
my $savedcwd = cwd;
- Gruntmaster::Daemon::process "$tempdir/jobs/job";
- check_job "$tempdir/log/1";
+ chdir $tempdir;
+ Gruntmaster::Daemon::process $job;
+ check_job $job;
chdir $savedcwd;
- remove_tree "$tempdir/log", "$tempdir/jobs", {keep_root => 1};
}
}
}
--- /dev/null
+package Gruntmaster::Data;
+use v5.14;
+use warnings;
+use parent qw/Exporter/;
+
+BEGIN { $INC{'Gruntmaster/Data.pm'} = 1; }
+
+my (@jobs, %problems);
+
+sub job_inmeta { $jobs[$_[0]]{inmeta} };
+sub set_job_inmeta { $jobs[$_[0]]{inmeta} = $_[1] };
+sub job_problem { $jobs[$_[0]]{problem} };
+sub set_job_problem { $jobs[$_[0]]{problem} = $_[1] };
+
+sub set_job_result { $jobs[$_[0]]{result} = $_[1] };
+sub set_job_result_text { $jobs[$_[0]]{result_text} = $_[1] };
+sub set_job_results { $jobs[$_[0]]{results} = $_[1] };
+sub set_job_errors { $jobs[$_[0]]{errors} = $_[1] };
+sub set_job_daemon { $jobs[$_[0]]{daemon} = $_[1] };
+
+sub problem_meta { $problems{$_[0]}{meta} }
+sub set_problem_meta { $problems{$_[0]}{meta} = $_[1] }
+
+sub get_job { $jobs[$_[0]] }
+
+sub PUBLISH {}
+sub SUBSCRIBE {}
+sub WAIT_FOR_MESSAGES {}
+
+our @EXPORT = do {
+ no strict 'refs';
+ grep { $_ =~ /^[a-zA-Z]/ and exists &$_ } keys %{__PACKAGE__ . '::'};
+};
+
+1