File: | t/01-basic.t |
Coverage: | 88.5% |
line | stmt | bran | cond | sub | pod | time | code |
---|---|---|---|---|---|---|---|
1 | 1 1 1 | 1856 2 20 | use strict; | ||||
2 | 1 1 1 | 2 0 13 | use warnings; | ||||
3 | 1 1 1 | 195 645 30 | use FindBin; | ||||
4 | 1 1 1 | 201 375 3 | use lib "$FindBin::Bin/lib"; | ||||
5 | 1 1 1 | 376 1 19 | use Tie::Input::Insertable; | ||||
6 | 1 1 1 | 217 15306 78 | use Capture::Tiny ':all'; | ||||
7 | 1 1 1 | 164 3990 3 | use Syntax::Feature::Void; | ||||
8 | 1 1 1 | 1904 13019 4 | use Test::More; | ||||
9 | 1 1 1 | 400 5803 144 | use Data::Dumper::Concise; | ||||
10 | |||||||
11 | # Loading nine types of message in all sorts of really funky ways just to | ||||||
12 | # test coverage on the import method -- it is kind of important :-) | ||||||
13 | BEGIN { | ||||||
14 | 1 1 1 1 1 | 1 439 2 1 2 | use_ok( 'Message::String' ); | ||||
15 | 1 1 1 1 1 | 198 66 1 1 1 | use_ok( 'Message::String', 'void' ); | ||||
16 | 1 1 1 1 1 | 127 47 1 0 2 | use_ok( 'message' ); | ||||
17 | #<<< | ||||||
18 | 1 1 1 1 1 | 139 53 1 0 2 | use_ok( | ||||
19 | 'message', | ||||||
20 | ALT_MESSAGE_001 => 'Alert.', | ||||||
21 | EXPORT => (), | ||||||
22 | EXPORT => ( CRT_MESSAGE_002 => 'Critical.' ), | ||||||
23 | EXPORT => (), | ||||||
24 | EXPORT_OK => ( ERR_MESSAGE_003 => 'Error.\n' ), | ||||||
25 | EXPORT_OK => (), | ||||||
26 | ':TAG1' => ( WRN_MESSAGE_004 => 'Warning.' ), | ||||||
27 | ':TAG1' => (), | ||||||
28 | ':TAG1', ':TAG2' => ( NTC_MESSAGE_005 => 'Notice.' ), | ||||||
29 | ':TAG1', ':TAG2' => (), | ||||||
30 | ':TAG1,:TAG2' => ( INF_MESSAGE_006 => 'Info.' ), | ||||||
31 | ':TAG1,:TAG2' => (), | ||||||
32 | { DGN_MESSAGE_007 => 'Debug.\t' }, {}, | ||||||
33 | [ RSP_MESSAGE_008 => 'Password:\s' ], [], | ||||||
34 | ); | ||||||
35 | #>>> | ||||||
36 | 1 1 1 1 1 | 144 57 1 0 2 | use_ok( 'message', << 'EOF'); | ||||
37 | |||||||
38 | # Comment under a blank line | ||||||
39 | MSG_MESSAGE_009 Other type of | ||||||
40 | ... really, really long message. | ||||||
41 | + With two lines. | ||||||
42 | RSP_ANOTHER_010 Another response.\r\a | ||||||
43 | EOF | ||||||
44 | } | ||||||
45 | |||||||
46 | 1 | 74534 | my ( $stdout, $stderr, @result ); | ||||
47 | 1 1 1 | 163 1 1344 | no warnings 'once'; | ||||
48 | 1 | 4 | tie *FAKE_STDIN, 'Tie::Input::Insertable', *STDIN; | ||||
49 | 1 | 2 | *Message::String::INPUT_ORIGINAL = \*Message::String::INPUT; | ||||
50 | 1 | 1 | *Message::String::INPUT = \*FAKE_STDIN; | ||||
51 | |||||||
52 | 1 | 1 | eval { | ||||
53 | 1 0 | 5 0 | message->import( sub {'Nonsense, should generate error'} ); | ||||
54 | }; | ||||||
55 | 1 | 50 | like( $@, qr/C_EXPECT_HAREF_OR_KVPL/, "Caught 'C_EXPECT_HAREF_OR_KVPL'" ); | ||||
56 | |||||||
57 | 1 1 | 170 2 | eval { void ALT_MESSAGE_001 }; | ||||
58 | 1 | 4 | like( $@, qr/ALT_MESSAGE_001 Alert\./, "Caught 'ALT_MESSAGE_001 Alert.'" ); | ||||
59 | |||||||
60 | 1 1 | 134 2 | eval { void CRT_MESSAGE_002 }; | ||||
61 | 1 | 3 | like( $@, qr/CRT_MESSAGE_002 Critical\./, | ||||
62 | "Caught 'CRT_MESSAGE_002 Critical.'" ); | ||||||
63 | |||||||
64 | 1 1 | 155 623 | ( $stderr ) = capture_stderr { void ERR_MESSAGE_003 }; | ||||
65 | 1 | 1798 | like( $stderr && $stderr, qr/Error\./, "Got 'Error.' on stderr" ); | ||||
66 | |||||||
67 | 1 1 | 298 457 | ( $stderr ) = capture_stderr { void WRN_MESSAGE_004 }; | ||||
68 | 1 | 488 | like( $stderr && $stderr, qr/Warning\./, "Got 'Warning.' on stderr" ); | ||||
69 | |||||||
70 | 1 1 | 262 493 | ( $stderr ) = capture_stderr { void NTC_MESSAGE_005 }; | ||||
71 | 1 | 517 | like( $stderr && $stderr, qr/Notice\./, "Got 'Notice.' on stderr" ); | ||||
72 | |||||||
73 | 1 1 | 253 522 | ( $stdout ) = capture_stdout { void INF_MESSAGE_006 }; | ||||
74 | 1 | 390 | like( $stdout && $stdout, qr/Info\./, "Got 'Info.' on stdout" ); | ||||
75 | |||||||
76 | 1 1 | 184 379 | ( $stdout ) = capture_stdout { void DGN_MESSAGE_007 }; | ||||
77 | 1 | 328 | like( $stdout && $stdout, qr/# Debug\./, "Got '# Debug .' on stdout" ); | ||||
78 | |||||||
79 | ( $stdout ) = capture_stdout { | ||||||
80 | 1 | 336 | print Message::String::INPUT "User Input\n"; | ||||
81 | 1 | 3 | void RSP_MESSAGE_008; | ||||
82 | 1 | 182 | }; | ||||
83 | 1 | 300 | like( $stdout && $stdout, qr/Password:/, "Got 'Password:' on stdout" ); | ||||
84 | 1 | 143 | like( RSP_MESSAGE_008->response, qr/User Input/, | ||||
85 | "Got 'User Input' on stdin" ); | ||||||
86 | |||||||
87 | 1 1 | 149 308 | ( $stdout ) = capture_stdout { void MSG_MESSAGE_009 }; | ||||
88 | 1 | 327 | like( | ||||
89 | $stdout && $stdout, qr/Other type of.*message.\nWith two lines/s, | ||||||
90 | "Got 'Other type of message' on stdout" ); | ||||||
91 | |||||||
92 | 1 | 141 | *Message::String::INPUT = \*Message::String::INPUT_ORIGINAL; | ||||
93 | |||||||
94 | # Ok that basically gets us to 100% of statements, 90.6% of branches, 76.8% | ||||||
95 | # of conditionals, 95.1% aggregate on coverage tests. | ||||||
96 | |||||||
97 | 1 | 3 | done_testing; |