Keeping in mind I'm not a C programmer so my user expectations may be
all wrong.


On Mon, Dec 06, 2004 at 10:00:32AM -0000, Clayton, Nik wrote:
> Then you have one of ok() or ok2() at your disposal.  ok()'s first parameter
> is the code to test.  The second parameter is the test name.  This is a 
> printf()like format string, and the third and subsequent parameters should
> fill out any values in the string.
> 
>     ok(a_func() == 0, "test name");
>     ok(some_func(i), "some_func(%d)", i);

Why add that extra auto-sprintf complexity?  Can't the user do the exact
same thing with:

        ok(some_func(i), sprintf("some_func(%d)", i));

Making the test name a sprintf string can complicate things if they want
to do formatting themselves, they have the extra problem of escaping their
result for sprintf.

Also, folks putting in bare strings might be surprised.

        ok( tax(.05), "taxing at 5%" );


> ok2() is for situations where the code to test is sufficiently 
> self-documenting that you don't need to provide a test name.
> 
>     ok2(code to test); /* test name is automatically the same as the code */
> 
> E.g.,
> 
>     ok(1 == 1, "1 equals one"); /* PRINT: ok 1 - 1 equals 1 */
>     ok2(1 == 2);                /* PRINT: not ok 2 - 1 == 2 */

Why the split?  You can do variable length argument lists in C.


> This is normally implemented with a "do { ... } while(0);" loop, with a 
> "continue;" immediately after the skip() call.  This ensures that there
> are no additional side effects from the skipped tests.
> 
>     do {
>         if(getuid() != 0) {
>             skip(1, "Test only makes sense as root");
>             continue;
>         }
> 
>         ok(do_something_as_root() == 0, "do_something_as_root() worked");
>     } while(0);

It might make more sense to do this.

        if( getuid() != 0 ) {
            skip(1, "Test only makes sense as root");
        }
        else {
            ok(do_something_as_root() == 0, "do_something_as_root() worked");
        }

I'm becoming less and less happy with the way skip is implemented in 
Test::More.


> Two macros, SKIP_START and SKIP_END can handle some of this for you.  The
> above example could be re-written:
> 
>     SKIP_START(getuid() != 0, 1, "Test only makes sense as root");
> 
>     ok(do_something_as_root() == 0, "do_something_as_root() worked");
> 
>     SKIP_END;

That's pretty cool.  Does it work with loops?  What if in that SKIP section
somebody calls a routine which then calls ok()?


> You also have diag(), which takes a printf() style format string and related
> arguments, and sends the output to stderr as a test comment.  diag() adds
> the necessary trailing "\n" for you.
> 
>     diag("Expected return code 0, got return code %d", rcode);

Don't forget about adding the # comment on the front of each line.


> Finally, there's exit_status(), which returns an int suitable for use
> when return'ing from main(), or calling exit().  You should always do one
> of:
> 
>     return exit_status();
>     exit(exit_status());

What is this for?  <--- possible C ignorance

I hope you're not emulating Test::More's exit code == # of tests failed
"feature" that I'm planning on getting rid of.


-- 
Michael G Schwern        [EMAIL PROTECTED]  http://www.pobox.com/~schwern/
michael schwern is

Reply via email to