Skip to content

Commit

Permalink
Make (v)fprintf tests more robust
Browse files Browse the repository at this point in the history
By using a separate file for each test. Also drop some unnecessary
SKIPIF checks for file creation. We assume that files can be created in
the test directories all over the place, so don't check for it here.
  • Loading branch information
nikic committed Feb 21, 2019
1 parent 8c2288b commit cc4c313
Show file tree
Hide file tree
Showing 21 changed files with 34 additions and 94 deletions.
9 changes: 1 addition & 8 deletions ext/standard/tests/strings/fprintf_variation_001.phpt
@@ -1,20 +1,13 @@
--TEST--
Test fprintf() function (variation - 1)
--SKIPIF--
<?php
$data_file = dirname(__FILE__) . '/dump.txt';
if (!($fp = fopen($data_file, 'w'))) {
die('skip File dump.txt could not be created');
}
?>
--FILE--
<?php

$float_variation = array( "%f","%-f", "%+f", "%7.2f", "%-7.2f", "%07.2f", "%-07.2f", "%'#7.2f" );
$float_numbers = array( 0, 1, -1, 0.32, -0.32, 3.4. -3.4, 2.54, -2.54 );

/* creating dumping file */
$data_file = dirname(__FILE__) . '/dump.txt';
$data_file = dirname(__FILE__) . '/fprintf_variation_001.txt';
if (!($fp = fopen($data_file, 'wt')))
return;

Expand Down
9 changes: 1 addition & 8 deletions ext/standard/tests/strings/fprintf_variation_002.phpt
@@ -1,20 +1,13 @@
--TEST--
Test fprintf() function (variation - 2)
--SKIPIF--
<?php
$data_file = dirname(__FILE__) . '/dump.txt';
if (!($fp = fopen($data_file, 'w'))) {
die('skip File dump.txt could not be created');
}
?>
--FILE--
<?php

$int_variation = array( "%d", "%-d", "%+d", "%7.2d", "%-7.2d", "%07.2d", "%-07.2d", "%'#7.2d" );
$int_numbers = array( 0, 1, -1, 2.7, -2.7, 23333333, -23333333, "1234" );

/* creating dumping file */
$data_file = dirname(__FILE__) . '/dump.txt';
$data_file = dirname(__FILE__) . '/fprintf_variation_002.txt';
if (!($fp = fopen($data_file, 'wt')))
return;

Expand Down
6 changes: 1 addition & 5 deletions ext/standard/tests/strings/fprintf_variation_003.phpt
Expand Up @@ -2,10 +2,6 @@
Test fprintf() function (variation - 3)
--SKIPIF--
<?php
$data_file = dirname(__FILE__) . '/dump.txt';
if (!($fp = fopen($data_file, 'w'))) {
die('skip File dump.txt could not be created');
}
if (PHP_INT_SIZE != 4) die("skip this test is for 32bit platform only");
?>
--FILE--
Expand All @@ -14,7 +10,7 @@ if (PHP_INT_SIZE != 4) die("skip this test is for 32bit platform only");
$int_numbers = array( 0, 1, -1, 2.7, -2.7, 23333333, -23333333, "1234" );

/* creating dumping file */
$data_file = dirname(__FILE__) . '/dump.txt';
$data_file = dirname(__FILE__) . '/fprintf_variation_003.txt';
if (!($fp = fopen($data_file, 'wt')))
return;

Expand Down
6 changes: 1 addition & 5 deletions ext/standard/tests/strings/fprintf_variation_003_64bit.phpt
Expand Up @@ -2,10 +2,6 @@
Test fprintf() function (variation - 3)
--SKIPIF--
<?php
$data_file = dirname(__FILE__) . '/dump.txt';
if (!($fp = fopen($data_file, 'w'))) {
die('skip File dump.txt could not be created');
}
if (PHP_INT_SIZE != 8) die("skip this test is for 64bit platform only");
?>
--FILE--
Expand All @@ -14,7 +10,7 @@ if (PHP_INT_SIZE != 8) die("skip this test is for 64bit platform only");
$int_numbers = array( 0, 1, -1, 2.7, -2.7, 23333333, -23333333, "1234" );

/* creating dumping file */
$data_file = dirname(__FILE__) . '/dump.txt';
$data_file = dirname(__FILE__) . '/fprintf_variation_003_64bit.txt';
if (!($fp = fopen($data_file, 'wt')))
return;

