File: 20new.t

package info (click to toggle)
libarchive-ar-perl 1.13b-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 56 kB
  • ctags: 25
  • sloc: perl: 370; makefile: 43
file content (46 lines) | stat: -rw-r--r-- 1,175 bytes parent folder | download | duplicates (2)
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
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/perl -w

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

BEGIN {
        chdir 't' if -d 't';
        use lib '../blib/lib', 'lib/', '..';
}

my $mod = "Archive::Ar";
my $mock = new Test::MockObject;
my $ar;

use_ok($mod);
can_ok($mod, "new");


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

ok($ar = new Archive::Ar, "The new operator without any arguments should always succeed");
ok($ar = Archive::Ar->new(), "Class-method new() without any arguments");
ok(!$mock->called("read"), "Archive::Ar's read() shouldn't be called if there are no arguments");

$ar = new Archive::Ar("myfilename");

ok(!$ar, "The new operator with a filename should fail if read fails");
ok($mock->called("read"), "Object creation should call read() if it is given a filename");
$mock->clear();

my $GLOB = *STDIN;
$ar = new Archive::Ar($GLOB);

ok(!$ar, "The new operator with a GLOB should fail if read fails");
ok($mock->called("read"), "Object creation should call read() if it is given a file GLOB");



# The rest will have to be done with integration tests, as there is no good fake filesystem mod

$mock->clear();