http://www.pobox.com/~schwern/src/Test-Simple-0.30.tar.gz

I'm not putting this up on CPAN just yet, want to hear what people
think.  Dave and Mattia, try it out for your problems (Alzabo and
Parrot::Test) and see how it feels.  Let me know how it goes.


0.30  Thu Sep 27 22:10:04 EDT 2001
    * Added Test::Builder
    * Diagnostics are back to using STDERR *unless* it's from a todo
      test.  Those go to STDOUT.
    - Fixed it so nothing is printed if a test is run with a -c flag.
      Handy when a test is being deparsed with B::Deparse.

chromatic kicked off an internals rewrite and this the completion.

Test::Builder is a new module for writing other testing libraries.
People have been trying to build test libraries around Test::More
(Parrot::Test is one) and running into snags here and there.  Others
have been trying to do things that Test::More just isn't really made
to do.  Test::Builder should solve both problems.

For the first group, you can now use Test::Builder to write your test
libraries, getting most of the benefits, compatibility and snazzy
features of Test::More while being able to customize it pretty well.

For the second group, since Test::Simple and Test::More have been
gutted and are now just thin wrappers around Test::Builder, you can
grab the Test::Builder object from underneath and tweak their behavior
in ways the normal interface doesn't allow.  For example:

    use Test::Simple tests => 2;
    my $builder = Test::Builder->new;
    $builder->use_numbers(0);

    ok(1);
    ok(1);

will print

    1..2
    ok
    ok

This is perfectly kosher to do so.  I'll make that a bit more explicit
in the Test::Simple/More docs.



NAME
    Test::Builder - Backend for building test libraries

SYNOPSIS
      package My::Test::Module;
      use Test::Builder;
      require Exporter;
      @ISA = qw(Exporter);
      @EXPORT = qw(ok);

      my $Test = Test::Builder->new;
      $Test->output('my_logfile');

      sub import {
          my($self) = shift;
          my $pack = caller;

          $Test->exported_to($pack);
          $Test->plan(@_);

          $self->export_to_level(1, $self, 'ok');
      }

      sub ok {
          my($test, $name) = @_;

          $Test->ok($test, $name);
      }

