2 use lib
(split(/:/, $ENV{GITPERLLIB
}));
12 use lib
$ENV{GITWEBLIBDIR
} || "$ENV{GIT_BUILD_DIR}/gitweb/lib";
14 # ....................................................................
16 use_ok
('GitwebCache::Capture::Simple');
17 diag
("Using lib '$INC[0]'");
18 diag
("Testing '$INC{'GitwebCache/Capture/Simple.pm'}'");
20 # Test setting up capture
22 my $capture = new_ok
('GitwebCache::Capture::Simple' => [], 'The $capture');
26 sub capture_block
(&) {
27 return $capture->capture(shift);
30 diag
('Should not print anything except test results and diagnostic');
31 my $test_data = 'Capture this';
32 my $captured = capture_block
{
35 is
($captured, $test_data, 'capture simple data');
37 binmode STDOUT
, ':utf8';
41 utf8
::decode
($test_data);
42 $captured = capture_block
{
43 binmode STDOUT
, ':utf8';
47 utf8
::decode
($captured);
48 is
($captured, $test_data, 'capture utf8 data');
50 $test_data = '|\x{fe}\x{ff}|\x{9F}|\000|'; # invalid utf-8
51 $captured = capture_block
{
52 binmode STDOUT
, ':raw';
56 is
($captured, $test_data, 'capture raw data');
58 # Test nested capturing
61 local $TODO = "not required for capturing gitweb output";
64 my $outer_capture = GitwebCache
::Capture
::Simple
->new();
65 $captured = $outer_capture->capture(sub {
67 my $captured = $capture->capture(sub {
73 is
($captured, "pre|inner|post", 'nested capture');
77 skip
"Capture::Tiny not available", 1
78 unless eval { require Capture
::Tiny
; };
80 $captured = Capture
::Tiny
::capture
(sub {
81 my $inner = $capture->capture(sub {
85 is
($captured, '', "doesn't print while capturing");
88 # Test capturing to file
90 my $test_data = 'Capture this';
91 open my $fh, '>', 'expected' or die "Couldn't open file for writing: $!";
92 print {$fh} $test_data;
95 $capture->capture(sub { print $test_data; }, 'actual');
96 cmp_ok
(compare
('expected', 'actual'), '==', 0, 'capturing to file via filename');
98 open my $fh, '>', 'actual' or die "Couldn't open file for writing: $!";
99 $capture->capture(sub { print $test_data; }, $fh);
101 cmp_ok
(compare
('expected', 'actual'), '==', 0, 'capturing to file via filehandle');