1Test::HexString(3) User Contributed Perl Documentation Test::HexString(3)
2
3
4
6 "Test::HexString" - test binary strings with hex dump diagnostics
7
9 use Test::More tests => 1;
10 use Test::HexString;
11
12 my $data = generate_some_output;
13
14 is_hexstr( $data, "\x01\x02\x03\x04", 'Generated output' );
15
17 This testing module provides a single function, "is_hexstr()", which
18 asserts that the given string matches what was expected. When the
19 strings match (i.e. compare equal using the "eq" operator), the
20 behaviour is identical to the usual "is()" function provided by
21 "Test::More".
22
23 When the strings are different, a hex dump is produced as diagnostic,
24 rather than the string values being printed raw. This may be beneficial
25 if the string contains largely binary data, such as may be produced by
26 binary file or network protocol modules.
27
28 To print the hex dump when it fails, each string is broken into 16 byte
29 chunks. The first pair of chunks that fail to match are then printed,
30 in both hexadecimal and character form, in a message in the following
31 format:
32
33 # Failed test at -e line 1.
34 # at bytes 0-0xf (0-15)
35 # got: | 61 20 6c 6f 6e 67 20 73 74 72 69 6e 67 20 68 65 |a long string he|
36 # exp: | 61 20 6c 6f 6e 67 20 53 74 72 69 6e 67 20 68 65 |a long String he|
37 # Looks like you failed 1 test of 1.
38
39 Only bytes in the range "0x20-0x7e" are printed as literal characters.
40 Any other byte is rendered as ".":
41
42 # Failed test at -e line 1.
43 # at bytes 0-0xf (0-15)
44 # got: | 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f |................|
45 # exp: | 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 10 |................|
46 # Looks like you failed 1 test of 1.
47
48 Only the first differing line is printed; because otherwise it may
49 result in a long output because of misaligned bytes.
50
51 If STDOUT is a terminal, then different bytes are printed in bold for
52 visibility.
53
55 is_hexstr( $got, $expect, $name )
56 Test that the string $got is what was expected by $expect. If the
57 strings are not equal, a hex dump is printed showing the region where
58 they first start to differ.
59
61 Paul Evans <leonerd@leonerd.org.uk>
62
63
64
65perl v5.28.0 2018-07-15 Test::HexString(3)