Hello fellow monks,
I'm trying to create a cache of objects and have them shared between test files using Test::Harness, or more specifically, TAP::Parser. I see that I can pass cmdline like args using test_args but that does not work for an object. I even tried to use freeze/thaw but that doesn't work either, in fact since this object contains a TCP/IP socket I'm afraid any serialization solution might just not be appropriated.
What I have tried was to create the cache in a module that loads the test files and them refer to that cache from the test files. The trouble seems to be that each test file "uses" this module independently, instead of keeping whatever values where set by previous test file executions.
My problem could maybe be summarized by the following code, in it, if I could get the value of $one to be updated from test file1 to test file2, then the test on file2 would not fail.
# harness.pl - Main Program
#!/usr/bin/perl
use strict;
use warnings;
use TAP::Parser;
use Tester;
Tester::main();
# Tester.pm - Loads test cases
#!/usr/bin/perl
use strict;
use warnings;
use TAP::Parser;
package Tester;
our $one = 1;
sub main {
my @test_files = qw( file1 file2 );
for my $file ( @test_files ) {
my %args = (
source => $file,
test_args => [ arg1 => 'arg1' ], # Not used for ilustr
+ation only
);
my $parser = TAP::Parser->new( \%args );
while ( my $result = $parser->next ) {
print $result->as_string, "\n";
}
}
}
sub get_one {
return $one;
}
sub set_one {
my $class = shift;
$one = shift;
}
1;
# file1 - First test case
#!/usr/bin/perl
use strict;
use warnings;
use Test::More 'no_plan';
use Tester;
Tester->set_one(1);
my $one = Tester->get_one();
Tester->set_one(2); # Try to set this for the next test
Test::More::is( $one, 1, 'One equals to one' );
# file2 - second test case (fails $one is reset to 1)
#!/usr/bin/perl
use strict;
use warnings;
use Test::More 'no_plan';
use Tester;
Tester->set_one(1);
my $one = Tester->get_one();
Tester->set_one(2); # Try to set this for the next test
Test::More::is( $one, 1, 'One equals to one' );