App-Fetchware
view release on metacpan or search on metacpan
t/bin-fetchware-uninstall.t view on Meta::CPAN
# is installed. This is to avoid any conflicts with already installed fetchware
# packages, because if the actual fetchware database path is used for this test,
# then this test will actually upgrade any installed fetchware packages. Early
# in testing I found this acceptable, but now it's a massive bug. I've already
# implemented the FETCHWARE_DATABASE_PATH evironment variable, so I may as well
# take advantage of it.
$ENV{FETCHWARE_DATABASE_PATH} = tempdir("fetchware-test-$$-XXXXXXXXXX",
CLEANUP => 1, TMPDIR => 1);
ok(-e $ENV{FETCHWARE_DATABASE_PATH},
'Checked creating upgrade test FETCHWARE_DATABASE_PATH success.');
# Only those who run fetchware's own author tests will have
# FETCHWARE_NONROOT_USER set when the test suite runs. So most users will get an
# annoying uninitialized warning from this. Also, this will set the user config
# file option to the empty string, which fetchware most likely considers similar
# to undef so that probably doesn't cause any weird bugs. To deal with this
# situation, I'll just set it here to nobody, which is otherwise the default
# anyway.
#
# Other options are to have if statements everywhere FETCHWARE_NONROOT_USER is
# used. Something like.
#
# if (defined $ENV{FETCHWARE_NONROOT_USER}) {
# my $test_dist_path = make_test_dist(file_name => 'test-dist',
# ver_num => '1.00',
# append_option => qq{user '$ENV{FETCHWARE_NONROOT_USER}';});
# } else {
# my $test_dist_path = make_test_dist(file_name => 'test-dist',
# ver_num => '1.00');
# }
# But that's fugly, and adds annoying code duplication. I know my test suite was
# created with loads of copy and paste, but that doesn't mean this kind of
# garbage code is okay. I'd kill for like a line oriented, smart (meaning fixes
# obvious syntax errors for you) ifdef system where I could just if def this
# argument, where only if FETCHWARE_NONROOT_USER was defined this stupid
# argument would be added. Do Perl 6 macros do this???
$ENV{FETCHWARE_NONROOT_USER} = 'nobody' if not defined $ENV{FETCHWARE_NONROOT_USER};
my $fetchware_package_path;
subtest 'test cmd_uninstall() success' => sub {
skip_all_unless_release_testing();
# Changed from FETCHWARE_HTTP_LOOKUP_URL, because Apache does *not* have a make # uninstall, which fetchware needs for automatic package uninstalltion.
my ($vol, $dirs, $file) = splitpath("$ENV{FETCHWARE_LOCAL_BUILD_URL}");
note("VOL[$vol][$dirs][$file]");
my $lookup_url = "file://$dirs";
note("LOOKUPURL[$lookup_url]");
my $fetchwarefile = <<EOF;
use App::Fetchware;
program 'ctags';
lookup_url '$lookup_url';
# Must provide a mirror as well, so just use the same thing as the lookup_url.
mirror '$lookup_url';
filter 'ctags';
###BUGALERT### Add local verification for this.
verify_failure_ok 'On';
# FETCHWARE_LOCAL_URL is in a user's home directory, so drop_privs() default of
# nobody has no access to this directory hence need for user config option.
user '$ENV{FETCHWARE_NONROOT_USER}';
EOF
note('FETCHWAREFILE');
note("$fetchwarefile");
my $fetchwarefile_path = create_test_fetchwarefile($fetchwarefile);
ok(-e $fetchwarefile_path,
'check create_test_fetchwarefile() test Fetchwarefile');
# I obviously must install apache before I can test uninstalling it :)
$fetchware_package_path = cmd_install($fetchwarefile_path);
# And then test if the install was successful.
ok(grep /ctags/, glob(catfile(fetchware_database_path(), '*')),
'check cmd_install(Fetchware) success.');
# Clear internal %CONFIG variable, because I have to pare a Fetchwarefile
# twice, and it's only supported once.
__clear_CONFIG();
# cmd_uninstall accepts a string that needs to be found in the fetchware
# database. It does *not* take Fetchwarefiles or fetchware packages as
# arguments.
my $uninstalled_package_path = cmd_uninstall('ctags');
like($fetchware_package_path, qr/$uninstalled_package_path/,
'check cmd_install(Fetchware) success.');
};
subtest 'test cmd_uninstall() failure' => sub {
skip_all_unless_release_testing();
# Save cwd to chdir to it later, because the uninstall exceptions that I'm
# trapping below do *not* chdir back to the main fetchware directory after
# they are thrown, so I must do it manually.
my $original_cwd = cwd();
###BUGALERT### The exception below cannot be tested, because the condition it
#tests for is tested previously as tested in the test below. Remove throwing
#this exception, or move throwing it to cmd_uninstall() from
#determine_fetchware_package_path().
### eval_ok(sub {cmd_uninstall('fetchware-test' . rand(2838382828282))},
### <<EOE, 'checkec cmd_uninstall() package existence
###fetchware: The argument you provided to fetchware upgrade was not found in
###fetchware's package database. To get a list of available packages to upgrade
###just run the fetchware list command to list all installed packages. Select one
###of those to upgrade, and then rerun fetchware upgrade.
###EOE
# Test for correct error if a package isn't installed.
eval_ok(sub {cmd_uninstall('fetchware-test' . rand(3739929293))},
# Use a regex, because a variable is interpolated in the error message.
qr/fetchware: Fetchware failed to determine the fetchware package that is
associated with the argument that you provided to fetchware/ ,
'checked cmd_uninstall() package existence');
( run in 0.822 second using v1.01-cache-2.11-cpan-39bf76dae61 )