File: 10_object.t

package info (click to toggle)
libarchive-ar-perl 2.02-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 160 kB
  • ctags: 36
  • sloc: perl: 421; makefile: 2
file content (33 lines) | stat: -rw-r--r-- 785 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
use strict;
use warnings;

use Test::More tests => 6;
use Test::MockObject;

use IO::Handle;

use Archive::Ar;

my $mock = new Test::MockObject;
my $ar;

$mock->set_false('read');
local *Archive::Ar::read;
*Archive::Ar::read = sub { return $mock->read(); };

$ar = Archive::Ar->new();
isa_ok $ar, 'Archive::Ar', 'object';
ok !$mock->called('read'), 'read not called if new with no options';

$ar = Archive::Ar->new('myfilename');
is $ar, undef, 'new fails if read fails';
ok $mock->called('read'), 'read called if new with filename';
$mock->clear();

$ar = new Archive::Ar(*STDIN);
ok $mock->called('read'), 'read called if new with file glob';
$mock->clear();

$ar = new Archive::Ar(IO::Handle->new());
ok $mock->called('read'), 'read called if new with file handle';
$mock->clear();