Replace system() calls for 'touch' and friends with Perl ops for same.
authorDerrik Pates <demon@now.ai>
Mon, 1 Aug 2011 16:33:27 +0000 (10:33 -0600)
committerDerrik Pates <demon@now.ai>
Mon, 1 Aug 2011 16:33:27 +0000 (10:33 -0600)
If we don't need specific command functionality, we should use Perl calls
to effect the desired result. That way, we depend less on command specific
functionality, and invite less opportunity for platform-specific command
options giving us trouble.

13 files changed:
test/chmod.t
test/chown.t
test/getdir.t
test/link.t
test/mknod.t
test/open.t
test/read.t
test/rename.t
test/symlink.t
test/truncate.t
test/unlink.t
test/utime.t
test/write.t

index 366f89b..1ccb3ef 100644 (file)
@@ -3,7 +3,9 @@ use test::helper qw($_real $_point);
 use Test::More;
 plan tests => 4;
 chdir($_point);
-system("echo frog >file");
+open($file, '>', 'file');
+print $file "frog\n";
+close($file);
 ok(chmod(0644,"file"),"set unexecutable");
 ok(!-x "file","unexecutable");
 ok(chmod(0755,"file"),"set executable");
index 45a811f..74adb14 100644 (file)
@@ -6,7 +6,9 @@ plan tests => 4;
 
 my (@stat);
 chdir($_point);
-system("echo frog >file");
+open($file, '>', 'file');
+print $file "frog\n";
+close($file);
 
 SKIP: {
        skip('Need root to give away ownership', 4) unless ($UID == 0);
index 1d60561..e6d402a 100644 (file)
@@ -7,7 +7,10 @@ plan tests => 2 * scalar @names;
 chdir($_real);
 
 # create entries
-map { system("touch \"$_\"") } @names;
+foreach $fname (@names) {
+    open($file, '>', $fname);
+    close($file);
+}
 
 # make sure they exist in real dir
 opendir(REAL,$_real);
index 391b2f0..f617c93 100644 (file)
@@ -3,7 +3,9 @@ use test::helper qw($_real $_point);
 use Test::More;
 plan tests => 8;
 chdir($_point);
-system("echo hippity >womble");
+open($file, '>', 'womble');
+print $file "hippity\n";
+close($file);
 ok(-f "womble","exists");
 ok(!-f "rabbit","target file doesn't exist");
 is(-s "womble",8,"right size");
index 0edec86..c35853a 100644 (file)
@@ -4,13 +4,14 @@ use Test::More;
 plan tests => 24;
 use English;
 use Unix::Mknod qw(:all);
-use Fcntl qw(:mode);
+use Fcntl qw(S_IFCHR S_IFBLK);
 use POSIX;
 
 my (@stat);
 
 chdir($_point);
-ok(!(system("touch reg"      )>>8),"create normal file");
+ok(open($file, '>', 'reg'),"create normal file");
+close($file);
 ok(defined mkfifo($_point.'/fifo', 0600),"create fifo");
 
 chdir($_real);
index 030dc1f..b3afaf6 100644 (file)
@@ -3,7 +3,9 @@ use test::helper qw($_real $_point);
 use Test::More;
 plan tests => 1;
 chdir($_real);
-system("echo frog >file");
+open($file, '>', 'file');
+print $file "frog\n";
+close($file);
 chdir($_point);
 ok(open(FILE,"file"),"open");
 close(FILE);
index 5eca920..b4297f3 100644 (file)
@@ -3,7 +3,9 @@ use test::helper qw($_real $_point);
 use Test::More;
 plan tests => 3;
 chdir($_real);
-system("echo frog >file");
+open($file, '>','file');
+print $file "frog\n";
+close($file);
 chdir($_point);
 ok(open(FILE,"file"),"open");
 my ($data) = <FILE>;
index 9fbb330..e934173 100644 (file)
@@ -3,7 +3,9 @@ use test::helper qw($_real $_point);
 use Test::More;
 plan tests => 5;
 chdir($_point);
-system("echo hippity >frog");
+open($file, '>', 'frog');
+print $file "hippity\n";
+close($file);
 ok(-f "frog","exists");
 ok(!-f "toad","target file doesn't exist");
 ok(rename("frog","toad"),"rename");
index a17860f..f6c731e 100644 (file)
@@ -14,8 +14,11 @@ unlink("def");
 # bug: doing a 'cp -a' on a directory which contains a symlink
 # reports an error
 mkdir("dira");
-system("cd dira; touch filea; ln -s filea fileb");
+open($file, '>', 'dira/filea');
+close($file);
+symlink('filea', 'dira/fileb');
 my $cp = 'cp -a';
 if ($^O eq 'netbsd') { $cp = 'cp -R'; }
 is(system($cp . " dira dirb")>>8,0,$cp);
-system("rm -rf dira dirb");
+map { unlink($_) } ('dira/filea', 'dira/fileb', 'dirb/filea', 'dirb/fileb');
+map { rmdir($_) } ('dira', 'dirb');
index 8607421..0e9ceab 100644 (file)
@@ -3,7 +3,9 @@ use test::helper qw($_real $_point);
 use Test::More;
 plan tests => 5;
 chdir($_point);
-system("echo hippity >womble");
+open($file, '>', 'womble');
+print $file "hippity\n";
+close($file);
 ok(-f "womble","exists");
 is(-s "womble",8,"right size");
 ok(truncate("womble",4),"truncate");
index eef8c1a..85c255f 100644 (file)
@@ -3,7 +3,8 @@ use test::helper qw($_real $_point);
 use Test::More;
 plan tests => 4;
 chdir($_point);
-system("touch file");
+open($file, '>', 'file');
+close($file);
 ok(-f "file","file exists");
 chdir($_real);
 ok(-f "file","file really exists");
index 8ccefc6..e6bc7b8 100644 (file)
@@ -4,7 +4,9 @@ use Test::More;
 plan tests => 3;
 my (@stat);
 chdir($_real);
-system("echo frog >file");
+open($file, '>', 'file');
+print($file "frog\n");
+close($file);
 chdir($_point);
 ok(utime(1,2,"file"),"set utime");
 @stat = stat("file");
index 58af2aa..406a7e3 100644 (file)
@@ -6,7 +6,9 @@ my ($data);
 chdir($_point);
 undef $/; # slurp it all
 # create file
-system("echo frogbing >writefile");
+open($file, '>', 'writefile');
+print $file "frogbing\n";
+close($file);
 
 # fetch contents of file
 ok(open(FILE,"writefile"),"open");