php-src/ext/standard/tests/file/touch_basic-win32.phpt
Peter Kokot d679f02295 Sync leading and final newlines in *.phpt sections
This patch adds missing newlines, trims multiple redundant final
newlines into a single one, and trims redundant leading newlines in all
*.phpt sections.

According to POSIX, a line is a sequence of zero or more non-' <newline>'
characters plus a terminating '<newline>' character. [1] Files should
normally have at least one final newline character.

C89 [2] and later standards [3] mention a final newline:
"A source file that is not empty shall end in a new-line character,
which shall not be immediately preceded by a backslash character."

Although it is not mandatory for all files to have a final newline
fixed, a more consistent and homogeneous approach brings less of commit
differences issues and a better development experience in certain text
editors and IDEs.

[1] http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_206
[2] https://port70.net/~nsz/c/c89/c89-draft.html#2.1.1.2
[3] https://port70.net/~nsz/c/c99/n1256.html#5.1.1.2
2018-10-15 04:33:09 +02:00

95 lines
2.2 KiB
PHP

--TEST--
Test touch() function : basic functionality
--CREDITS--
Dave Kelsey <d_kelsey@uk.ibm.com>
--SKIPIF--
<?php
if (substr(PHP_OS, 0, 3) != 'WIN') {
die('skip.. only for Windows');
}
?>
--FILE--
<?php
/* Prototype : proto bool touch(string filename [, int time [, int atime]])
* Description: Set modification time of file
* Source code: ext/standard/filestat.c
* Alias to functions:
*/
echo "*** Testing touch() : basic functionality ***\n";
$filename = dirname(__FILE__)."/touch.dat";
echo "\n--- testing touch creates a file ---\n";
@unlink($filename);
if (file_exists($filename)) {
die("touch_basic failed");
}
var_dump( touch($filename) );
if (file_exists($filename) == false) {
die("touch_basic failed");
}
echo "\n --- testing touch doesn't alter file contents ---\n";
$testln = "Here is a test line";
$h = fopen($filename, "wb");
fwrite($h, $testln);
fclose($h);
touch($filename);
$h = fopen($filename, "rb");
echo fgets($h);
fclose($h);
echo "\n\n --- testing touch alters the correct file metadata ---\n";
$init_meta = stat($filename);
clearstatcache();
sleep(1);
touch($filename);
$next_meta = stat($filename);
$type = array("dev", "ino", "mode", "nlink", "uid", "gid",
"rdev", "size", "atime", "mtime", "ctime",
"blksize", "blocks");
for ($i = 0; $i < count($type); $i++) {
if ($init_meta[$i] != $next_meta[$i]) {
echo "stat data differs at $type[$i]\n";
}
}
// Initialise all required variables
$time = 10000;
$atime = 20470;
// Calling touch() with all possible arguments
echo "\n --- testing touch using all parameters ---\n";
var_dump( touch($filename, $time, $atime) );
clearstatcache();
$init_meta = stat($filename);
echo "ctime=".$init_meta['ctime']."\n";
echo "mtime=".$init_meta['mtime']."\n";
echo "atime=".$init_meta['atime']."\n";
unlink($filename);
echo "Done";
?>
--EXPECTF--
*** Testing touch() : basic functionality ***
--- testing touch creates a file ---
bool(true)
--- testing touch doesn't alter file contents ---
Here is a test line
--- testing touch alters the correct file metadata ---
stat data differs at atime
stat data differs at mtime
--- testing touch using all parameters ---
bool(true)
ctime=%d
mtime=10000
atime=20470
Done