summaryrefslogtreecommitdiff
path: root/t/use_tap_harness.t
blob: bfce5069aa70891ca5d3112eeacdf5b40d4e1765 (plain)
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/usr/bin/perl -w

use strict;
use Test::More;
use lib 't/lib';
if (eval { require TAP::Harness && TAP::Harness->VERSION(3) }) {
    plan tests => 9;
} else {
    plan skip_all => 'TAP::Harness 3+ not installed'
}

use MBTest;
use DistGen;

blib_load('Module::Build');
my $tmp = MBTest->tmpdir;
my $dist = DistGen->new( dir => $tmp );
$dist->regen;
$dist->chdir_in;

#########################

# Make sure that TAP::Harness properly does its thing.
$dist->change_build_pl(
    module_name     => $dist->name,
    use_tap_harness => 1,
    quiet           => 1,
);
$dist->regen;

ok my $mb = $dist->new_from_context,
    'Construct build object with test_file_exts parameter';

$mb->add_to_cleanup('save_out');
# Use uc() so we don't confuse the current test output
my $out = uc(stdout_of(
    sub {$mb->dispatch('test', verbose => 1)}
));

like $out, qr/^OK 1/m, 'Should see first test output';
like $out, qr/^ALL TESTS SUCCESSFUL/m, 'Should see test success message';

#########################

# Make sure that arguments are passed through to TAP::Harness.
$dist->change_build_pl(
    module_name     => $dist->name,
    use_tap_harness => 1,
    tap_harness_args => { verbosity => 0 },
    quiet           => 1,
);
$dist->regen;

ok $mb = $dist->new_from_context,
    'Construct build object with test_file_exts parameter';

$mb->add_to_cleanup('save_out');
# Use uc() so we don't confuse the current test output
$out = uc(stdout_of(
    sub {$mb->dispatch('test', verbose => 1)}
));

unlike $out, qr/^OK 1/m, 'Should not see first test output';
like $out, qr/^ALL TESTS SUCCESSFUL/m, 'Should see test success message';

#--------------------------------------------------------------------------#
# test that a failing test dies
#--------------------------------------------------------------------------#

$dist->change_build_pl(
    module_name     => $dist->name,
    use_tap_harness => 1,
    tap_harness_args => { verbosity => 1 },
    quiet           => 1,
);
$dist->change_file('t/basic.t',<<"---");
use Test::More tests => 1;
use strict;

use $dist->{name};
ok 0;
---
$dist->regen;

ok $mb = $dist->new_from_context,
    'Construct build object after setting tests to fail';
# Use uc() so we don't confuse the current test output
$out = stdout_stderr_of( sub { $dist->run_build('test')} );
ok( $?, "'Build test' had non-zero exit code" );
like( $out, qr{Errors in testing\.  Cannot continue\.},
    "Saw emulated Test::Harness die() message"
);

# vim:ts=4:sw=4:et:sta