]> iEval git - gruntmaster-daemon.git/commitdiff
Revamp test suite to work with new Redis-based gruntmasterd
authorMarius Gavrilescu <marius@ieval.ro>
Fri, 31 Jan 2014 13:22:50 +0000 (15:22 +0200)
committerMarius Gavrilescu <marius@ieval.ro>
Fri, 31 Jan 2014 13:22:50 +0000 (15:22 +0200)
t/00-compile.t
t/01-jobs.t
t/FakeData.pm [new file with mode: 0644]

index 28dd755759f69d7a1f82dcaf9a5d656bc8b56ab7..038520cdf124d6223f0621111b16807648afd694 100644 (file)
@@ -4,4 +4,5 @@ use strict;
 use warnings;
 
 use Test::More tests => 1;
+use t::FakeData;
 BEGIN { use_ok('Gruntmaster::Daemon') };
index 2365b12dfab7e5097c3a85bf0bfe7a4654f0f2e7..32f299b60bb777486a9d6b1b3c7c025da4401535 100644 (file)
@@ -3,12 +3,13 @@ use v5.14;
 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;
@@ -31,8 +32,12 @@ $ENV{PATH}.=':' . cwd;
 
 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";
@@ -45,23 +50,36 @@ plan tests => 3 * sum map { my @temp = <$_/tests/*>; scalar @temp } @problems;
 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};
        }
   }
 }
diff --git a/t/FakeData.pm b/t/FakeData.pm
new file mode 100644 (file)
index 0000000..fe64241
--- /dev/null
@@ -0,0 +1,35 @@
+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
This page took 0.031596 seconds and 4 git commands to generate.