2 Test::Leaner - A slimmer Test::More for when you favor performance over
9 use Test::Leaner tests => 10_000;
12 is $one, 1, "checking situation $_";
16 When profiling some Test::More-based test script that contained about 10
17 000 unit tests, I realized that 60% of the time was spent in
18 Test::Builder itself, even though every single test actually involved a
21 This module aims to be a partial replacement to Test::More in those
22 situations where you want to run a large number of simple tests. Its
23 functions behave the same as their Test::More counterparts, except for
24 the following differences :
26 * Stringification isn't forced on the test operands. However, "ok"
27 honors 'bool' overloading, "is" and "is_deeply" honor 'eq'
28 overloading (and just that one) and "cmp_ok" honors whichever
29 overloading category corresponds to the specified operator.
31 * "pass", "fail", "ok", "is", "isnt", "like", "unlike" and "cmp_ok"
32 are all guaranteed to return the truth value of the test.
34 * "like" and "unlike" don't special case regular expressions that are
35 passed as '/.../' strings. A string regexp argument is always
36 treated as a the source of the regexp, making "like $text, $rx" and
37 "like $text, qr[$rx]" equivalent to each other and to "cmp_ok $text,
38 '=~', $rx" (and likewise for "unlike").
40 * "cmp_ok" throws an exception if the given operator isn't a valid
41 Perl binary operator (except '=' and variants). It also tests in
42 scalar context, so '..' will be treated as the flip-flop operator
43 and not the range operator.
45 * "is_deeply" doesn't guard for memory cycles. If the two first
46 arguments present parallel memory cycles, the test may result in an
49 * The tests don't output any kind of default diagnostic in case of
50 failure ; the rationale being that if you have a large number of
51 tests and a lot of them are failing, then you don't want to be
52 flooded by diagnostics.
54 * "use_ok", "require_ok", "can_ok", "isa_ok", "new_ok", "subtest",
55 "explain", "TODO" blocks and "todo_skip" are not implemented.
58 "PERL_TEST_LEANER_USES_TEST_MORE"
59 If this environment variable is set, Test::Leaner will replace its
60 functions by those from Test::More. Moreover, the symbols that are
61 imported you "use Test::Leaner" will be those from Test::More, but you
62 can still only import the symbols originally defined in Test::Leaner
63 (hence the functions from Test::More that are not implemented in
64 Test::Leaner will not be imported). If your version of Test::More is too
65 old and doesn't have some symbols (like "note" or "done_testing"), they
66 will be replaced in Test::Leaner by croaking stubs.
68 This may be useful if your Test::Leaner-based test script fails and you
69 want extra diagnostics.
72 The following functions from Test::More are implemented and exported by
75 "plan [ tests => $count | 'no_plan' | skip_all => $reason ]"
76 See "plan" in Test::More.
78 "skip $reason => $count"
79 See "skip" in Test::More.
81 "done_testing [ $count ]"
82 See "done_testing" in Test::More.
85 See "ok" in Test::More.
88 See "pass" in Test::More.
91 See "fail" in Test::More.
93 "is $got, $expected [, $desc ]"
94 See "is" in Test::More.
96 "isnt $got, $expected [, $desc ]"
97 See "isnt" in Test::More.
99 "like $got, $regexp_expected [, $desc ]"
100 See "like" in Test::More.
102 "unlike $got, $regexp_expected, [, $desc ]"
103 See "unlike" in Test::More.
105 "cmp_ok $got, $op, $expected [, $desc ]"
106 See "cmp_ok" in Test::More.
108 "is_deeply $got, $expected [, $desc ]"
109 See "is_deeply" in Test::More.
112 See "diag" in Test::More.
115 See "note" in Test::More.
118 See "BAIL_OUT" in Test::More.
120 Test::Leaner also provides some functions of its own, which are never
124 Read/write accessor for the filehandle to which the tests are outputted.
125 On write, it also turns autoflush on onto $fh.
127 Note that it can only be used as a write accessor before you start any
128 thread, as threads::shared cannot reliably share filehandles.
130 Defaults to "STDOUT".
132 "diag_stream [ $fh ]"
133 Read/write accessor for the filehandle to which the diagnostics are
134 printed. On write, it also turns autoflush on onto $fh.
136 Just like "tap_stream", it can only be used as a write accessor before
137 you start any thread, as threads::shared cannot reliably share
140 Defaults to "STDERR".
143 This constant evaluates to true if and only if Test::Leaner is
144 thread-safe, i.e. when this version of "perl" is at least 5.8, has been
145 compiled with "useithreads" defined, and threads has been loaded before
146 Test::Leaner. In that case, it also needs a working threads::shared.
151 Exporter, Test::More.
154 Vincent Pit, "<perl at profvince.com>", <http://www.profvince.com>.
156 You can contact me by mail or on "irc.perl.org" (vincent).
159 Please report any bugs or feature requests to "bug-test-leaner at
160 rt.cpan.org", or through the web interface at
161 <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Test-Leaner>. I will be
162 notified, and then you'll automatically be notified of progress on your
163 bug as I make changes.
166 You can find documentation for this module with the perldoc command.
171 Copyright 2010 Vincent Pit, all rights reserved.
173 This program is free software; you can redistribute it and/or modify it
174 under the same terms as Perl itself.