]> granicus.if.org Git - php/commitdiff
fix flaky zip tests, order is OS dependent
authorJoe Watkins <krakjoe@php.net>
Wed, 12 Jun 2019 07:47:47 +0000 (09:47 +0200)
committerJoe Watkins <krakjoe@php.net>
Wed, 12 Jun 2019 07:47:47 +0000 (09:47 +0200)
ext/zip/tests/bug64342_1-mb.phpt
ext/zip/tests/bug64342_1.phpt
ext/zip/tests/oo_addemptydir.phpt
ext/zip/tests/oo_addfile.phpt
ext/zip/tests/oo_addglob.phpt
ext/zip/tests/oo_addpattern.phpt
ext/zip/tests/oo_rename.phpt
ext/zip/tests/utils.inc

index 611a416253686e50f32f37f09129ef36c67a1db6..6b14c7fb5dc0293bfc2b2e83d585419537bdf4f6 100644 (file)
@@ -21,7 +21,16 @@ if (!$zip->addFile($dirname . 'cant_find_me.txt', 'test.php')) {
        echo "failed\n";
 }
 if ($zip->status == ZIPARCHIVE::ER_OK) {
-       dump_entries_name($zip);
+       if (!verify_entries($zip, [
+               "bar",
+               "foobar/",
+               "foobar/baz",
+               "entry1.txt"
+       ])) {
+               echo "failed\n";
+       } else {
+               echo "OK";
+       }
        $zip->close();
 } else {
        echo "failed\n";
@@ -30,7 +39,4 @@ if ($zip->status == ZIPARCHIVE::ER_OK) {
 ?>
 --EXPECT--
 failed
-0 bar
-1 foobar/
-2 foobar/baz
-3 entry1.txt
+OK
index 84cd5db9934d25ca92183b1d68ef8e8d05dce68c..0baf4c832efc33ba80832cbdc888ecba109ab079 100644 (file)
@@ -21,7 +21,16 @@ if (!$zip->addFile($dirname . 'cant_find_me.txt', 'test.php')) {
        echo "failed\n";
 }
 if ($zip->status == ZIPARCHIVE::ER_OK) {
-       dump_entries_name($zip);
+       if (!verify_entries($zip, [
+               "bar",
+               "foobar/",
+               "foobar/baz",
+               "entry1.txt"
+       ])) {
+               echo "failed\n";
+       } else {
+               echo "OK";
+       }
        $zip->close();
 } else {
        echo "failed\n";
@@ -30,7 +39,4 @@ if ($zip->status == ZIPARCHIVE::ER_OK) {
 ?>
 --EXPECT--
 failed
-0 bar
-1 foobar/
-2 foobar/baz
-3 entry1.txt
+OK
index e63952935d8ed63f9f03ee1107b0606dfb966d61..efaa354ecf99ca88b581375156f3574fdf120aba 100644 (file)
@@ -20,16 +20,22 @@ if (!$zip->open($file)) {
 
 $zip->addEmptyDir('emptydir');
 if ($zip->status == ZIPARCHIVE::ER_OK) {
-       dump_entries_name($zip);
+       if (!verify_entries($zip, [
+               "bar",
+               "foobar/",
+               "foobar/baz",
+               "entry1.txt",
+               "emptydir/"
+       ])) {
+               echo "failed\n";
+       } else {
+               echo "OK";
+       }
        $zip->close();
 } else {
-       echo "failed\n";
+       echo "failed3\n";
 }
 @unlink($file);
 ?>
 --EXPECT--
-0 bar
-1 foobar/
-2 foobar/baz
-3 entry1.txt
-4 emptydir/
+OK
index 7592f5b2b4313ef3348612302c2cec8d77e1d0f9..271642b6dd12056e814cacadd92ba2526f7bc4b8 100644 (file)
@@ -21,7 +21,17 @@ if (!$zip->addFile($dirname . 'utils.inc', 'test.php')) {
        echo "failed\n";
 }
 if ($zip->status == ZIPARCHIVE::ER_OK) {
-       dump_entries_name($zip);
+       if (!verify_entries($zip, [
+               "bar",
+               "foobar/",
+               "foobar/baz",
+               "entry1.txt",
+               "test.php"
+       ])) {
+               echo "failed\n";
+       } else {
+               echo "OK";
+       }
        $zip->close();
 } else {
        echo "failed\n";
@@ -29,8 +39,4 @@ if ($zip->status == ZIPARCHIVE::ER_OK) {
 @unlink($file);
 ?>
 --EXPECT--
-0 bar
-1 foobar/
-2 foobar/baz
-3 entry1.txt
-4 test.php
+OK
index 0699797a5dbe864fc03860235a91e044f57151ca..b20d4ab07a656302a4c08f10dcaa0ec74db2f8a5 100644 (file)
@@ -29,10 +29,21 @@ if (!$zip->addGlob($dirname . '*.{txt,baz}', GLOB_BRACE, $options)) {
         echo "failed1\n";
 }
 if ($zip->status == ZIPARCHIVE::ER_OK) {
-        dump_entries_name($zip);
+        if (!verify_entries($zip, [
+            "bar",
+            "foobar/",
+            "foobar/baz",
+            "entry1.txt",
+            "baz/foo.txt",
+            "baz/bar.baz"
+        ])) {
+            echo "failed\n";
+        } else {
+            echo "OK";
+        }
         $zip->close();
 } else {
-        echo "failed2\n";
+        echo "failed3\n";
 }
 ?>
 --CLEAN--
@@ -44,9 +55,4 @@ unlink($dirname . 'bar.baz');
 rmdir($dirname);
 ?>
 --EXPECT--
-0 bar
-1 foobar/
-2 foobar/baz
-3 entry1.txt
-4 baz/foo.txt
-5 baz/bar.baz
+OK
index a66ecba312f296ed0a9d43900043dd64c3c5ae96..fe1a57368df68c43349887cd12087f021ac4762c 100644 (file)
@@ -30,10 +30,21 @@ if (!$zip->addPattern('/\.txt$/', $dir, $options)) {
         echo "failed\n";
 }
 if ($zip->status == ZIPARCHIVE::ER_OK) {
-        dump_entries_name($zip);
+        if (!verify_entries($zip, [
+            "bar",
+            "foobar/",
+            "foobar/baz",
+            "entry1.txt",
+            "baz/foo.txt",
+            "baz/bar.txt"
+        ])) {
+            echo "failed\n";
+        } else {
+            echo "OK";
+        }
         $zip->close();
 } else {
-        echo "failed\n";
+        echo "failed3\n";
 }
 ?>
 --CLEAN--
@@ -45,9 +56,4 @@ unlink($dirname . 'bar.txt');
 rmdir($dirname);
 ?>
 --EXPECT--
-0 bar
-1 foobar/
-2 foobar/baz
-3 entry1.txt
-4 baz/bar.txt
-5 baz/foo.txt
+OK
index 1ec661eed2c274b269c06a75ac60403fdfdcfb99..518fe35706532c5ad8bab6f4150d83438f382cb7 100644 (file)
@@ -23,17 +23,24 @@ $zip->addFromString('dir/entry2.txt', 'entry #2');
 
 if (!$zip->status == ZIPARCHIVE::ER_OK) {
        var_dump($zip);
-       echo "failed\n";
+       echo "failed2\n";
 }
 
 $zip->close();
 
 if (!$zip->open($file)) {
-       exit('failed');
+       exit('failed3');
 }
 
-dump_entries_name($zip);
-echo "\n";
+if (!verify_entries($zip, [
+       "entry1.txt",
+    "entry2.txt",
+    "dir/entry2.txt"
+])) {
+       exit("failed4");
+} else {
+       echo "OK\n";
+}
 
 if (!$zip->renameIndex(0, 'ren_entry1.txt')) {
        echo "failed index 0\n";
@@ -42,16 +49,20 @@ if (!$zip->renameIndex(0, 'ren_entry1.txt')) {
 if (!$zip->renameName('dir/entry2.txt', 'dir3/ren_entry2.txt')) {
        echo "failed name dir/entry2.txt\n";
 }
-dump_entries_name($zip);
+
+if (!verify_entries($zip, [
+       "ren_entry1.txt",
+    "entry2.txt",
+    "dir3/ren_entry2.txt"
+])) {
+       exit("failed5");
+} else {
+       echo "OK\n";
+}
 $zip->close();
 
 @unlink($file);
 ?>
 --EXPECT--
-0 entry1.txt
-1 entry2.txt
-2 dir/entry2.txt
-
-0 ren_entry1.txt
-1 entry2.txt
-2 dir3/ren_entry2.txt
+OK
+OK
index c7cd2a8b0b7760916fa147d0c8fe7278da3f8c22..f44ab3af32c8f7370a9d4fd150e1fd3866fb1bde 100644 (file)
@@ -1,11 +1,25 @@
 <?php
+function verify_entries($zip, $entries = []) {
+    $verified = true;
+    $found    = [];
 
-function dump_entries_name($z) {
-       for($i=0; $i<$z->numFiles; $i++) {
-           $sb = $z->statIndex($i);
-           echo $i . ' ' . $sb['name'] . "\n";
-       }
+    for ($index = 0; $index < $zip->numFiles; $index++) {
+        $stat = $zip->statIndex($index);
+
+        if (!in_array($stat["name"], $entries)) {
+            $verified = false;
+        }
+        
+        $found[] = $stat["name"];
+    }
+
+    if (!$verified) {
+        var_dump($found);
+    }
+
+    return $verified;
 }
+
 /* recursively remove a directoryy */
 function rmdir_rf($dir) {
        if ($handle = opendir($dir)) {