App-Fetchware

 view release on metacpan or  search on metacpan

lib/Test/Fetchware.pm  view on Meta::CPAN

#

# These tags go with the override() subroutine, and together allow you to
# replace some or all of fetchware's default behavior to install unusual
# software.
our %EXPORT_TAGS = (
    TESTING => [qw(
        eval_ok
        print_ok
        fork_ok
        fork_not_ok
        skip_all_unless_release_testing
        make_clean
        make_test_dist
        md5sum_file
        expected_filename_listing
        verbose_on
        export_ok
        end_ok
        add_prefix_if_nonroot
        create_test_fetchwarefile

lib/Test/Fetchware.pm  view on Meta::CPAN

    }

    # And test that the child returned successfully.
    ok(($? >> 8) == 0, $test_name);

    return $?;
}



sub fork_not_ok {
    my $coderef = shift;
    my $test_name = shift;


    my $kid = fork;
    die "Couldn't fork: $!\n" if not defined $kid;
    # ... parent code here ...
    if ( $kid ) {
        # Block waiting for the child process ($kid) to exit.
        waitpid($kid, 0);

lib/Test/Fetchware.pm  view on Meta::CPAN


fork_ok() has a major bug that makes any tests you attempt to run in
&code_fork_should_do that fail never report this failure properly to
Test::Builder. Also, any success is not reported either. This is not fork_ok()'s
fault it is Test::Builder's fault for still not having support for forking. This
lack of support for forking may be fixed in Test::Builder 1.5 or perhaps 2.0,
but those are still in development.

=back

=head2 fork_not_ok()

    fork_not_ok(&code_fork_should_do, $test_name);

The exact same thing as fork_ok() except it expects failure and reports true
when the provided coderef returns failure. If the provided coderef returns true,
then it reports failure to the test suite.

The same warnings and problems associated with fork_ok() apply to fork_not_ok().

=head2 skip_all_unless_release_testing()

    subtest 'some subtest that tests fetchware' => sub {
        skip_all_unless_release_testing();

        # ... Your tests go here that will be skipped unless
        # FETCHWARE_RELEASE_TESTING among other env vars are set properly.
    };

t/Test-Fetchware.t  view on Meta::CPAN

}



###BUGALERT### Add tests for :TESTING subs that have no tests!!!
subtest 'TESTING export what they should' => sub {
    my @expected_testing_exports = qw(
        eval_ok
        print_ok
        fork_ok
        fork_not_ok
        skip_all_unless_release_testing
        make_clean
        make_test_dist
        md5sum_file
        expected_filename_listing
        verbose_on
        export_ok
        end_ok
        add_prefix_if_nonroot
        create_test_fetchwarefile

t/Test-Fetchware.t  view on Meta::CPAN

    # success. When this test fails it succeeds, because it is testing failure.
    TODO: {
        todo_skip 'Turn failure into success.', 1;

        fork_ok(sub { return 0 },
            'checked fork_ok() failure.');
    }
};


subtest 'test fork_not_ok()' => sub {
    fork_not_ok(sub {ok(0, 'successful fork_not_ok() test.')},
        'checked fork_not_ok() success.');

    # Abuse a TODO block to test fork_not_ok() failure by turning that failure into
    # success. When this test fails it succeeds, because it is testing failure.
    TODO: {
        todo_skip 'Turn failure into success.', 1;

        fork_not_ok(sub { return 1 },
            'checked fork_not_ok() failure.');
    }
};


subtest 'test rmdashr_ok()' => sub {
    # rmdashr_ok() calls Test::More functions for me, so I can skip them here.
    # Perhaps Test::Module testing stuff should be used for this instead?

    my ($fh, $filename) = tempfile('fetchware-test-XXXXXXXXX', TMPDIR => 1);
    close $filename; # Don't actually need $filname open.

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

    my $fail_test_dist = make_test_dist(file_name => 'fail-dist',
        ver_num => '1.00', configure => <<EOF);
# A test ./configure for testing cmd_install() failing

echo "fetchware: ./configure failed!"
# Return failure exit status to truly indicate failure.
exit 1
EOF
    my $fail_dist_md5 = md5sum_file($fail_test_dist);

	fork_not_ok(sub {cmd_install($fail_test_dist)},
		'checked cmd_install() failure.');
};



subtest 'test cmd_install(else)' => sub {
    eval_ok(sub {cmd_install()}, <<EOE, 'checked cmd_install() no args');
fetchware: You called fetchware install incorrectly. You must also specify
either a Fetchwarefile or a fetchware package that ends with [.fpkg].
EOE



( run in 0.379 second using v1.01-cache-2.11-cpan-0a987023a57 )