File: 03_silent.t

package info (click to toggle)
libtap-formatter-html-perl 0.13%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 460 kB
  • sloc: perl: 754; javascript: 80; makefile: 2
file content (52 lines) | stat: -rw-r--r-- 1,536 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
use strict;
use warnings;

use lib 'lib';
use lib 't/lib';

use Test::More 'no_plan';
use FileTempTFH;

use TAP::Harness;
use_ok( 'TAP::Formatter::HTML' );

my $output_fh      = FileTempTFH->new;
my $stdout_fh      = FileTempTFH->new;
my $stdout_orig_fh = IO::File->new_from_fd( fileno(STDOUT), 'w' )
  or die "Error opening STDOUT for writing: $!";

STDOUT->fdopen( fileno($stdout_fh), 'w' )
  or die "Error re-directing STDOUT: $!";

# Note: strangely this doesn't fail on Windows, even though we're
# running 2 tests... worth pointing out it may be due to lack of
# output...
my @tests = ( 't/data/01_pass.pl', 't/data/02_fail.pl' );
{
    my $f = TAP::Formatter::HTML->new({ escape_output => 1, silent => 1 });
    my $h = TAP::Harness->new({ merge => 1, formatter => $f });
    $h->runtests(@tests);

    my $stdout = $stdout_fh->get_all_output || '';
    is( $stdout, '', 'should be no output to stdout' );

    my $html_ref = $f->html;
    ok( $$html_ref, 'formatter->html exists' );
}

{
    my $f = TAP::Formatter::HTML->new({ silent => 1, output_fh => $output_fh });
    my $h = TAP::Harness->new({ merge => 1, formatter => $f });
    $h->runtests(@tests);

    my $stdout = $stdout_fh->get_all_output || '';
    is( $stdout, '', 'should be no output to stdout' );

    my $html = $output_fh->get_all_output || '';
    ok( $html, 'html still output to non-stdout fh when silent is set' );
    like( $html, qr|01_pass|, 'html contains file 1' );

    my $html_ref = $f->html;
    ok( $$html_ref, 'formatter->html exists' );
}