App-Fetchware
view release on metacpan or search on metacpan
t/App-Fetchware-install.t view on Meta::CPAN
my $class = 'App::Fetchware';
subtest 'OVERRIDE_INSTALL exports what it should' => sub {
my @expected_overide_install_exports = qw(
chdir_unless_already_at_path
);
# sort them to make the testing their equality very easy.
my @sorted_install_tag = sort @{$App::Fetchware::EXPORT_TAGS{OVERRIDE_INSTALL}};
@expected_overide_install_exports = sort @expected_overide_install_exports;
is_deeply(\@sorted_install_tag, \@expected_overide_install_exports,
'checked for correct OVERRIDE_INSTALL @EXPORT_TAG');
};
subtest 'test chdir_unless_already_at_path() success' => sub {
# Create a temporary directory in tmpdir(), and then chdir to tmpdir(), and
# then run chdir_unless_already_at_path($the_created_tempdir).
my $temp_dir = tempdir("fetchware-test-$$-XXXXXXXXXX",
TMPDIR => 1, CLEANUP => 1);
# Keep $old_cwd for chdir() back after testing.
my $old_cwd = cwd();
ok(chdir(tmpdir()),
'chdir()d to tmpdir()');
chdir_unless_already_at_path($temp_dir);
is(cwd(), $temp_dir,
'checked chdir_unless_already_at_path() success.');
# Now repeat the call to chdir_unless_already_at_path(), and this time it
# should do basically nothing, because we're already at the correct path.
# This is what happens when stay_root is in effect.
chdir_unless_already_at_path($temp_dir);
is(cwd(), $temp_dir,
'checked chdir_unless_already_at_path() success.');
# Undo the chdir().
ok(chdir($old_cwd),
'chdir()d back to original working directory.');
};
my $build_path;
subtest 'do prerequisites' => sub {
skip_all_unless_release_testing();
# Needed by all other subtests.
my $package_path = $ENV{FETCHWARE_LOCAL_BUILD_URL};
fail("FETCHWARE environment vars not set!!! Run frt()")
if not defined $package_path;
# Because these tests call App::Fetchware's API subs directly, and even skip
# some steps such as verification, I need to add a prefix configuration
# option manually with config(). This option enabled only when run non-root
# causes fetchware to install its program to a different writable directory
# other than the system ones, which are only writable by root. Also, do this
# when running on an OS other than Unix.
if (not is_os_type('Unix') or $> != 0 ) {
my $temp_dir = tempdir("fetchware-test-$$-XXXXXXXXXX", TMPDIR => 1, CLEANUP => 1);
note("Running as nonroot or nonunix using prefix temp dir [$temp_dir]");
config(prefix => $temp_dir);
}
# Call start() to create & cd to a tempdir, so end() called later can delete all
# of the files that will be downloaded.
start();
# Copy the $ENV{FETCHWARE_LOCAL_URL}/$package_path file to the temp dir, which
# is what download would normally do for fetchware.
cp("$package_path", '.') or die "copy $package_path failed: $!";
$build_path = unarchive($package_path);
ok($build_path, 'prerequisite install() run');
ok(build($build_path), 'prerequisite build() run');
};
subtest 'test install() default success' => sub {
skip_all_unless_release_testing();
ok(install($build_path), 'checked install() success.');
};
subtest 'test install() make_options success' => sub {
skip_all_unless_release_testing();
make_options '-j4';
ok(install($build_path), 'checked install() make_options success.');
config_delete('make_options');
};
subtest 'test install() install_commands success' => sub {
skip_all_unless_release_testing();
install_commands 'make install';
ok(install($build_path), 'checked install() make_options success.');
config_delete('install_commands');
install_commands 'make install', 'make clean';
ok(install($build_path), 'checked install() install_commands success.');
config_delete('install_commands');
};
subtest 'test install() no_install success' => sub {
# Skip this test, because its prereqs won't be done when we're not release
# testing.
skip_all_unless_release_testing();
no_install 'True';
is(install($build_path), 'installation skipped!',
'checked install() no_install success');
};
subtest 'Call end() to delete temporary directory.' => sub {
# Skip this test, because its prereqs won't be done when we're not release
# testing.
skip_all_unless_release_testing();
( run in 2.025 seconds using v1.01-cache-2.11-cpan-64ef6c95b5d )