Expand Down
Binary file modified ext/standard/tests/strings/fprintf_variation_004.phpt
Binary file not shown.
9 changes: 1 addition & 8 deletions ext/standard/tests/strings/fprintf_variation_005.phpt
@@ -1,19 +1,12 @@
--TEST--
Test fprintf() function (variation - 5)
--SKIPIF--
<?php
$data_file = dirname(__FILE__) . '/dump.txt';
if (!($fp = fopen($data_file, 'w'))) {
die('skip File dump.txt could not be created');
}
?>
--FILE--
<?php

$int_numbers = array( 0, 1, -1, 2.7, -2.7, 23333333, -23333333, "1234" );

/* creating dumping file */
$data_file = dirname(__FILE__) . '/dump.txt';
$data_file = dirname(__FILE__) . '/fprintf_variation_005.txt';
if (!($fp = fopen($data_file, 'wt')))
return;

Expand Down
6 changes: 1 addition & 5 deletions ext/standard/tests/strings/fprintf_variation_006.phpt
Expand Up @@ -2,10 +2,6 @@
Test fprintf() function (variation - 6)
--SKIPIF--
<?php
$data_file = dirname(__FILE__) . '/dump.txt';
if (!($fp = fopen($data_file, 'w'))) {
die('skip File dump.txt could not be created');
}
if (PHP_INT_SIZE != 4) die("skip this test is for 32bit platform only");
?>
--FILE--
Expand All @@ -14,7 +10,7 @@ if (PHP_INT_SIZE != 4) die("skip this test is for 32bit platform only");
$int_numbers = array( 0, 1, -1, 2.7, -2.7, 23333333, -23333333, "1234" );

/* creating dumping file */
$data_file = dirname(__FILE__) . '/dump.txt';
$data_file = dirname(__FILE__) . '/fprintf_variation_006.txt';
if (!($fp = fopen($data_file, 'wt')))
return;

Expand Down
6 changes: 1 addition & 5 deletions ext/standard/tests/strings/fprintf_variation_006_64bit.phpt
Expand Up @@ -2,10 +2,6 @@
Test fprintf() function (variation - 6)
--SKIPIF--
<?php
$data_file = dirname(__FILE__) . '/dump.txt';
if (!($fp = fopen($data_file, 'w'))) {
die('skip File dump.txt could not be created');
}
if (PHP_INT_SIZE != 8) die("skip this test is for 64bit platform only");
?>
--FILE--
Expand All @@ -14,7 +10,7 @@ if (PHP_INT_SIZE != 8) die("skip this test is for 64bit platform only");
$int_numbers = array( 0, 1, -1, 2.7, -2.7, 23333333, -23333333, "1234" );

/* creating dumping file */
$data_file = dirname(__FILE__) . '/dump.txt';
$data_file = dirname(__FILE__) . '/fprintf_variation_006_64bit.txt';
if (!($fp = fopen($data_file, 'wt')))
return;

Expand Down
6 changes: 1 addition & 5 deletions ext/standard/tests/strings/fprintf_variation_007.phpt
Expand Up @@ -2,10 +2,6 @@
Test fprintf() function (variation - 7)
--SKIPIF--
<?php
$data_file = dirname(__FILE__) . '/dump.txt';
if (!($fp = fopen($data_file, 'w'))) {
die('skip File dump.txt could not be created');
}
if (PHP_INT_SIZE != 4) die("skip this test is for 32bit platform only");
?>
--FILE--
Expand All @@ -14,7 +10,7 @@ if (PHP_INT_SIZE != 4) die("skip this test is for 32bit platform only");
$int_numbers = array( 0, 1, -1, 2.7, -2.7, 23333333, -23333333, "1234" );

/* creating dumping file */
$data_file = dirname(__FILE__) . '/dump.txt';
$data_file = dirname(__FILE__) . '/fprintf_variation_007.txt';
if (!($fp = fopen($data_file, 'wt')))
return;

Expand Down
6 changes: 1 addition & 5 deletions ext/standard/tests/strings/fprintf_variation_007_64bit.phpt
Expand Up @@ -2,10 +2,6 @@
Test fprintf() function (variation - 7)
--SKIPIF--
<?php
$data_file = dirname(__FILE__) . '/dump.txt';
if (!($fp = fopen($data_file, 'w'))) {
die('skip File dump.txt could not be created');
}
if (PHP_INT_SIZE != 8) die("skip this test is for 64bit platform only");
?>
--FILE--
Expand All @@ -14,7 +10,7 @@ if (PHP_INT_SIZE != 8) die("skip this test is for 64bit platform only");
$int_numbers = array( 0, 1, -1, 2.7, -2.7, 23333333, -23333333, "1234" );

