forked from hdp/module-build
-
Notifications
You must be signed in to change notification settings - Fork 0
/
runthrough.t
145 lines (108 loc) · 4 KB
/
runthrough.t
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
use strict;
use Test;
BEGIN { plan tests => 28 }
use Module::Build;
use File::Spec;
use File::Path;
use Config;
ok(1);
ok $INC{'Module/Build.pm'}, '/blib/', "Make sure version from blib/ is loaded";
my $common_pl = File::Spec->catfile('t', 'common.pl');
require $common_pl;
######################### End of black magic.
my $have_yaml = Module::Build->current->feature('YAML_support');
my $start_dir = Module::Build->cwd;
# Would be nice to just have a 'base_dir' parameter for M::B->new()
my $goto = File::Spec->catdir( $start_dir, 't', 'Sample' );
chdir $goto or die "can't chdir to $goto: $!";
my $build = Module::Build->new_from_context();
ok $build;
ok $build->license, 'perl';
# Make sure cleanup files added before create_build_script() get respected
$build->add_to_cleanup('before_script');
eval {$build->create_build_script};
ok $@, '';
ok -e $build->build_script, 1;
ok $build->dist_dir, 'Sample-0.01';
# The 'cleanup' file doesn't exist yet
ok grep $_ eq 'before_script', $build->cleanup;
$build->add_to_cleanup('save_out');
# The 'cleanup' file now exists
ok grep $_ eq 'before_script', $build->cleanup;
ok grep $_ eq 'save_out', $build->cleanup;
my $output = eval {
stdout_of( sub { $build->dispatch('test', verbose => 1) } )
};
ok $@, '';
ok $output, qr/all tests successful/i;
# This is the output of lib/Sample/Script.PL
ok -e $build->localize_file_path('lib/Sample/Script');
# We prefix all lines with "| " so Test::Harness doesn't get confused.
print "vvvvvvvvvvvvvvvvvvvvv Sample/test.pl output vvvvvvvvvvvvvvvvvvvvv\n";
$output =~ s/^/| /mg;
print $output;
print "^^^^^^^^^^^^^^^^^^^^^ Sample/test.pl output ^^^^^^^^^^^^^^^^^^^^^\n";
if ($have_yaml) {
eval {$build->dispatch('disttest')};
ok $@, '';
# After a test, the distdir should contain a blib/ directory
ok -e File::Spec->catdir('Sample-0.01', 'blib');
eval {$build->dispatch('distdir')};
ok $@, '';
# The 'distdir' should contain a lib/ directory
ok -e File::Spec->catdir('Sample-0.01', 'lib');
# The freshly run 'distdir' should never contain a blib/ directory, or
# else it could get into the tarball
ok not -e File::Spec->catdir('Sample-0.01', 'blib');
# Make sure all of the above was done by the new version of Module::Build
my $fh = IO::File->new(File::Spec->catfile($goto, 'META.yml'));
my $contents = do {local $/; <$fh>};
$contents =~ /Module::Build version ([0-9_.]+)/m;
ok 0+$1, 0+$build->VERSION, "Check version used to create META.yml";
if ($build->check_installed_status('Archive::Tar', 0)
or $build->isa('Module::Build::Platform::Unix')) {
$build->add_to_cleanup($build->dist_dir . ".tar.gz");
eval {$build->dispatch('dist')};
ok $@, '';
} else {
skip_subtest("not sure if we can create a tarball on this platform");
}
} else {
skip_subtest("YAML.pm is not installed, or disabled") for 1..7;
}
{
# Make sure the 'script' file was recognized as a script.
my $scripts = $build->script_files;
ok $scripts->{script};
# Check that a shebang line is rewritten
my $blib_script = File::Spec->catdir( qw( blib script script ) );
ok -e $blib_script;
my $fh = IO::File->new($blib_script);
my $first_line = <$fh>;
print "# rewritten shebang?\n$first_line";
ok $first_line ne "#!perl -w\n";
}
{
# Check PPD
$build->dispatch('ppd', args => {codebase => '/path/to/codebase'});
my $ppd = slurp('Sample.ppd');
# This test is quite a hack since with XML you don't really want to
# do a strict string comparison, but absent an XML parser it's the
# best we can do.
ok $ppd, <<'EOF';
<SOFTPKG NAME="Sample" VERSION="0,01,0,0">
<TITLE>Sample</TITLE>
<ABSTRACT>Foo foo sample foo</ABSTRACT>
<AUTHOR>Sample Man <sample@example.com></AUTHOR>
<IMPLEMENTATION>
<DEPENDENCY NAME="File-Spec" VERSION="0,0,0,0" />
<CODEBASE HREF="/path/to/codebase" />
</IMPLEMENTATION>
</SOFTPKG>
EOF
}
eval {$build->dispatch('realclean')};
ok $@, '';
ok !-e $build->build_script, 1;
ok !-e $build->config_dir, 1;
ok !-e $build->dist_dir, 1;