Multiple changes for better *BSD compatibility, including:
[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
7 my $maj_off = 8;
8 if ($^O eq 'darwin') { $maj_off = 24; }
9
10 my (@stat);
11
12 chdir($_point);
13 ok(!(system("touch reg"      )>>8),"create normal file");
14 ok(!(system("mkfifo fifo"    )>>8),"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(!(system("mknod chr c 2 3")>>8),"create chrdev");
27         ok(!(system("mknod blk b 2 3")>>8),"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],3+(2<<$maj_off),"chrdev has right major,minor");
41         @stat = stat("blk");
42         is($stat[6],3+(2<<$maj_off),"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],3+(2<<$maj_off),"chrdev has right major,minor");
61         @stat = stat("blk");
62         is($stat[6],3+(2<<$maj_off),"blkdev has right major,minor");
63 }
64
65 map { unlink } qw(reg chr blk fifo);