From 10c4f6f5ac0c8a3d3462416fd7e2f3ce62e72788 Mon Sep 17 00:00:00 2001 From: Marius Gavrilescu Date: Fri, 31 Jan 2014 15:22:50 +0200 Subject: [PATCH] Revamp test suite to work with new Redis-based gruntmasterd --- t/00-compile.t | 1 + t/01-jobs.t | 40 +++++++++++++++++++++++++++++----------- t/FakeData.pm | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 65 insertions(+), 11 deletions(-) create mode 100644 t/FakeData.pm diff --git a/t/00-compile.t b/t/00-compile.t index 28dd755..038520c 100644 --- a/t/00-compile.t +++ b/t/00-compile.t @@ -4,4 +4,5 @@ use strict; use warnings; use Test::More tests => 1; +use t::FakeData; BEGIN { use_ok('Gruntmaster::Daemon') }; diff --git a/t/01-jobs.t b/t/01-jobs.t index 2365b12..32f299b 100644 --- a/t/01-jobs.t +++ b/t/01-jobs.t @@ -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 index 0000000..fe64241 --- /dev/null +++ b/t/FakeData.pm @@ -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 -- 2.39.2