Skip to content

Commit 94798eb

Browse files
committed
Keep test data out of t directory.
1 parent 9d24cc2 commit 94798eb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+77
-47
lines changed

etc/metacpan_testing.pl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
port => '5900',
44
die_on_error => 1,
55
level => ($ENV{TEST_VERBOSE} ? 'info' : 'warn'),
6-
cpan => 't/var/tmp/fakecpan',
7-
source_base => 't/var/tmp/source',
6+
cpan => 'var/t/tmp/fakecpan',
7+
source_base => 'var/t/tmp/source',
88
logger => [{
99
class => 'Log::Log4perl::Appender::Screen',
1010
name => 'testing'

t/00_setup.t

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,16 @@ use warnings;
44
use lib 't/lib';
55

66
use CPAN::Faker 0.010;
7+
use Devel::Confess;
78
use File::Copy;
89
use MetaCPAN::Script::Tickets;
910
use MetaCPAN::Server::Test;
10-
use MetaCPAN::TestHelpers qw( get_config );
11+
use MetaCPAN::TestHelpers qw(
12+
fakecpan_configs_dir
13+
fakecpan_dir
14+
get_config
15+
tmp_dir
16+
);
1117
use MetaCPAN::TestServer;
1218
use Module::Faker 0.015 (); # Generates META.json.
1319
use Path::Class qw(dir);
@@ -16,12 +22,7 @@ use Test::More 0.96;
1622
use Test::More 0.96 ();
1723
use Test::Most;
1824

19-
my $tmp_dir = dir('var/tmp');
20-
21-
unless ( -d $tmp_dir || -l $tmp_dir ) {
22-
$tmp_dir->mkpath();
23-
}
24-
ok( ( -d $tmp_dir || -l $tmp_dir ), 'var/tmp exists for testing' );
25+
ok( ( -d tmp_dir() ), 'var/tmp exists for testing' );
2526

2627
my $server = MetaCPAN::TestServer->new;
2728
$server->setup;
@@ -40,19 +41,26 @@ foreach my $test_dir ( $config->{cpan}, $config->{source_base} ) {
4041
my $mod_faker = 'Module::Faker::Dist::WithPerl';
4142
eval "require $mod_faker" or die $@; ## no critic (StringyEval)
4243

44+
my $fakecpan_dir = fakecpan_dir();
45+
$fakecpan_dir->rmtree;
46+
$fakecpan_dir = fakecpan_dir(); # recreate dir
47+
48+
my $fakecpan_configs = fakecpan_configs_dir();
49+
4350
my $cpan = CPAN::Faker->new(
4451
{
45-
source => 't/var/fakecpan/configs',
46-
dest => $config->{cpan},
52+
source => $fakecpan_configs->subdir('configs')->stringify,
53+
dest => $fakecpan_dir->stringify,
4754
dist_class => $mod_faker,
4855
}
4956
);
5057

5158
ok( $cpan->make_cpan, 'make fake cpan' );
59+
$fakecpan_dir->subdir('authors')->mkpath;
5260

5361
# do some changes to 06perms.txt
5462
{
55-
my $perms_file = dir( $config->{cpan} )->file(qw(modules 06perms.txt));
63+
my $perms_file = $fakecpan_dir->subdir('modules')->file('06perms.txt');
5664
my $perms = $perms_file->slurp;
5765
$perms =~ s/^Some,LOCAL,f$/Some,MO,f/m;
5866
my $fh = $perms_file->openw;
@@ -64,29 +72,29 @@ ok( $cpan->make_cpan, 'make fake cpan' );
6472
require Parse::PMFile;
6573
local $Parse::PMFile::VERBOSE = $ENV{TEST_VERBOSE} ? 9 : 0;
6674

67-
$server->index_releases;
68-
$server->set_latest;
69-
70-
my $cpan_dir = dir( 't', 'var', 'fakecpan', );
75+
my $src_dir = $fakecpan_configs;
7176

72-
copy( $cpan_dir->file('00whois.xml'),
73-
file( $config->{cpan}, qw(authors 00whois.xml) ) );
77+
$src_dir->file('00whois.xml')
78+
->copy_to( $fakecpan_dir->file(qw(authors 00whois.xml)) );
7479

75-
copy( $cpan_dir->file('author-1.0.json'),
76-
file( $config->{cpan}, qw(authors id M MO MO author-1.0.json) ) );
80+
copy( $src_dir->file('author-1.0.json'),
81+
$fakecpan_dir->file(qw(authors id M MO MO author-1.0.json)) );
7782

78-
copy( $cpan_dir->file('bugs.tsv'), file( $config->{cpan}, 'bugs.tsv' ) );
83+
copy( $src_dir->file('bugs.tsv'), $fakecpan_dir->file('bugs.tsv') );
7984

85+
$server->index_releases;
86+
$server->set_latest;
8087
$server->index_authors;
88+
$server->index_cpantesters;
8189

8290
ok(
8391
MetaCPAN::Script::Tickets->new_with_options(
8492
{
8593
%{$config},
8694
rt_summary_url => 'file://'
87-
. file( $config->{cpan}, 'bugs.tsv' )->absolute,
95+
. $fakecpan_dir->file('bugs.tsv')->absolute,
8896
github_issues => 'file://'
89-
. dir(qw(t var fakecpan github))->absolute
97+
. $fakecpan_dir->subdir('github')->absolute
9098
. '/%s/%s.json?per_page=100',
9199
}
92100
)->run,

t/lib/MetaCPAN/DarkPAN.pm

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
package MetaCPAN::DarkPAN;
22

3-
use strict;
4-
use warnings;
3+
use MetaCPAN::Moose;
54

65
use CPAN::Repository::Perms;
76
use MetaCPAN::TestHelpers qw( get_config );
87
use MetaCPAN::Types qw( Dir );
98
use MetaCPAN::Util qw( author_dir );
10-
use Moose;
119
use OrePAN2::Indexer;
1210
use OrePAN2::Injector;
1311
use Path::Class qw( dir );

t/lib/MetaCPAN/TestHelpers.pm

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,18 @@ use Try::Tiny qw( catch try );
1616
use base 'Exporter';
1717
our @EXPORT = qw(
1818
catch
19-
get_config
2019
decode_json_ok
2120
encode_json
21+
fakecpan_configs_dir
22+
fakecpan_dir
2223
finally
24+
get_config
2325
hex_escape
2426
multiline_diag
2527
run_tests
2628
test_distribution
2729
test_release
30+
tmp_dir
2831
try
2932
);
3033

@@ -100,4 +103,23 @@ sub get_config {
100103
return $config;
101104
}
102105

106+
sub tmp_dir {
107+
my $dir = dir( undef, checkout_root(), 'var', 't', 'tmp' );
108+
$dir->mkpath;
109+
return $dir;
110+
}
111+
112+
sub fakecpan_dir {
113+
my $dir = tmp_dir();
114+
my $fakecpan = $dir->subdir('fakecpan');
115+
$fakecpan->mkpath;
116+
return $fakecpan;
117+
}
118+
119+
sub fakecpan_configs_dir {
120+
my $source = dir( undef, checkout_root(), 'test-data', 'fakecpan' );
121+
$source->mkpath;
122+
return $source;
123+
}
124+
103125
1;

t/lib/MetaCPAN/TestServer.pm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use MetaCPAN::Script::CPANTesters ();
88
use MetaCPAN::Script::Latest;
99
use MetaCPAN::Script::Mapping;
1010
use MetaCPAN::Script::Release;
11-
use MetaCPAN::TestHelpers qw( get_config );
11+
use MetaCPAN::TestHelpers qw( get_config fakecpan_dir );
1212
use MetaCPAN::Types qw( Dir HashRef Str );
1313
use Search::Elasticsearch;
1414
use Search::Elasticsearch::TestServer;
@@ -48,7 +48,7 @@ has _cpan_dir => (
4848
isa => Dir,
4949
init_arg => 'cpan_dir',
5050
coerce => 1,
51-
default => 't/var/tmp/fakecpan',
51+
default => sub { fakecpan_dir() },
5252
);
5353

5454
sub setup {

t/model/archive.t

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
use strict;
44
use warnings;
55

6+
use MetaCPAN::TestHelpers qw( fakecpan_dir );
67
use Test::Most;
78

89
my $CLASS = 'MetaCPAN::Model::Archive';
@@ -29,10 +30,10 @@ subtest 'archive extraction' => sub {
2930
'Some-1.00-TRIAL/MANIFEST' => 62,
3031
);
3132

32-
my $archive
33-
= $CLASS->new( file =>
34-
't/var/tmp/fakecpan/authors/id/L/LO/LOCAL/Some-1.00-TRIAL.tar.gz'
35-
);
33+
my $archive = $CLASS->new(
34+
file => fakecpan_dir->file(
35+
'/authors/id/L/LO/LOCAL/Some-1.00-TRIAL.tar.gz')
36+
);
3637

3738
ok !$archive->is_impolite;
3839
ok !$archive->is_naughty;
@@ -51,10 +52,10 @@ subtest 'temp cleanup' => sub {
5152
my $tempdir;
5253

5354
{
54-
my $archive
55-
= $CLASS->new( file =>
56-
't/var/tmp/fakecpan/authors/id/L/LO/LOCAL/Some-1.00-TRIAL.tar.gz'
57-
);
55+
my $archive = $CLASS->new(
56+
file => fakecpan_dir->file(
57+
'authors/id/L/LO/LOCAL/Some-1.00-TRIAL.tar.gz')
58+
);
5859

5960
$tempdir = $archive->extract;
6061
ok -d $tempdir;
@@ -68,10 +69,10 @@ subtest 'temp cleanup' => sub {
6869
};
6970

7071
subtest 'extract once' => sub {
71-
my $archive
72-
= $CLASS->new( file =>
73-
't/var/tmp/fakecpan/authors/id/L/LO/LOCAL/Some-1.00-TRIAL.tar.gz'
74-
);
72+
my $archive = $CLASS->new(
73+
file => fakecpan_dir->file(
74+
'authors/id/L/LO/LOCAL/Some-1.00-TRIAL.tar.gz')
75+
);
7576

7677
is $archive->extract, $archive->extract;
7778
};
@@ -81,8 +82,8 @@ subtest 'set extract dir' => sub {
8182

8283
{
8384
my $archive = $CLASS->new(
84-
file =>
85-
't/var/tmp/fakecpan/authors/id/L/LO/LOCAL/Some-1.00-TRIAL.tar.gz',
85+
file => facecpan_dir->file(
86+
'authors/id/L/LO/LOCAL/Some-1.00-TRIAL.tar.gz'),
8687
extract_dir => $temp->dirname
8788
);
8889

t/model/release/dependencies.t

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@ use warnings;
44
use FindBin;
55
use MetaCPAN::Model::Release;
66
use MetaCPAN::Script::Runner;
7-
use MetaCPAN::TestHelpers qw( get_config );
7+
use MetaCPAN::TestHelpers qw( fakecpan_dir get_config );
88
use Test::Most;
99

1010
my $config = get_config();
1111

1212
subtest 'basic dependencies' => sub {
1313
my $file
14-
= 't/var/tmp/fakecpan/authors/id/M/MS/MSCHWERN/Prereqs-Basic-0.01.tar.gz';
14+
= fakecpan_dir->file(
15+
'/authors/id/M/MS/MSCHWERN/Prereqs-Basic-0.01.tar.gz');
1516

1617
my $release = MetaCPAN::Model::Release->new(
1718
logger => $config->{logger},

t/model/release/metadata.t

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ use warnings;
44
use FindBin;
55
use MetaCPAN::Model::Release;
66
use MetaCPAN::Script::Runner;
7-
use MetaCPAN::TestHelpers qw( get_config );
7+
use MetaCPAN::TestHelpers qw( fakecpan_dir get_config );
88
use Test::More;
99

10-
my $authordir = 't/var/tmp/fakecpan/authors/id/L/LO/LOCAL';
10+
my $authordir = fakecpan_dir->file('authors/id/L/LO/LOCAL');
1111

1212
my $config = get_config();
1313

File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)