esharris has asked for the wisdom of the Perl Monks concerning the following question:

Why am I getting inconsistent results from "ok"? I have a perl script (which I use in a make test), where ok('','') fails. And if one of the arguments is the number 5, I get the following warning. "You named your test '5'. You shouldn't use numbers for your test names." This is my understanding of "ok". The ok routine accepts two arguments: the result from the current test and the expected result. An ok message is printed if the two arguments are equal; a not ok message is printed if they are different. So, I expected the ok call to succeed. I used h2xs to build the Perl extension skeleton. The resulting files are backward compatible with 5.8.3.
  • Comment on Understanding the Test module's "ok" subroutine

Replies are listed 'Best First'.
Re: Understanding h2xs's "ok" subroutine
by Ven'Tatsu (Deacon) on Sep 10, 2004 at 16:18 UTC
    Which testing module is being used? Test behave the way you are expecting, but Test::More and Test::Simple expect the first argument to be either true or false and the second (optional) argument to be a name for the test.
    My guess is that h2xs has the test harness using Test::More.
      You're right! I had an old h2xs that "use Test". The current h2xs "use Test::More". That's a gotcha. Thanks Again, Earl
Re: Understanding the Test module's "ok" subroutine
by petdance (Parson) on Sep 10, 2004 at 19:29 UTC
    First, don't use Test. Use Test::More. Test's ok() function is horrifyingly bad.
    • ok($x) means "Make sure $x is true"
    • ok($x,$y) means "Make sure $x is equal to $y"
    • ok($x,/$z/) means "Make sure $x matches /$z/"
    This means that you can NOT just change "use Test" to "use Test::More".

    Second, don't use h2xs any more. Use Module::Starter.

    xoxo,
    Andy