/* creating dumping file */
$data_file = dirname(__FILE__) . '/dump.txt';
$data_file = dirname(__FILE__) . '/fprintf_variation_007_64bit.txt';
if (!($fp = fopen($data_file, 'wt')))
return;

Expand Down
6 changes: 1 addition & 5 deletions ext/standard/tests/strings/fprintf_variation_008.phpt
Expand Up @@ -2,10 +2,6 @@
Test fprintf() function (variation - 8)
--SKIPIF--
<?php
$data_file = dirname(__FILE__) . '/dump.txt';
if (!($fp = fopen($data_file, 'w'))) {
die('skip File dump.txt could not be created');
}
if (PHP_INT_SIZE != 4) die("skip this test is for 32bit platform only");
?>
--FILE--
Expand All @@ -15,7 +11,7 @@ $int_variation = array( "%d", "%-d", "%+d", "%7.2d", "%-7.2d", "%07.2d", "%-07.2
$int_numbers = array( 0, 1, -1, 2.7, -2.7, 23333333, -23333333, "1234" );

/* creating dumping file */
$data_file = dirname(__FILE__) . '/dump.txt';
$data_file = dirname(__FILE__) . '/fprintf_variation_008.txt';
if (!($fp = fopen($data_file, 'wt')))
return;

Expand Down
6 changes: 1 addition & 5 deletions ext/standard/tests/strings/fprintf_variation_008_64bit.phpt
Expand Up @@ -2,10 +2,6 @@
Test fprintf() function (variation - 8)
--SKIPIF--
<?php
$data_file = dirname(__FILE__) . '/dump.txt';
if (!($fp = fopen($data_file, 'w'))) {
die('skip File dump.txt could not be created');
}
if (PHP_INT_SIZE != 8) die("skip this test is for 64bit platform only");
?>
--FILE--
Expand All @@ -15,7 +11,7 @@ $int_variation = array( "%d", "%-d", "%+d", "%7.2d", "%-7.2d", "%07.2d", "%-07.2
$int_numbers = array( 0, 1, -1, 2.7, -2.7, 23333333, -23333333, "1234" );

/* creating dumping file */
$data_file = dirname(__FILE__) . '/dump.txt';
$data_file = dirname(__FILE__) . '/fprintf_variation_008_64bit.txt';
if (!($fp = fopen($data_file, 'wt')))
return;

Expand Down
9 changes: 1 addition & 8 deletions ext/standard/tests/strings/fprintf_variation_009.phpt
@@ -1,20 +1,13 @@
--TEST--
Test fprintf() function (variation - 9)
--SKIPIF--
<?php
$data_file = dirname(__FILE__) . '/dump.txt';
if (!($fp = fopen($data_file, 'w'))) {
die('skip File dump.txt could not be created');
}
?>
--FILE--
<?php

$string_variation = array( "%5s", "%-5s", "%05s", "%'#5s" );
$strings = array( NULL, "abc", 'aaa' );

/* creating dumping file */
$data_file = dirname(__FILE__) . '/dump.txt';
$data_file = dirname(__FILE__) . '/fprintf_variation_009.txt';
if (!($fp = fopen($data_file, 'wt')))
return;

Expand Down
Binary file modified ext/standard/tests/strings/md5_file.phpt
Binary file not shown.
20 changes: 10 additions & 10 deletions ext/standard/tests/strings/sha1_file.phpt
Expand Up @@ -10,15 +10,15 @@ Test sha1_file() function with ASCII output and raw binary output. Based on ext/
echo "*** Testing sha1_file() : basic functionality ***\n";

/* Creating an empty file */
if (($handle = fopen( "EmptyFile.txt", "w+")) == FALSE)
if (($handle = fopen( "EmptyFileSHA1.txt", "w+")) == FALSE)
return false;

/* Creating a data file */
if (($handle2 = fopen( "DataFile.txt", "w+")) == FALSE)
if (($handle2 = fopen( "DataFileSHA1.txt", "w+")) == FALSE)
return false;

/* Writing into file */
$filename = "DataFile.txt";
$filename = "DataFileSHA1.txt";
$content = "Add this to the file\n";
if (is_writable($filename)) {
if (fwrite($handle2, $content) === FALSE) {
Expand Down Expand Up @@ -50,23 +50,23 @@ echo "\n-- Zero arguments --\n";
var_dump ( sha1_file() );

echo "\n-- More than valid number of arguments ( valid is 2) --\n";
var_dump ( sha1_file("EmptyFile.txt", true, NULL) );
var_dump ( sha1_file("EmptyFileSHA1.txt", true, NULL) );

echo "\n-- Hexadecimal Output for Empty file as Argument --\n";
var_dump( sha1_file("EmptyFile.txt") );
var_dump( sha1_file("EmptyFileSHA1.txt") );

echo "\n-- Raw Binary Output for Empty file as Argument --\n";
var_dump( bin2hex(sha1_file("EmptyFile.txt", true)));
var_dump( bin2hex(sha1_file("EmptyFileSHA1.txt", true)));

echo "\n-- Hexadecimal Output for a valid file with some contents --\n";
var_dump( sha1_file("DataFile.txt") );
var_dump( sha1_file("DataFileSHA1.txt") );

echo "\n-- Raw Binary Output for a valid file with some contents --\n";
var_dump ( bin2hex(sha1_file("DataFile.txt", true)));
var_dump ( bin2hex(sha1_file("DataFileSHA1.txt", true)));

// remove temp files
unlink("DataFile.txt");
unlink("EmptyFile.txt");
unlink("DataFileSHA1.txt");
unlink("EmptyFileSHA1.txt");

?>
===DONE===
Expand Down
4 changes: 2 additions & 2 deletions ext/standard/tests/strings/vfprintf_basic.phpt
Expand Up @@ -25,7 +25,7 @@ function writeAndDump($fp, $format, $args)
echo "*** Testing vfprintf() : basic functionality ***\n";

// Open handle
$file = 'vfprintf_test.txt';
$file = 'vfprintf_basic.txt';
$fp = fopen( $file, "a+" );

// Test vfprintf()
Expand All @@ -46,7 +46,7 @@ fclose( $fp );
--CLEAN--
<?php

$file = 'vfprintf_test.txt';
$file = 'vfprintf_basic.txt';
unlink( $file );

?>
Expand Down
4 changes: 2 additions & 2 deletions ext/standard/tests/strings/vfprintf_error1.phpt
Expand Up @@ -13,7 +13,7 @@ precision=14
*/

// Open handle
$file = 'vfprintf_test.txt';
$file = 'vfprintf_error1.txt';
$fp = fopen( $file, "a+" );

echo "\n-- Testing vfprintf() function with more than expected no. of arguments --\n";
Expand All @@ -31,7 +31,7 @@ fclose($fp);
--CLEAN--
<?php

$file = 'vfprintf_test.txt';
$file = 'vfprintf_error1.txt';
unlink( $file );

?>
Expand Down
4 changes: 2 additions & 2 deletions ext/standard/tests/strings/vfprintf_error2.phpt
Expand Up @@ -13,7 +13,7 @@ precision=14
*/

// Open handle
$file = 'vfprintf_test.txt';
$file = 'vfprintf_error2.txt';
$fp = fopen( $file, "a+" );

echo "\n-- Testing vfprintf() function with less than expected no. of arguments --\n";
Expand All @@ -30,7 +30,7 @@ fclose($fp);
--CLEAN--
<?php

$file = 'vfprintf_test.txt';
$file = 'vfprintf_error2.txt';
unlink( $file );

?>
Expand Down
4 changes: 2 additions & 2 deletions ext/standard/tests/strings/vfprintf_error3.phpt
Expand Up @@ -13,7 +13,7 @@ precision=14
*/

// Open handle
$file = 'vfprintf_test.txt';
$file = 'vfprintf_error3.txt';
$fp = fopen( $file, "a+" );

echo "\n-- Testing vfprintf() function with wrong variable types as argument --\n";
Expand All @@ -39,7 +39,7 @@ fclose( $fp );
--CLEAN--
<?php

$file = 'vfprintf_test.txt';
$file = 'vfprintf_error3.txt';
unlink( $file );

?>
Expand Down
4 changes: 2 additions & 2 deletions ext/standard/tests/strings/vfprintf_error4.phpt
Expand Up @@ -13,7 +13,7 @@ precision=14
*/

// Open handle
$file = 'vfprintf_test.txt';
$file = 'vfprintf_error4.txt';
$fp = fopen( $file, "a+" );

echo "\n-- Testing vfprintf() function with other strangeties --\n";
Expand All @@ -28,7 +28,7 @@ fclose( $fp );
--CLEAN--
<?php

$file = 'vfprintf_test.txt';
$file = 'vfprintf_error4.txt';
unlink( $file );

?>
Expand Down

0 comments on commit cc4c313

Please sign in to comment.