☺唐鳳☻
and 1 contributors

NAME

Test::Builder - Backend for building test libraries

SYNOPSIS

  module My::Test::Module;

  use Test::Builder;
  use Test::Builder::Output;

  my Test::Builder $Test .= new(
        output => Test::Builder::Output.new(
               error_output => open('my_error_log_file')
        )
    );

  sub plan (Str ?$explanation, Int ?$tests) is export {
         $Test.plan($explanation, $tests);
  }

  sub ok ($passed, ?$description, ?$todo) is export {
         if $todo {
                $Test.todo($passed, $description, $todo) 
                    || $Test->diag("FAILED : $desciption");
         }
         else {
                $Test.ok($passed, $description)
                    || $Test->diag("FAILED : $desciption");
         }
  }

  sub is ($got, $expected, ?$description, ?$todo) is export {
         if $todo {
                $Test.todo($got eq $expected, $description, $todo)
                    || $Test->diag("FAILED : $desciption");             
         }
         else {
                $Test.ok($got eq $expected, $description)
                    || $Test->diag("FAILED : $desciption");             
         }
  }

  # then using our test module the test file themselves ...

  use My::Test::Module;

  plan('no_plan');
  # or
  plan :tests<20>;

  ok(2 == 2, '... 2 is equal to 2');
  is(2 + 2, 5, '... 2 plus 2 should be 5', :todo<bug>);

DESCRIPTION

This is a Perl 6 port of the Perl 5 module Test::Builder.

PUBLIC ATTRIBUTES

Test::Builder::Output $.output
Test::Builder::TestPlan $.plan

METHODS

new( *@args )

This method actually returns a Test::Builder singleton, creating it if necessary. The optional named arguments are:

output

A Test::Builder::Output object.

plan

A Test::Builder::TestPlan object.

create( *@args )

This method actually creates and returns a new Test::Builder instance. It takes the same optional named arguments as new.

plan( Str ?$explanation, Int ?$tests )

Sets the current test plan or throws an exception if there's already a plan in place. You have two options for the plan. If you pass a pair such as tests =Egt 10, the plan is to run ten tests. If you pass the string no_plan, there is no set number of tests to run.

Those are the only valid arguments.

You must have a plan set before you can record any tests.

ok returns Bit ( Bit $passed, Str ?$description = '' )

Records that a test has passed or failed, depending on the value of $passed, recording $description as an optional explanation.

todo returns Bit ( Bit $passed, Str ?$description, Str ?$reason )

Records that a test has passed or failed, depending on $passed with an optional $description, but marks it as a TODO test with an optional $reason.

skip( Int ?$num = 1, Str ?$reason = 'skipped' )

Records the skipping of $num tests (one by default), giving an optional $reason for skipping them.

skip_all()

Skips all of the tests before running them.

Fails if there is a test plan set.

BAILOUT( Str $reason = '' )

Aborts the entire test run.

report_test( Test::Builder::Test $test )

Records a test. Internal use only, probably.

SEE ALSO

Perl 5 Test::Builder.

AUTHORS

code by chromatic <chromatic@wgz.org>

documentation by Stevan Little <stevan@iinteractive.com> and chromatic.