-
Notifications
You must be signed in to change notification settings - Fork 138
/
02-install_files.t
247 lines (198 loc) · 6.32 KB
/
02-install_files.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
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
#! perl
# Copyright (C) 2007-2014, Parrot Foundation.
# 02-install_files.t
use strict;
use warnings;
use Test::More tests => 16;
use Carp;
use Cwd;
use File::Copy;
use File::Temp qw( tempdir );
use lib qw( lib );
use Parrot::Install qw(
install_files
create_directories
);
use Parrot::Configure::Utils qw( capture );
my $cwd = cwd();
my $testsourcedir = qq{$cwd/t/tools/install/testlib};
{
my $tdir = tempdir( CLEANUP => 1 );
$tdir .= '/';
my @dirs = qw(foo/bar foo/bar/baz);
create_directories($tdir, { map { $_ => 1 } @dirs });
{
my ( $rv, $stdout, $stderr, $retval ) =
capture(sub { install_files("destdir", 1); });
like($retval, qr/Error: parameter \$options must be a hashref/s,
"Catches non-HASH \$options");
}
}
{
my $tdir = tempdir( CLEANUP => 1 );
$tdir .= '/';
my @dirs = qw(foo/bar foo/bar/baz);
create_directories($tdir, { map { $_ => 1 } @dirs });
{
my ( $rv, $stdout, $stderr, $retval ) =
capture( sub { install_files({}); });
like($retval, qr/Error: parameter \$files must be an array/s,
"Catches non-ARRAY \$files");
}
}
{
my $tdir = tempdir( CLEANUP => 1 );
$tdir .= '/';
my @dirs = qw(foo/bar foo/bar/baz);
create_directories($tdir, { map { $_ => 1 } @dirs });
# Case where element in @files is not a hash ref
my $files_ref = [ q[] ];
{
my ( $stdout, $stderr, $rv );
eval {
capture(
sub { $rv = install_files({'dry-run'=>1}, '', $files_ref); },
\$stdout,
\$stderr,
);
};
like($stderr, qr/Bad reference passed in \$files/,
"Catches non-HASH files");
like( $stdout, qr/Installing \.\.\./,
'Got expected installation message' );
}
}
{
my $tdir = tempdir( CLEANUP => 1 );
$tdir .= '/';
my @dirs = qw(foo/bar foo/bar/baz);
create_directories($tdir, { map { $_ => 1 } @dirs });
my $files_ref = [ {
Source => "$testsourcedir/README.pod",
Dest => "$dirs[0]/README.pod",
} ];
{
my ( $stdout, $stderr, $rv );
capture(
sub { $rv = install_files({'dry-run'=>1},'',$files_ref); },
\$stdout,
\$stderr,
);
ok( $rv, 'install_files() completed successfully in dry-run case' );
my $files_created = 0;
foreach my $el (@$files_ref) {
$files_created++ if -f $tdir . $el->{Dest};
}
is( $files_created, 0, 'Dry run, so no files created' );
like( $stdout, qr/Installing.*README\.pod.*README\.pod/s,
'Got expected installation message' );
$stdout =~ qr/Installing.*README\.pod.*README\.pod/s
or print "Warning was: $stderr";
}
{
my ( $stdout, $stderr, $rv );
capture(
sub { $rv = install_files({destdir=>$tdir, 'dry-run'=>0}, '',
$files_ref); },
\$stdout,
\$stderr,
);
ok( $rv, 'install_files() completed successfully in production case' );
my $files_created = 0;
foreach my $el (@$files_ref) {
$files_created++ if -f "$tdir$el->{Dest}";
}
is( $files_created, 1, 'Production, so 1 file created' );
like( $stdout, qr/Installing.*README\.pod/s,
'Got expected installation message' );
}
}
{
local $^O = 'cygwin';
my $tdir = tempdir( CLEANUP => 1 );
chdir $tdir or die "Unable to change to testing directory: $!";
$tdir .= '/';
my @dirs = qw(foo/bar foo/bar/baz);
create_directories($tdir, { map { $_ => 1 } @dirs });
my @testingfiles = qw( README.pod phony );
foreach my $f ( @testingfiles ) {
copy "$testsourcedir/$f", "$tdir/$f"
or die "Unable to copy $f prior to testing: $!";
}
my $files_ref = [
{
Source => "$tdir/README.pod",
Dest => "$dirs[0]/README.pod",
},
{
Source => "$tdir/phony",
Dest => "$dirs[0]/phony",
},
];
{
my ( $stdout, $stderr, $rv );
capture(
sub { $rv = install_files({destdir=>$tdir, 'dry-run'=>0}, '',
$files_ref); },
\$stdout,
\$stderr,
);
ok( $rv, 'install_files() completed successfully in mock-Cygwin case' );
my $files_created = 0;
foreach my $el (@$files_ref) {
$files_created++ if -f "$tdir$el->{Dest}";
}
is( $files_created, 2, 'Production, so 2 files created' );
like( $stdout, qr/Installing.*README\.pod.*phony/s,
'Got expected installation message' );
}
chdir $cwd or die "Unable to change back to starting directory: $!";
}
{
my $tdir = tempdir( CLEANUP => 1 );
$tdir .= '/';
my @dirs = qw(foo/bar foo/bar/baz);
create_directories($tdir, { map { $_ => 1 } @dirs });
# Case where element in @files does not hold existent file
my $nonexistent = q{ajdpfadksjfjvjkvds} . $$;
my $files_ref = [
{
Source => $nonexistent,
Dest => "$dirs[0]/$nonexistent",
}
];
{
my ( $stdout, $stderr, $rv );
capture(
sub { $rv = install_files({destdir=>$tdir, 'dry-run'=>0}, '', $files_ref); },
\$stdout,
\$stderr,
);
ok( $rv, 'install_files() handled non-existent file as expected' );
like( $stdout, qr/Installing \.\.\./,
'Got expected installation message' );
}
}
pass("Completed all tests in $0");
################### DOCUMENTATION ###################
=head1 NAME
02-install_files.t - test subroutines exported by C<Parrot::Install>
=head1 SYNOPSIS
% prove t/tools/install/02-install_files.t
=head1 DESCRIPTION
The files in this directory test functionality used by the scripts
F<tools/dev/install_files.pl>, F<tools/dev/install_doc_files.pl> and
F<tools/dev/install_dev_files.pl> and are exported by
F<lib/Parrot/Install.pm>.
=head1 AUTHOR
James E Keenan and Timothy S Nelson
=head1 SEE ALSO
Parrot::Install, F<tools/dev/install_files.pl>,
F<tools/dev/install_doc_files.pl>, F<tools/dev/install_dev_files.pl>
=cut
# Local Variables:
# mode: cperl
# cperl-indent-level: 4
# fill-column: 78
# End:
# vim: expandtab shiftwidth=4: