Test suites are important, or, How can you break sprintf()?!

petdance on 2003-02-17T02:28:57

We were about to roll out PHP 4.3.0 into production at work until my boss just stumbled across sprintf() being broken. Here's the test file that I wrote that is now in our project's test suite.
// printf/sprintf/etc broke between PHP 4.2.3 and PHP 4.3.0 // I reported it as bug #22227 // http://bugs.php.net/bug.php?id=22227 // Closed as being the same as #20108 // http://bugs.php.net/bug.php?id=20108

require( "Test.php" );

plan( 3 );

diag( "PHP Version" . phpversion() );

$masks = Array( "%-3.3s", "%.3s", "%-.3s" ); $str = "abcdefg"; foreach ( $masks as $mask ) { $result = sprintf( "[$mask]", $str ); is( $result, "[abc]", "[$mask]" ); } test_end();

?>
You'll note the similarities to Perl tests using Test::More. It's not a coincidence.

That first test breaks. It prints "[abcdefg]" instead of "[abc]". It runs fine under 4.2.3.

More importantly, why was someone mucking around with sprintf() such that it would segfault?


it's all too common

broquaint on 2003-02-17T12:47:33

More importantly, why was someone mucking around with sprintf() such that it would segfault?
The PHP team have quite a history of mucking with the fundamentals and then knocking out a release. For this reason it's usually best to wait a month or so after a new version is released before upgrading.

Also, is your testing system completely homegrown or are you using PHPUnit as well? Although some of the stuff that comes out of PEAR is rather questionable :-/

Re:it's all too common

petdance on 2003-02-17T15:56:19

It's all homegrown. I don't like the xUnit idea of having code and tests side-by-side. I made my Test.php mirror Test::More.

Plus, and most importantly for He Who Now Maintains Test::Harness, I want my PHP and Perl tests to run under the same harness.