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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174
|
--TEST--
System commands tests
--SKIPIF--
<?php
if (!getenv('PHP_PEAR_RUNTESTS')) {
echo 'skip ';
}
?>
--FILE--
<?php
require_once 'System.php';
$sep = DIRECTORY_SEPARATOR;
/*******************
cat
********************/
echo "Testing: cat offline\n";
if (!function_exists('file_put_contents')) {
function file_put_contents($file, $text) {
$fd = fopen($file, 'wb');
fputs($fd, $text);
fclose($fd);
}
}
$catdir = uniqid('foobar');
$catfile = $catdir.$sep.basename(System::mktemp("-t {$catdir} tst"));
// Create temp files
$tmpfile = array();
$totalfiles = 3;
for ($i = 0; $i < $totalfiles + 1; ++$i) {
$tmpfile[] = $catdir.$sep.basename(System::mktemp("-t {$catdir} tst"));
file_put_contents($tmpfile[$i], 'FILE ' . $i);
}
// Concat in new file
for ($i = $totalfiles; $i > 0; --$i) {
$cat = '';
$expected = '';
for ($j = $i; $j > 0; --$j) {
$cat .= $tmpfile[$j] . ' ';
$expected .= 'FILE ' . $j;
}
$cat .= '> ' . $catfile;
System::cat($cat);
if (file_get_contents($catfile) != $expected) {
print "System::cat(> '$cat') failed\n";
}
}
// Concat append to file
for ($i = $totalfiles; $i > 0; --$i) {
$cat = '';
for ($j = $i; $j > 0; --$j) {
$cat .= $tmpfile[$j] . ' ';
$expected .= 'FILE ' . $j;
}
$cat .= '>> ' . $catfile;
System::cat($cat);
if (file_get_contents($catfile) != $expected) {
print "System::cat(>> '$cat') failed\n";
}
}
// Concat to string
for ($i = $totalfiles; $i > 0; --$i) {
$cat = '';
$expected = '';
for ($j = $i; $j > 0; --$j) {
$cat .= $tmpfile[$j] . ' ';
$expected .= 'FILE ' . $j;
}
if (System::cat($cat) != $expected) {
print "System::cat('$cat') failed\n";
}
}
// Concat by array to string
for ($i = $totalfiles; $i > 0; --$i) {
$cat = array();
$expected = '';
for ($j = $i; $j > 0; --$j) {
$cat[] = $tmpfile[$j];
$expected .= 'FILE ' . $j;
}
if (System::cat($cat) != $expected) {
print "System::cat(Array) failed\n";
}
}
// Concat by array in new file
for ($i = $totalfiles; $i > 0; --$i) {
$cat = array();
$expected = '';
for ($j = $i; $j > 0; --$j) {
$cat[] = $tmpfile[$j];
$expected .= 'FILE ' . $j;
}
$cat[] = '>';
$cat[] = $catfile;
System::cat($cat);
if (file_get_contents($catfile) != $expected) {
print "System::cat(Array > $catfile) failed\n";
}
}
// Concat by array append to file
for ($i = $totalfiles; $i > 0; --$i) {
$cat = array();
for ($j = $i; $j > 0; --$j) {
$cat[] = $tmpfile[$j];
$expected .= 'FILE ' . $j;
}
$cat[] = '>>';
$cat[] = $catfile;
System::cat($cat);
if (file_get_contents($catfile) != $expected) {
print "System::cat(Array >> $catfile) failed\n";
}
}
// Clean up
for ($i = 0; $i < $totalfiles + 1; ++$i) {
unlink($tmpfile[$i]);
}
unlink($catfile);
// Concat to files with space in names
$catfile1 = $catdir.$sep.basename(System::mktemp("-t {$catdir} tst"));
$catfile = $catfile1.' space in filename';
// Create temp files with space in names
$tmpfile = array();
$tmpfile1 = array();
$totalfiles = 3;
for ($i = 0; $i < $totalfiles + 1; ++$i) {
$tmpfile1[$i] = $catdir.$sep.basename(System::mktemp("-t {$catdir} tst"));
$tmpfile[$i] = $tmpfile1[$i].' space in filename';
file_put_contents($tmpfile[$i], 'FILE ' . $i);
}
// Concat by array in new file with space in names
for ($i = $totalfiles; $i > 0; --$i) {
$cat = array();
$expected = '';
for ($j = $i; $j > 0; --$j) {
$cat[] = $tmpfile[$j];
$expected .= 'FILE ' . $j;
}
$cat[] = '>';
$cat[] = $catfile;
System::cat($cat);
if (file_get_contents($catfile) != $expected) {
print "System::cat(Array > $catfile) with space in names failed\n";
}
}
// Clean up
for ($i = 0; $i < $totalfiles + 1; ++$i) {
unlink($tmpfile[$i]);
unlink($tmpfile1[$i]);
}
unlink($catfile);
unlink($catfile1);
rmdir($catdir);
print "end\n";
?>
--EXPECT--
Testing: cat offline
end
|