1Test::LongString(3) User Contributed Perl Documentation Test::LongString(3)
2
3
4
6 Test::LongString - tests strings for equality, with more helpful fail‐
7 ures
8
10 use Test::More tests => 1;
11 use Test::LongString;
12 like_string( $html, qr/(perl⎪cpan)\.org/ );
13
14 # Failed test (html-test.t at line 12)
15 # got: "<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Trans"...
16 # length: 58930
17 # doesn't match '(?-xism:(perl⎪cpan)\.org)'
18
20 This module provides some drop-in replacements for the string compari‐
21 son functions of Test::More, but which are more suitable when you test
22 against long strings. If you've ever had to search for text in a
23 multi-line string like an HTML document, or find specific items in
24 binary data, this is the module for you.
25
27 is_string( $string, $expected [, $label ] )
28
29 "is_string()" is equivalent to "Test::More::is()", but with more help‐
30 ful diagnostics in case of failure.
31
32 · It doesn't print the entire strings in the failure message.
33
34 · It reports the lengths of the strings that have been compared.
35
36 · It reports the length of the common prefix of the strings.
37
38 · In the diagnostics, non-ASCII characters are escaped as "\x{xx}".
39
40 For example:
41
42 is_string( $soliloquy, $juliet );
43
44 # Failed test (soliloquy.t at line 15)
45 # got: "To be, or not to be: that is the question:\x{0a}Whether"...
46 # length: 1490
47 # expected: "O Romeo, Romeo,\x{0a}wherefore art thou Romeo?\x{0a}Deny thy"...
48 # length: 154
49 # strings begin to differ at char 1
50
51 is_string_nows( $string, $expected [, $label ] )
52
53 Like "is_string()", but removes whitepace (in the "\s" sense) from the
54 arguments before comparing them.
55
56 like_string( $string, qr/regex/ [, $label ] )
57
58 unlike_string( $string, qr/regex/ [, $label ] )
59
60 "like_string()" and "unlike_string()" are replacements for
61 "Test::More:like()" and "unlike()" that only print the beginning of the
62 received string in the output. Unfortunately, they can't print out the
63 position where the regex failed to match.
64
65 like_string( $soliloquy, qr/Romeo⎪Juliet⎪Mercutio⎪Tybalt/ );
66
67 # Failed test (soliloquy.t at line 15)
68 # got: "To be, or not to be: that is the question:\x{0a}Whether"...
69 # length: 1490
70 # doesn't match '(?-xism:Romeo⎪Juliet⎪Mercutio⎪Tybalt)'
71
72 contains_string( $string, $substring [, $label ] )
73
74 "contains_string()" searches for $substring in $string. It's the same
75 as "like_string()", except that it's not a regular expression search.
76
77 contains_string( $soliloquy, "Romeo" );
78
79 # Failed test (soliloquy.t at line 10)
80 # searched: "To be, or not to be: that is the question:\x{0a}Whether"...
81 # and can't find: "Romeo"
82
83 lacks_string( $string, $substring [, $label ] )
84
85 "lacks_string()" makes sure that $substring does NOT exist in $string.
86 It's the same as "like_string()", except that it's not a regular
87 expression search.
88
89 lacks_string( $soliloquy, "slings" );
90
91 # Failed test (soliloquy.t at line 10)
92 # searched: "To be, or not to be: that is the question:\x{0a}Whether"...
93 # and found: "slings"
94 # at position: 147
95
97 By default, only the first 50 characters of the compared strings are
98 shown in the failure message. This value is in $Test::LongString::Max,
99 and can be set at run-time.
100
101 You can also set it by specifying an argument to "use":
102
103 use Test::LongString max => 100;
104
105 When the compared strings begin to differ after a large prefix,
106 Test::LongString will not print them from the beginning, but will start
107 at the middle, more precisely at $Test::LongString::Context characters
108 before the first difference. By default this value is 10 characters. If
109 you want Test::LongString to always print the beginning of compared
110 strings no matter where they differ, undefine $Test::LongString::Con‐
111 text.
112
114 Written by Rafael Garcia-Suarez. Thanks to Mark Fowler (and to Joss
115 Whedon) for the inspirational Acme::Test::Buffy. Thanks to Andy Lester
116 for lots of patches.
117
118 This program is free software; you may redistribute it and/or modify it
119 under the same terms as Perl itself.
120
122 Test::Builder, Test::Builder::Tester, Test::More.
123
124
125
126perl v5.8.8 2006-11-08 Test::LongString(3)