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 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
|
#!/usr/bin/perl -w
BEGIN {
unshift @INC, 't/lib';
}
use strict;
use warnings;
use Test::More;
use File::Spec;
use App::Prove;
use Text::ParseWords qw(shellwords);
my @SCHEDULE;
BEGIN {
my $t_dir = File::Spec->catdir('t');
# to add a new test to proverun, just list the name of the file in
# t/sample-tests and a name for the test. The rest is handled
# automatically.
my @tests = (
{ file => 'simple',
name => 'Create empty',
},
{ file => 'todo_inline',
name => 'Passing TODO',
},
);
# TODO: refactor this and add in a test for:
# prove --source 'File: {extensions: [.1]}' t/source_tests/source.1
for my $test (@tests) {
# let's fully expand that filename
$test->{file}
= File::Spec->catfile( $t_dir, 'sample-tests', $test->{file} );
}
@SCHEDULE = (
map {
{ name => $_->{name},
args => [ $_->{file} ],
expect => [
[ 'new',
'TAP::Parser::Iterator::Process',
{ merge => undef,
command => [
'PERL',
$ENV{HARNESS_PERL_SWITCHES}
? shellwords( $ENV{HARNESS_PERL_SWITCHES} )
: (),
$_->{file},
],
setup => \'CODE',
teardown => \'CODE',
}
]
]
}
} @tests,
);
plan tests => @SCHEDULE * 3;
}
# Waaaaay too much boilerplate
package FakeProve;
use base qw( App::Prove );
sub new {
my $class = shift;
my $self = $class->SUPER::new(@_);
$self->{_log} = [];
return $self;
}
sub get_log {
my $self = shift;
my @log = @{ $self->{_log} };
$self->{_log} = [];
return @log;
}
package main;
{
use TAP::Parser::Iterator::Process;
use TAP::Formatter::Console;
# Patch TAP::Parser::Iterator::Process
my @call_log = ();
no warnings qw(redefine once);
my $orig_new = TAP::Parser::Iterator::Process->can('new');
*TAP::Parser::Iterator::Process::new = sub {
push @call_log, [ 'new', @_ ];
# And then new turns round and tramples on our args...
$_[1] = { %{ $_[1] } };
$orig_new->(@_);
};
# Patch TAP::Formatter::Console;
my $orig_output = \&TAP::Formatter::Console::_output;
*TAP::Formatter::Console::_output = sub {
# push @call_log, [ '_output', @_ ];
};
sub get_log {
my @log = @call_log;
@call_log = ();
return @log;
}
}
sub _slacken {
my $obj = shift;
if ( my $ref = ref $obj ) {
if ( 'HASH' eq ref $obj ) {
return { map { $_ => _slacken( $obj->{$_} ) } keys %$obj };
}
elsif ( 'ARRAY' eq ref $obj ) {
return [ map { _slacken($_) } @$obj ];
}
elsif ( 'SCALAR' eq ref $obj ) {
return $obj;
}
else {
return \$ref;
}
}
else {
return $obj;
}
}
sub is_slackly($$$) {
my ( $got, $want, $msg ) = @_;
return is_deeply _slacken($got), _slacken($want), $msg;
}
# ACTUAL TEST
for my $test (@SCHEDULE) {
my $name = $test->{name};
my $app = FakeProve->new;
$app->process_args( '--norc', @{ $test->{args} } );
# Why does this make the output from the test spew out of
# our STDOUT?
ok eval { $app->run }, 'run returned true';
ok !$@, 'no errors' or diag $@;
my @log = get_log();
# Bodge: we don't know what pathname will be used for the exe so we
# obliterate it here. Need to test that it's sane.
for my $call (@log) {
if ( 'HASH' eq ref $call->[2] && exists $call->[2]->{command} ) {
$call->[2]->{command}->[0] = 'PERL';
}
}
is_slackly \@log, $test->{expect}, "$name: command args OK";
# use Data::Dumper;
# diag Dumper(
# { got => \@log,
# expect => $test->{expect}
# }
# );
}
|