Skip to content

Skip file_put_contents_variation7.phpt on Windows #16722

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

cmb69
Copy link
Member

@cmb69 cmb69 commented Nov 7, 2024

While the test obviously succeeds on Windows, it may occasionally conflict with file_put_contents_variation7-win32.phpt[1], so we skip it like we do for many other of these tests which have win32 pendants.

[1] https://github.com/php/php-src/actions/runs/11527743659/job/32093951818


It might be a good idea to actually drop the Windows specific ext/standard/tests/file tests; or at least to reduce their number. In this case, the

tests mostly differ wrt DIRECTORY_SEPARATOR
$ diff -u file_put_contents_variation7.phpt file_put_contents_variation7-win32.phpt
--- file_put_contents_variation7.phpt   2024-11-07 13:48:03.788622800 +0100
+++ file_put_contents_variation7-win32.phpt     2022-08-31 13:34:34.558404900 +0200
@@ -4,8 +4,8 @@
 Dave Kelsey <[email protected]>
 --SKIPIF--
 <?php
-if(substr(PHP_OS, 0, 3) == "WIN")
-  die("skip Not for Windows");
+if(substr(PHP_OS, 0, 3) != "WIN")
+  die("skip Only run on Windows");
 ?>
 --FILE--
 <?php
@@ -15,31 +15,34 @@
 $subDir = "filePutContentsVar7Sub";
 $absMainDir = __DIR__."/".$mainDir;
 mkdir($absMainDir);
-$absSubDir = $absMainDir."/".$subDir;
+$absSubDir = $absMainDir."\\".$subDir;
 mkdir($absSubDir);

 $old_dir_path = getcwd();
 chdir(__DIR__);
+$unixifiedDir = '/'.substr(str_replace('\\','/',$absSubDir),3);


 // Note invalid dirs in p8 result in (The system cannot find the path specified.)
 // rather than No Such File or Directory in php.net
 $allDirs = array(
   // absolute paths
-  "$absSubDir/",
-  "$absSubDir/../".$subDir,
-  "$absSubDir//.././".$subDir,
-  "$absSubDir/../../".$mainDir."/./".$subDir,
-  "$absSubDir/..///".$subDir."//..//../".$subDir,
-  "$absSubDir/BADDIR",
+  "$absSubDir\\",
+  "$absSubDir\\..\\".$subDir,
+  "$absSubDir\\\\..\\.\\".$subDir,
+  "$absSubDir\\..\\..\\".$mainDir."\\.\\".$subDir,
+  "$absSubDir\\..\\\\\\".$subDir."\\\\..\\\\..\\".$subDir,
+  "$absSubDir\\BADDIR",

   // relative paths
-  $mainDir."/".$subDir,
-  $mainDir."//".$subDir,
-   $mainDir."///".$subDir,
-  "./".$mainDir."/../".$mainDir."/".$subDir,
+  $mainDir."\\".$subDir,
+  $mainDir."\\\\".$subDir,
+   $mainDir."\\\\\\".$subDir,
+  ".\\".$mainDir."\\..\\".$mainDir."\\".$subDir,
   "BADDIR",

+  // unixifed path
+  $unixifiedDir,
 );

 $filename = 'FileGetContentsVar7.tmp';
@@ -50,7 +53,7 @@
   $j = $i+1;
   $dir = $allDirs[$i];
   echo "\n-- Iteration $j --\n";
-  $res = file_put_contents($dir."/".$filename, ($data . $i));
+  $res = file_put_contents($dir."\\".$filename, ($data . $i));
   if ($res !== false) {
       $in = file_get_contents($absFile);
       if ($in == ($data . $i)) {
@@ -90,12 +93,12 @@

 -- Iteration 5 --

-Warning: file_put_contents(%sfilePutContentsVar7.dir/filePutContentsVar7Sub/..///filePutContentsVar7Sub//..//../filePutContentsVar7Sub/FileGetContentsVar7.tmp): Failed to open stream: %s in %s on line %d
+Warning: file_put_contents(%sfilePutContentsVar7.dir\filePutContentsVar7Sub\..\\\filePutContentsVar7Sub\\..\\..\filePutContentsVar7Sub\FileGetContentsVar7.tmp): Failed to open stream: %s in %s on line %d
 No data written

 -- Iteration 6 --

-Warning: file_put_contents(%sfilePutContentsVar7.dir/filePutContentsVar7Sub/BADDIR/FileGetContentsVar7.tmp): Failed to open stream: %s in %s on line %d
+Warning: file_put_contents(%sfilePutContentsVar7.dir\filePutContentsVar7Sub\BADDIR\FileGetContentsVar7.tmp): Failed to open stream: %s in %s on line %d
 No data written

 -- Iteration 7 --
@@ -112,7 +115,10 @@

 -- Iteration 11 --

-Warning: file_put_contents(BADDIR/FileGetContentsVar7.tmp): Failed to open stream: %s in %s on line %d
+Warning: file_put_contents(BADDIR\FileGetContentsVar7.tmp): Failed to open stream: %s in %s on line %d
 No data written

+-- Iteration 12 --
+Data written correctly
+
 *** Done ***

Windows is fine with either backslashes and slashes; if we want to be strict, we could actually use DIRECTORY_SEPARATOR.

Dropping the win32 variants would avoid that the tests differ over time. And it would help a bit to keep the test suite better manageable.

While the test obviously succeeds on Windows, it may occasionally
conflict with file_put_contents_variation7-win32.phpt[1], so we skip it
like we do for many other of these tests which have win32 pendants.

[1] <https://github.com/php/php-src/actions/runs/11527743659/job/32093951818>
@Girgias
Copy link
Member

Girgias commented Nov 8, 2024

I think dropping the windows variants where possible is the best approach IMHO.

@cmb69
Copy link
Member Author

cmb69 commented Nov 8, 2024

I think dropping the windows variants where possible is the best approach IMHO.

But maybe not for stable versions. I had master in mind (maybe PHP-8.4).

@cmb69
Copy link
Member Author

cmb69 commented Nov 18, 2024

Found the next issue: #16854. These tests need thorough review and resolutions (without having too long paths).

@cmb69 cmb69 closed this in 3656a84 Nov 20, 2024
@cmb69 cmb69 deleted the cmb/file_put_contents_variation7.phpt branch November 20, 2024 14:53
charmitro pushed a commit to wasix-org/php that referenced this pull request Mar 13, 2025
While the test obviously succeeds on Windows, it may occasionally
conflict with file_put_contents_variation7-win32.phpt[1], so we skip it
like we do for many other of these tests which have win32 pendants.

[1] <https://github.com/php/php-src/actions/runs/11527743659/job/32093951818>

Closes phpGH-16722.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants