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' );
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.