From 331d8f488b00b0d815cf369dc0bbe4011d882e83 Mon Sep 17 00:00:00 2001 From: Derrik Pates Date: Sat, 30 Jul 2011 21:48:57 -0600 Subject: [PATCH] Change mknod test to use Unix::Mknod and POSIX::mkfifo(). Instead of using system() to call executables (and depend on mknod and mkfifo command syntax), use Unix::Mknod's mknod() function and POSIX's mkfifo() function to make device and named pipe nodes, and use Unix::Mknod's makedev() to combine major/minor numbers appropriately instead of depending on knowing (or guessing) the shift distance for the device major number. --- test/mknod.t | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/test/mknod.t b/test/mknod.t index 8ea3b46..0edec86 100644 --- a/test/mknod.t +++ b/test/mknod.t @@ -3,15 +3,15 @@ use test::helper qw($_real $_point); use Test::More; plan tests => 24; use English; - -my $maj_off = 8; -if ($^O eq 'darwin') { $maj_off = 24; } +use Unix::Mknod qw(:all); +use Fcntl qw(:mode); +use POSIX; my (@stat); chdir($_point); ok(!(system("touch reg" )>>8),"create normal file"); -ok(!(system("mkfifo fifo" )>>8),"create fifo"); +ok(defined mkfifo($_point.'/fifo', 0600),"create fifo"); chdir($_real); ok(-e "reg" ,"normal file exists"); @@ -23,8 +23,8 @@ SKIP: { skip('Need root to mknod devices', 8) unless ($UID == 0); chdir($_point); - ok(!(system("mknod chr c 2 3")>>8),"create chrdev"); - ok(!(system("mknod blk b 2 3")>>8),"create blkdev"); + ok(!mknod($_point.'/chr', 0600|S_IFCHR, makedev(2,3)),"create chrdev"); + ok(!mknod($_point.'/blk', 0600|S_IFBLK, makedev(2,3)),"create blkdev"); chdir($_real); ok(-e "chr" ,"chrdev exists"); @@ -37,9 +37,9 @@ SKIP: { ok(-b "blk" ,"blkdev is blkdev"); @stat = stat("chr"); - is($stat[6],3+(2<<$maj_off),"chrdev has right major,minor"); + is($stat[6],makedev(2,3),"chrdev has right major,minor"); @stat = stat("blk"); - is($stat[6],3+(2<<$maj_off),"blkdev has right major,minor"); + is($stat[6],makedev(2,3),"blkdev has right major,minor"); } chdir($_point); @@ -57,9 +57,9 @@ SKIP: { ok(-b "blk" ,"blkdev is blkdev"); @stat = stat("chr"); - is($stat[6],3+(2<<$maj_off),"chrdev has right major,minor"); + is($stat[6],makedev(2,3),"chrdev has right major,minor"); @stat = stat("blk"); - is($stat[6],3+(2<<$maj_off),"blkdev has right major,minor"); + is($stat[6],makedev(2,3),"blkdev has right major,minor"); } map { unlink } qw(reg chr blk fifo); -- 2.20.1