Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

petdance (2468)

AOL IM: petdance (Add Buddy, Send Message)
Yahoo! ID: petdance (Add User, Send Message)

I'm Andy Lester, and I like to test stuff. I also write for the Perl Journal, and do tech edits on books. Sometimes I write code, too.

Journal of petdance (2468)

Sunday February 16, 2003
09:28 PM

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

[ #10622 ]
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
// Closed as being the same as #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]" );


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?

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • 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 :-/


    broquaint out

    • 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.