remove t/logsetup.pl and move feature into $ENV{OBJECT_REMOTE_TEST_LOGGER}; set to...
[scpubgit/Object-Remote.git] / t / transfer.t
1 use strictures 1;
2 use Test::More;
3 use Test::Fatal;
4 use FindBin;
5
6 $ENV{OBJECT_REMOTE_TEST_LOGGER} = 1;
7
8 $ENV{PERL5LIB} = join(
9   ':', ($ENV{PERL5LIB} ? $ENV{PERL5LIB} : ()), qw(lib t/lib)
10 );
11
12 use Object::Remote;
13
14 my $strA = 'foo';
15 my $strB = 'bar';
16
17 is exception {
18   my $proxy = ORTestTransfer->new::on('-', value => \$strA);
19   is_deeply $proxy->value, \$strA, 'correct value after construction';
20 }, undef, 'scalar refs - no errors during construction';
21
22 is exception {
23   my $proxy = ORTestTransfer->new::on('-');
24   $proxy->value(\$strB);
25   is_deeply $proxy->value, \$strB, 'correct value after construction';
26 }, undef, 'scalar refs - no errors during attribute set';
27
28 my $data_file = "$FindBin::Bin/data/numbers.txt";
29
30 is exception {
31   my $out = '';
32   open my $fh, '>', \$out or die "Unable to open in-memory file: $!\n";
33   my $proxy = ORTestGlobs->new::on('-', handle => $fh);
34   ok $proxy->handle, 'filehandle was set';
35   ok $proxy->write('foo'), 'write was successful';
36   is $out, 'foo', 'write reached target';
37 }, undef, 'filehandles - no error during construction';
38
39 is exception {
40   my $proxy = ORTestGlobs->new::on('-');
41   my $handle = $proxy->gethandle;
42   print $handle 'foo';
43   is $proxy->getvalue, 'foo', 'correct value written';
44   $handle->autoflush(1);
45 }, undef, 'filehandles - no error during remote handle';
46
47 is exception {
48   my $proxy = ORTestGlobs->new::on('-');
49   my $rhandle = $proxy->getreadhandle($data_file);
50   my @lines = <$rhandle>;
51   chomp @lines;
52   is_deeply \@lines, [1 .. 5], 'reading back out of the handle';
53 }, undef, 'filehandles - no error during remote read';
54
55 is exception {
56   my $proxy = ORTestGlobs->new::on('-');
57   my $rhandle = $proxy->getreadhandle($data_file);
58   binmode $rhandle;
59 }, undef, 'filehandles - no errors during binmode';
60
61 done_testing;