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
|
#!/usr/bin/perl -w
BEGIN {
unshift @INC, 't/lib';
}
use strict;
use warnings;
use TAP::Harness;
use Test::More;
use File::Path qw/mkpath rmtree/;
use File::Spec::Functions qw/catdir catfile rel2abs/;
for my $path (@INC) {
$path = rel2abs($path);
}
if ( eval { require CPAN::Meta::YAML; 1 } ) {
plan tests => 4;
}
else {
plan skip_all => "requires CPAN::Meta::YAML";
}
# create temp directories long-hand
# XXX should we add File::Temp as a prereq to do this?
my $initial_dir = rel2abs(".");
my $work_dir = catdir($initial_dir, "tmp" . int(rand(2**31)));
my $t_dir = catdir($work_dir, 't');
mkpath($t_dir) or die "Could not create $t_dir: $!";
chdir $work_dir;
# clean up at the end, but only if we didn't skip
END { if ($initial_dir) {chdir $initial_dir; rmtree($work_dir) } }
# Create test rules in t
{
open my $fh, ">", catfile($t_dir, "testrules.yml");
print {$fh} <<'HERE';
---
par: t/p*.t
HERE
close $fh;
}
my $th = TAP::Harness->new;
my $exp = {
par => 't/p*.t'
};
is_deeply( $th->rules, $exp, "rules set from t/testrules.yml" );
# Create test rules in dist root
{
open my $fh, ">", catfile($work_dir, "testrules.yml");
print {$fh} <<'HERE';
---
seq:
- seq: t/p*.t
- par: '**'
HERE
close $fh;
}
$th = TAP::Harness->new;
$exp = {
seq => [
{ seq => 't/p*.t' },
{ par => '**' },
],
};
is_deeply( $th->rules, $exp, "root testrules.yml overrides t/testrules.yml" );
# Create alternately named file
my $altrules = catfile($work_dir, "myrules.yml");
{
open my $fh, ">", $altrules;
print {$fh} <<'HERE';
---
seq: **
HERE
close $fh;
}
{
local $ENV{HARNESS_RULESFILE} = $altrules;
$th = TAP::Harness->new;
$exp = {
seq => '**'
};
is_deeply( $th->rules, $exp, "HARNESS_RULESFILE overrides testrules.yml" );
}
$th = TAP::Harness->new( { rulesfile => $altrules} );
$exp = {
seq => '**'
};
is_deeply( $th->rules, $exp, "rulesfile param overrides testrules.yml" );
|