The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Test::Stream::Plugin::Core - Test::Stream implementation of the core Test::More tools.

EXPERIMENTAL CODE WARNING

This is an experimental release! Test-Stream, and all its components are still in an experimental phase. This dist has been released to cpan in order to allow testers and early adopters the chance to write experimental new tools with it, or to add experimental support for it into old tools.

PLEASE DO NOT COMPLETELY CONVERT OLD TOOLS YET. This experimental release is very likely to see a lot of code churn. API's may break at any time. Test-Stream should NOT be depended on by any toolchain level tools until the experimental phase is over.

DESCRIPTION

This is not a drop-in replacement for Test::More.

The new Testing library to replace Test::More. This library is directly built on new internals instead of Test::Builder.

This module implements most of the same functionality as Test::More, but since changing to this library from Test::More is not automatic, some incompatible API changes have been made. If you decide to replace Test::More in existing test files, you may have to update some function calls.

SYNOPSIS

    use Test::Stream qw/Core/;

    set_encoding('utf8');

    plan($num); # Optional, set a plan

    use Data::Dumper;
    imported_ok qw/Dumper/;
    not_imported_ok qw/dumper/;

    # skip all tests in some condition
    skip_all("do not run") if $cond;

    if ($passing) {
        pass('a passing test');
    }
    else {
        fail('a failing test');
    }

    ok($x, "simple test");

    # Check that the class or object has the specified methods defined.
    can_ok($class_or_obj, @methods);

    # Check that the class or object is or subclasses the specified packages
    isa_ok($class_or_obj, @packages);

    # Check that the class or object consumes the specified roles.
    DOES_ok($class_or_obj, @roles);

    # Check that $ref is a HASH reference
    ref_ok($ref, 'HASH', 'Must be a hash')

    # The preferred way to plan
    done_testing;

EXPORTS

All subs are exported by default.

ASSERTIONS

ok($bool)
ok($bool, $name)
ok($bool, $name, @diag)

Simple assertion. If $bool is true the test passes, if it is false the test fails. The test name is optional, and all arguments after the name are added as diagnostics message if and only if the test fails. If the test passes all the diagnostics arguments will be ignored.

pass()
pass($name)

Fire off a passing test (a single Ok event). The name is optional

fail()
fail($name)
fail($name, @diag)

Fire off a failing test (a single Ok event). The name and diagnostics are optional.

imported_ok(@SUB_NAMES)

Check that the specified subs have been defined in the current namespace. This will NOT find inherited subs, the subs must be in the current namespace.

not_imported_ok(@SUB_NAMES)

Check that the specified subs have NOT been defined in the current namespace. This will NOT find inherited subs, the subs must be in the current namespace.

can_ok($thing, @methods)

This checks that $thing (either a class name, or a blessed instance) has the specified methods.

isa_ok($thing, @classes)

This checks that $thing (either a class name, or a blessed instance) is or subclasses the specified classes.

DOES_ok($thing, @roles)

This checks that $thing (either a class name, or a blessed instance) does the specified roles.

ref_ok($thing)
ref_ok($thing, $type)
ref_ok($thing, $type, $name)

This checks that $thing is a reference. If $type is specified then it will check that $thing is that type of reference.

ref_is($ref1, $ref2, $name)

Verify that 2 references are the exact same reference.

ref_is_not($ref1, $ref2, $name)

Verify that 2 references are not the exact same reference.

DIAGNOSTICS

diag(@messages)

Write diagnostics messages. All items in @messages will be joined into a single string with no seperator. When using TAP diagnostics are sent to STDERR.

note(@messages)

Write note-diagnostics messages. All items in @messages will be joined into a single string with no seperator. When using TAP note-diagnostics are sent to STDOUT.

PLANNING

plan($num)

Set the number of tests that are expected. This must be done first or last, never in the middle of testing.

skip_all($reason)

Set the plan to 0 with a reason, then exit true. This should be used before any tests are run.

done_testing

Used to mark the end of testing. This is a safe way to have a dynamic or unknown number of tests.

BAIL_OUT($reason)

Something has gone horribly wrong, stop everything, kill all threads and processes, end the process with a false exit status.

META

$todo = todo($reason)
todo $reason => sub { ... }

This is used to mark some results as TODO. TODO means that the test may fail, but will not cause the overall test suite to fail.

There are 2 ways to use this, the first is to use a codeblock, the TODO will only apply to the codeblock.

    ok(1, "before"); # Not TODO

    todo 'this will fail' => sub {
        # This is TODO, as is any other test in this block.
        ok(0, "blah");
    };

    ok(1, "after"); # Not TODO

The other way is to use a scoped variable, TODO will end when the variable is destroyed or set to undef.

    ok(1, "before"); # Not TODO

    {
        my $todo = todo 'this will fail';

        # This is TODO, as is any other test in this block.
        ok(0, "blah");
    };

    ok(1, "after"); # Not TODO

This is the same thing, but without the {...} scope.

    ok(1, "before"); # Not TODO

    my $todo = todo 'this will fail';

    ok(0, "blah"); # TODO

    $todo = undef;

    ok(1, "after"); # Not TODO
skip($why)
skip($why, $count)

This is used to skip some tests. This requires you to wrap your tests in a block labeled SKIP:, this is somewhat magical. If no $count is specified then it will issue a single result. If you specify $count it will issue that many results.

    SKIP: {
        skip "This will wipe your drive";

        # This never gets run:
        ok(!system('sudo rm -rf /'), "Wipe drive");
    }
set_encoding($encoding)

This will set the encoding to whatever you specify. This will only effect the output of the current formatter, which is usually your TAP output formatter.

SEE ALSO

Test::Stream::Subtest

Subtest support

Test::Stream::Intercept

Tools for intercepting events, exceptions, warnings, etc.

Test::Stream::Tester

Tools for testing your test tools

Test::Stream::IPC

Use this module directly for more control over concurrency.

SOURCE

The source code repository for Test::Stream can be found at http://github.com/Test-More/Test-Stream/.

MAINTAINERS

Chad Granum <exodist@cpan.org>

AUTHORS

Chad Granum <exodist@cpan.org>

COPYRIGHT

Copyright 2015 Chad Granum <exodist7@gmail.com>.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

See http://www.perl.com/perl/misc/Artistic.html