App-Fetchware

 view release on metacpan or  search on metacpan

t/bin-fetchware-util.t  view on Meta::CPAN

    test_config({program => 'who cares',
            lookup_url => 'http://doesnt.exist/anywhere'},
        'checked parse_fetchwarefile() success CONFIG');

    my $no_use_fetchware = <<EOS;
program 'who cares';

lookup_url 'http://doesnt.exist/anywhere';

mirror 'http://doesnt.exist/anywhere/either';
EOS
    eval_ok(sub {parse_fetchwarefile(\$no_use_fetchware)},
        <<EOE, 'checked parse_fetchwarefile() no use fetchware');
fetchware: The fetchwarefile you provided did not have a [use App::Fetchware]
line in it. This line is required, because it is an important part of how
fetchware uses Perl for its configuration file. Your fetchware file was.
[program 'who cares';

lookup_url 'http://doesnt.exist/anywhere';

mirror 'http://doesnt.exist/anywhere/either';
]
EOE

    my $syntax_errors = <<EOS;
# J Random syntax error.
# Test for syntax error other than forgetting to use App::Fetchware;
use App::Fetchware;
for {
EOS

    eval_ok(sub {parse_fetchwarefile(\$syntax_errors)},
        qr/fetchware failed to execute the Fetchwarefile/,
        'checked parse_fetchwarefile() failed to execute Fetchwarefile');

    # Cleanup previous calls.
    __clear_CONFIG();

    my $api_subs_exported = <<EOS;
use App::Fetchware;

program 'who cares';
lookup_url 'none://';

mirror 'http://doesnt.exist/anywhere/either';

# Use extra perl code to "delete" some of the API subs to test that they weren't
# exported.
use Sub::Mage;
withdraw('lookup');
withdraw('install');
EOS

    eval_ok(sub {parse_fetchwarefile(\$api_subs_exported)},
        qr/fetchware: The App::Fetchware module you choose in your fetchwarefile does not/,
        'checked parse_fetchwarefile() failed to export api subs.');
};


subtest 'test create_fetchware_package()' => sub {
    ###BUGALERT### Must add tests for adding the gpg generated files to the
    #fetchware package, so that gpg doesn't have to download the keys again.
    #Also, I must actually add code for this in bin/fetchware.

    my $fetchwarefile = '# Fake Fetchwarefile for testing';

    # Create a hopefully successful fetchware package using the current working
    # directory (my Fetchware git checkout) and the fake Fetchwarefile I created
    # above.
    my $cwd = dir(cwd());
    my $cwd_parent = $cwd->parent();
    my $cwd_lastdir = $cwd->dir_list(-1, 1);
    is(create_fetchware_package(\$fetchwarefile, cwd(), $cwd_parent),
        catfile($cwd_parent, "$cwd_lastdir.fpkg"),
        'checked create_fetchware_package() success');

    is(cwd(), $cwd,
        'checked create_fetchware_package() chdir back to base directory');

    # Delete generated files.
    ok(unlink(catfile($cwd_parent,"$cwd_lastdir.fpkg")) == 1,
        'checked create_fetchware_package() delete generated files');

##CANNOTTEST## Can't test anymore, because the doesntexist.ever-anywhere file
#will fail the unless conditional and skip the cp() call, so I can't test for
#this specifically anymore.
##CANNOTTEST##    eval_ok(sub {create_fetchware_package('doesntexist.ever-anywhere', cwd())},
##CANNOTTEST##        <<EOE, 'checked create_fetchware_package() cp failure');
##CANNOTTEST##fetchware: run-time error. Fetchware failed to copy the Fetchwarefile you
##CANNOTTEST##specified [doesntexist.ever-anywhere] on the command line or was contained in the
##CANNOTTEST##fetchware package you specified to the newly created fetchware package. Please
##CANNOTTEST##see perldoc App::Fetchware. OS error [No such file or directory].
##CANNOTTEST##EOE

    ok(chdir($cwd), 'checked create_fetchware_package() chdir back to base directory');

};


subtest 'check fetchware_database_path()' => sub {
    # $ENV{FETCHWARE_DATABASE_PATH} has been set to a temporary directory at the
    # top of this file, so it applies to all of these tests too; however, the
    # tests below do not read or write to the actual FETCHWARE_DATABASE_PATH;
    # instead, they just return what it should be and test that the correct
    # things are being returned. Because fetchware_database_path()'s normal
    # behavior is needed to properly test this function even as root, we should
    # local delete $ENV{FETCHWARE_DATABASE_PATH} just for this one function,
    # fetchware_database_path(), because it needs "normal" behavior for proper
    # testing, and such proper testing has no side effects like messing witht he
    # filesystem.
    local $ENV{FETCHWARE_DATABASE_PATH};
    delete $ENV{FETCHWARE_DATABASE_PATH};

    if (is_os_type('Unix', $^O)) {
        # If we're effectively root use a "system" directory.
        if ($> == 0) {
            is(fetchware_database_path(), '/var/log/fetchware',
                'checked fetchware_database_path() as root');
        # else use a "user" directory.
        } else {
            like(fetchware_database_path(),
                # Add a generic "fetchware-test", because ~/.local and /tmp are



( run in 0.899 second using v1.01-cache-2.11-cpan-df04353d9ac )