DESCRIPTION
    *THIS IS ALPHA GRADE SOFTWARE* The interface will change.

    Test::Simple and Test::More have proven to be popular testing modules,
    but they're not always flexible enough. Test::Builder provides the a
    building block upon which to write your own test libraries.

  Construction

    new
          my $Test = Test::Builder->new;

        Returns a Test::Builder object representing the current state of the
        test.

        Since you only run one test per program, there is one and only one
        Test::Builder object. No matter how many times you call new(),
        you're getting the same object. (This is called a singleton).

  Setting up tests

    These methods are for setting up tests and declaring how many there are.
    You usually only want to call one of these methods.

    exported_to
          my $pack = $Test->exported_to;
          $Test->exported_to($pack);

        Tells Test::Builder what package you exported your functions to.
        This is important for getting TODO tests right.

    plan
          $Test->plan('no_plan');
          $Test->plan( skip_all => $reason );
          $Test->plan( tests => $num_tests );

        A convenient way to set up your tests. Call this and Test::Builder
        will print the appropriate headers and take the appropriate actions.

        If you call plan(), don't call any of the other methods below.

    expected_tests
            my $max = $Test->expected_tests;
            $Test->expected_tests($max);

        Gets/sets the # of tests we expect this test to run and prints out
        the appropriate headers.

    no_plan
          $Test->no_plan;

        Declares that this test will run an indeterminate # of tests.

    skip_all
          $Test->skip_all;
          $Test->skip_all($reason);

        Skips all the tests, using the given $reason. Exits immediately with
        0.

  Running tests

    These actually run the tests, analogous to the functions in Test::More.

    $name is always optional.

    ok
          $Test->ok($test, $name);

        Your basic test. Pass if $test is true, fail if $test is false. Just
        like Test::Simple's ok().

    is_eq
          $Test->is_eq($got, $expected, $name);

        Like Test::More's is(). Checks if $got eq $expected. This is the
        string version.

    is_num
          $Test->is_num($get, $expected, $name);

        Like Test::More's is(). Checks if $got == $expected. This is the
        numeric version.

    like
          $Test->like($this, qr/$regex/, $name);
          $Test->like($this, '/$regex/', $name);

        Like Test::More's like(). Checks if $this matches the given $regex.

        You'll want to avoid qr// if you want your tests to work before
        5.005.

    skip
            $Test->skip;
            $Test->skip($why);

        Skips the current test, reporting $why.

  Test style

    level
            $Test->level($how_high);

        How far up the call stack should $Test look when reporting where the
        test failed.

        Defaults to 1.

        Setting $Test::Builder::Level overrides. This is typically useful
        localized:

            {
                local $Test::Builder::Level = 2;
                $Test->ok($test);
            }

    use_numbers
            $Test->use_numbers($on_or_off);

        Whether or not the test should output numbers. That is, this if
        true:

          ok 1
          ok 2
          ok 3

        or this if false

          ok
          ok
          ok

        Most useful when you can't depend on the test output order, such as
        when threads or forking is involved.

        Test::Harness will accept either, but avoid mixing the two styles.

        Defaults to on.

  Output

    Controlling where the test output goes.

    diag
            $Test->diag(@msgs);

        Prints out the given $message. Normally, it uses the
        failure_output() handle, but if this is for a TODO test, the
        todo_output() handle is used.

        Output will be indented and prepended with a # as not to interfere
        with test output.

        We encourage using this rather than calling print directly.

    output
            $Test->output($fh);
            $Test->output($file);   # UNIMPLEMENTED

        Where normal "ok/not ok" test output should go.

        Defaults to STDOUT.

    failure_output
            $Test->failure_output($fh);
            $Test->failure_otuput($file);   # UNIMPLEMENTED

        Where diagnostic output on test failures and diag() should go.

        Defaults to STDERR.

    todo_output
            $Test->todo_output($fh);
            $Test->todo_output($file);  # UNIMPLEMENTED

        Where diagnostics about todo test failures and diag() should go.

        Defaults to STDOUT.

  Test Status and Info

    current_test
            my $curr_test = $Test->current_test;
            $Test->current_test($num);

        Gets/sets the current test # we're on.

        You usually shouldn't have to set this.

    summary
            my @tests = $Test->summary;

        A simple summary of the tests so far. True for pass, false for fail.
        This is a logical pass/fail, so todos are passes.

        Of course, test #1 is $tests[0], etc...

    details *UNIMPLEMENTED*
            my @tests = $Test->details;

        Like summary(), but with a lot more detail.

            $tests[$test_num - 1] = 
                    { ok         => is the test considered ok?
                      actual_ok  => did it literally say 'ok'?
                      name       => name of the test (if any)
                      type       => 'skip' or 'todo' (if any)
                      reason     => reason for the above (if any)
                    };

    todo
            my $todo_reason = $Test->todo;
            my $todo_reason = $Test->todo($pack);

        todo() looks for a $TODO variable in your tests. If set, all tests
        will be considered 'todo' (see Test::More and Test::Harness for
        details). Returns the reason (ie. the value of $TODO) if running as
        todo tests, false otherwise.

        todo() is pretty part about finding the right package to look for
        $TODO in. It uses the exported_to() package to find it. If that's
        not set, it's pretty good at guessing the right package to look at.

        Sometimes there is some confusion about where todo() should be
        looking for the $TODO variable. If you want to be sure, tell it
        explicitly what $pack to use.

    caller
            my $package = $Test->caller;
            my($pack, $file, $line) = $Test->caller;
            my($pack, $file, $line) = $Test->caller($height);

        Like the normal caller(), except it reports according to your
        level().

EXAMPLES
    At this point, Test::Simple and Test::More are your best examples.

AUTHOR
    Michael G Schwern <[EMAIL PROTECTED]>

SEE ALSO
    Test::Simple, Test::More, Test::Harness



-- 

Michael G. Schwern   <[EMAIL PROTECTED]>    http://www.pobox.com/~schwern/
Perl6 Quality Assurance     <[EMAIL PROTECTED]>       Kwalitee Is Job One
That which stirs me, stirs everything.
        -- Squonk Opera, "Spoon"

Reply via email to