1Test::Unit::Assertion::UCsoedreRCeofn(t3r)ibuted Perl DoTceusmte:n:tUantiito:n:Assertion::CodeRef(3)
2
3
4

NAME

6       Test::Unit::Assertion::CodeRef - A delayed evaluation assertion using a
7       Coderef
8

SYNOPSIS

10           require Test::Unit::Assertion::CodeRef;
11
12           my $assert_eq =
13             Test::Unit::Assertion::CodeRef->new(sub {
14               $_[0] eq $_[1]
15                 or Test::Unit::Failure->throw(-text =>
16                                                 "Expected '$_[0]', got '$_[1]'\n");
17             });
18
19           $assert_eq->do_assertion('foo', 'bar');
20
21       Although this is how you'd use Test::Unit::Assertion::CodeRef directly,
22       it is more usually used indirectly via Test::Unit::Test::assert, which
23       instantiates a Test::Unit::Assertion::CodeRef when passed a Coderef as
24       its first argument.
25

IMPLEMENTS

27       Test::Unit::Assertion::CodeRef implements the Test::Unit::Assertion
28       interface, which means it can be plugged into the Test::Unit::TestCase
29       and friends' "assert" method with no ill effects.
30

DESCRIPTION

32       This class is used by the framework to allow us to do assertions in a
33       'functional' manner. It is typically used generated automagically in
34       code like:
35
36           $self->assert(sub {
37                           $_[0] == $_[1]
38                             or $self->fail("Expected $_[0], got $_[1]");
39                         }, 1, 2);
40
41       (Note that if Damian Conway's Perl6 RFC for currying ever comes to pass
42       then we'll be able to do this as:
43
44           $self->assert(^1 == ^2 || $self->fail("Expected ^1, got ^2"), 1, 2)
45
46       which will be nice...)
47
48       If you have a working B::Deparse installed with your perl installation
49       then, if an assertion fails, you'll see a listing of the decompiled
50       coderef (which will be sadly devoid of comments, but should still be
51       useful)
52

AUTHOR

54       Copyright (c) 2001 Piers Cawley <pdcawley@iterative-software.com>.
55
56       All rights reserved. This program is free software; you can
57       redistribute it and/or modify it under the same terms as Perl itself.
58

SEE ALSO

60       ·   Test::Unit::TestCase
61
62       ·   Test::Unit::Assertion
63
64
65
66perl v5.30.0                      2019-09-05 Test::Unit::Assertion::CodeRef(3)
Impressum