Module:...stTarget(3)
π Module::Install::TestTarget π
hey bestie, welcome to the Module:...stTarget(3) page from the User Contributed Perl Documentation crew π«Ά this is the whole vibe: custom test targets for make, assembled with code snippets so your distribution gets tested under all kinds of conditions. no cap.
πΈ NAME πΈ
Module::Install::TestTarget β Assembles Custom Test Targets For make β¨
β¨ SYNOPSIS β¨
okay so inside Makefile.PL, itβs giving this:
use inc::Module::Install;
tests 't/*t';
# override the default `make test`
default_test_target
includes => ["$ENV{HOME}/perl5/lib"],
load_modules => [qw/Foo Bar/],
run_on_prepare => [qw/before.pl/],
run_on_finalize => [qw/after.pl/],
insert_on_prepare => ['print "start -> ", scalar localtime, "\n"'],
insert_on_finalize => ['print "end -> ", scalar localtime, "\n"'],
tests => ['t/baz/*t'],
env => { PERL_ONLY => 1 },
;
# create a new test target (allows `make foo`)
test_target foo => (
includes => ["$ENV{HOME}/perl5/lib"],
load_modules => [qw/Foo Bar/],
run_on_prepare => [qw/before.pl/],
run_on_finalize => [qw/after.pl/],
insert_on_prepare => ['print "start -> ", scalar localtime, "\n"'],
insert_on_finalize => ['print "end -> ", scalar localtime, "\n"'],
tests => ['t/baz/*t'],
env => { PERL_ONLY => 1 },
alias => 'testall', # make testall is run the make foo
);
# above target 'foo' will turn into something like:
perl "-MExtUtils::Command::MM" "-I/home/xaicron/perl5/lib" "-MFoo" "-MBar" "-e" "do { local \$@; do 'before.pl'; die \$@ if $@ }; sub { print \"start -> \", scalar localtime, \"\n\" }->(); test_harness(0, 'inc'); do { local \$@; do 'after.pl'; die \$@ if \$@ }; sub { print \"end -> \", scalar localtime, \"\n\" }->();" t/baz/*t
π¦ DESCRIPTION π¦
Module::Install::TestTarget creates make test variations with code snippets. This helps module developers to test their distributions with various conditions. literally a lil custom test-target machine, and it eats π
π EXAMPLES π
π§ͺ TEST A MODULE WITH XS/PP BACKENDS π§ͺ
Suppose your XS module can load a PurePerl backend by setting the PERL_ONLY environment variable. You can force your tests to use this environment flag using this construct:
test_target test_pp => (
env => { PERL_ONLY => 1 },
);
π’οΈ TEST AN APP USING DATABASES π’οΈ
Suppose you want to instantiate a mysqld instance using Test::mysqld, but you donβt want to start/stop mysqld for every test script. You can start mysqld once using this module.
First create a script like this:
# t/start_mysqld.pl
use Test::mysqld;
my $mysqld = Test::mysqld->new( ... );
Then in your Makefile.PL, simply specify that you want to run this script before executing any tests.
test_target test_db => (
run_on_prepare => [ 't/start_mysqld.pl' ]
);
Since the script is going to be executed in global scope, $mysqld will stay active during the execution of your tests -- the mysqld instance that came up will shutdown automatically after the tests are executed.
You can use this trick to run other daemons, such as memcached (maybe via Test::Memcached) π
π§° FUNCTIONS π§°
test_target($target, %args)
Defines a new test target with %args.
%args are:
includes => \@include_pathsβ Sets include paths.
test_target foo => (
includes => ['/path/to/inc'],
);
# `make foo` will be something like this:
perl -I/path/to/inc -MExtUtils::Command::MM -e "test_harness(0, 'inc')" t/*t
load_modules => \@module_namesβ Sets modules which are loaded before runningtest_harness().
test_target foo => (
load_modules => ['Foo', 'Bar::Baz'],
);
# `make test` will be something like this:
perl -MFoo -MBar::Baz -MExtUtils::Command::MM -e "test_harness(0, 'inc')" t/*t
run_on_prepare => \@scriptsβ Sets scripts to run before runningtest_harness().
test_target foo => (
run_on_prepare => ['tool/run_on_prepare.pl'],
);
# `make foo` will be something like this:
perl -MExtUtils::Command::MM -e "do { local \$@; do 'tool/run_on_prepare.pl; die \$@ if \$@ }; test_harness(0, 'inc')" t/*t
run_on_finalize => \@scriptsβ Sets scripts to run after runningtest_harness().
use inc::Module::Install;
tests 't/*t';
test_target foo => (
run_on_finalize => ['tool/run_on_after.pl'],
);
# `make foo` will be something like this:
perl -MExtUtils::Command::MM -e "test_harness(0, 'inc'); do { local \$@; do 'tool/run_on_after.pl; die \$@ if \$@ };" t/*t
insert_on_prepare => \@codesβ Sets perl codes to run before runningtest_harness().
use inc::Module::Install;
tests 't/*t';
test_target foo => (
insert_on_prepare => ['print scalar localtime , "\n"', sub { system qw/cat README/ }],
);
# `make foo` will be something like this:
perl -MExtUtils::Command::MM "sub { print scalar localtme, "\n" }->(); sub { system 'cat', 'README' }->(); test_harness(0, 'inc')" t/*t
The perl codes run, and run_on_prepare runs later.
insert_on_finalize => \@codesβ Sets perl codes to run after runningtest_harness().
use inc::Module::Install;
tests 't/*t';
test_target foo => (
insert_on_finalize => ['print scalar localtime , "\n"', sub { system qw/cat README/ }],
);
# `make foo` will be something like this:
perl -MExtUtils::Command::MM "test_harness(0, 'inc'); sub { print scalar localtme, "\n" }->(); sub { system 'cat', 'README' }->();" t/*t
The perl codes run, and run_on_finalize runs later.
alias => $nameβ Sets an alias of the test.
test_target test_pp => (
run_on_prepare => 'tool/force-pp.pl',
alias => 'testall',
);
# `make test_pp` and `make testall` will be something like this:
perl -MExtUtils::Command::MM -e "do { local \$@; do 'tool/force-pp.pl'; die \$@; if \$@ }; test_harness(0, 'inc')" t/*t
alias_for_author => $nameβ The same asalias, but only enabled if it is in authorβs environment.env => \%envβ Sets environment variables.
test_target foo => (
env => {
FOO => 'bar',
},
);
# `make foo` will be something like this:
perl -MExtUtils::Command::MM -e "\$ENV{q{FOO}} = q{bar}; test_harness(0, 'inc')" t/*t
tests => \@test_filesβ Sets test files to run.
test_target foo => (
tests => ['t/foo.t', 't/bar.t'],
env => { USE_FOO => 1 },
);
# `make foo` will be something like this:
perl -MExtUtils::Command::MM -e "$ENV{USE_FOO} = 1 test_harness(0, 'inc')" t/foo.t t/bar.t
default_test_target(%args)
Override the default make test with %args.
Same argument as test_target(), but target and alias are not allowed.
π AUTHOR π
Yuji Shimada <xaicron {at} cpan.org>Goro Fuji (gfx) <gfuji at cpan.org>Maki Daisuke (lestrrat)
π SEE ALSO π
Module::Install
π LICENSE π
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
mwah π thatβs the whole page β itβs from perl v5.40.0, dated 2024-09-05, and the page is Module:...stTarget(3) π¦β¨
π¦ where this page comes from
- epel 10: perl-Module-Install-TestTarget 0.19-36.el10_0 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms