forked from andk/cpanpm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlocal_utils.pm
100 lines (88 loc) · 2.82 KB
/
local_utils.pm
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
package local_utils;
use Config;
use Cwd;
use File::Copy qw(cp);
use File::Path qw(rmtree mkpath);
use File::Spec ();
sub _f ($) {File::Spec->catfile(split /\//, shift);}
sub _d ($) {File::Spec->catdir(split /\//, shift);}
sub prepare_dot_cpan {
rmtree _d"t/dot-cpan/sources";
rmtree _d"t/dot-cpan/build";
mkpath _d"t/dot-cpan/build";
rmtree _d"t/dot-cpan/prefs";
mkpath _d"t/dot-cpan/prefs";
unlink _f"t/dot-cpan/Metadata";
unlink _f"t/dot-cpan/.lock";
mkpath _d"t/dot-cpan/sources/authors/id/A/AN/ANDK";
mkpath _d"t/dot-cpan/Bundle";
# cp is not-overwriting on OS/2
unlink _f"t/CPAN/MyConfig.pm", _f"t/dot-cpan/sources/MIRRORED.BY";
cp _f"t/CPAN/TestConfig.pm", _f"t/CPAN/MyConfig.pm"
or die "Could not cp t/CPAN/TestConfig.pm over t/CPAN/MyConfig.pm: $!";
cp _f"t/CPAN/TestMirroredBy", _f"t/dot-cpan/sources/MIRRORED.BY"
or die "Could not cp t/CPAN/TestMirroredBy over t/dor-cpan/sources/MIRRORED.BY: $!";
}
sub cleanup_dot_cpan {
unlink _f"t/dot-cpan/sources/authors/id/A/AN/ANDK/CHECKSUMS";
unlink _f"t/dot-cpan/sources/MIRRORED.BY";
unlink _f"t/dot-cpan/prefs/FTPstats.yml";
unlink _f"t/dot-cpan/prefs/TestDistroPrefsFile.yml";
unlink _f"t/dot-cpan/prefs/ANDK.CPAN-Test-Dummy-Perl5-Make-Expect.yml";
rmtree _d"t/dot-cpan";
}
sub read_myconfig () {
local *FH;
open *FH, _f"t/CPAN/MyConfig.pm" or die "Could not read t/CPAN/MyConfig.pm: $!";
local $/;
eval <FH>;
}
# shamelessly stolen from Test::Builder
sub mydiag {
my(@msgs) = @_;
my $msg = join '', map { defined($_) ? $_ : 'undef' } @msgs;
# Escape each line with a #.
$msg =~ s/^/# /gm;
# Stick a newline on the end if it needs it.
$msg .= "\n" unless $msg =~ /\n\Z/;
print $msg;
}
sub mreq ($) {
my $m = shift;
eval "require $m; 1";
}
sub splitchunk ($) {
my $ch = shift;
my @s = split /(^\#[A-Za-z]:)/m, $ch;
shift @s; # leading empty string
for (my $i = 0; $i < @s; $i+=2) {
$s[$i] =~ s/\#//;
$s[$i] =~ s/://;
}
@s;
}
sub test_name {
my($prog,$comment) = @_;
($comment||"") . ($prog ? " (testing command '$prog')" : "[empty RET]")
}
sub run_shell_cmd_lit ($) {
my $cwd = shift;
my $t = File::Spec->catfile($cwd,"t");
my @system = (
$^X,
"-I$t", # get this test's own MyConfig
"-Mblib",
"-MCPAN::MyConfig",
"-MCPAN",
($INC{"Devel/Cover.pm"} ? "-MDevel::Cover" : ()),
# (@ARGV) ? "-d" : (), # force subtask into debug, maybe useful
"-e",
# "\$CPAN::Suppress_readline=1;shell('$prompt\n')",
"\@CPAN::Defaultsites = (); shell",
);
}
1;
# Local Variables:
# mode: cperl
# cperl-indent-level: 4
# End: