Change mknod test to use Unix::Mknod and POSIX::mkfifo().
[perl-fuse.git] / test / mknod.t
1 #!/usr/bin/perl
2 use test::helper qw($_real $_point);
3 use Test::More;
4 plan tests => 24;
5 use English;
6 use Unix::Mknod qw(:all);
7 use Fcntl qw(:mode);
8 use POSIX;
9
10 my (@stat);
11
12 chdir($_point);
13 ok(!(system("touch reg"      )>>8),"create normal file");
14 ok(defined mkfifo($_point.'/fifo', 0600),"create fifo");
15
16 chdir($_real);
17 ok(-e "reg" ,"normal file exists");
18 ok(-e "fifo","fifo exists");
19 ok(-f "reg" ,"normal file is normal file");
20 ok(-p "fifo","fifo is fifo");
21
22 SKIP: {
23         skip('Need root to mknod devices', 8) unless ($UID == 0);
24
25         chdir($_point);
26         ok(!mknod($_point.'/chr', 0600|S_IFCHR, makedev(2,3)),"create chrdev");
27         ok(!mknod($_point.'/blk', 0600|S_IFBLK, makedev(2,3)),"create blkdev");
28
29         chdir($_real);
30         ok(-e "chr" ,"chrdev exists");
31         ok(-e "blk" ,"blkdev exists");
32         
33         skip('mknod() is just pretend under fakeroot(1)', 4)
34           if exists $ENV{FAKEROOTKEY};
35
36         ok(-c "chr" ,"chrdev is chrdev");
37         ok(-b "blk" ,"blkdev is blkdev");
38
39         @stat = stat("chr");
40         is($stat[6],makedev(2,3),"chrdev has right major,minor");
41         @stat = stat("blk");
42         is($stat[6],makedev(2,3),"blkdev has right major,minor");
43 }
44
45 chdir($_point);
46 ok(-e "reg" ,"normal file exists");
47 ok(-e "fifo","fifo exists");
48 ok(-f "reg" ,"normal file is normal file");
49 ok(-p "fifo","fifo is fifo");
50
51 SKIP: {
52         skip('Need root to mknod devices', 6) unless ($UID == 0);
53
54         ok(-e "chr" ,"chrdev exists");
55         ok(-e "blk" ,"blkdev exists");
56         ok(-c "chr" ,"chrdev is chrdev");
57         ok(-b "blk" ,"blkdev is blkdev");
58
59         @stat = stat("chr");
60         is($stat[6],makedev(2,3),"chrdev has right major,minor");
61         @stat = stat("blk");
62         is($stat[6],makedev(2,3),"blkdev has right major,minor");
63 }
64
65 map { unlink } qw(reg chr blk fifo);