test suite: allow skipping of expensive tests

Defined a function attribute for KohaTest and subclasses
called 'Expensive'.  When a test method has that attribute,
it is skipped unless the RUN_EXPENSIVE_TESTS environment
variable is true.

To mark a test method, expensive, do this:

sub test_foo : Tests(4) Expensive { ... }

To mark a whole class and its subclasses expensive,
define a SKIP_CLASS sub (with empty body) with the
Expensive attribute:

sub SKIP_CLASS : Expensive { }

Updated the t/Makefile so that 'make test' runs
nonexpensive tests, while 'make fulltest' runs both
cheap and expensive tests.

Marked KohaTest::Installer test class expensive.

Signed-off-by: Andrew Moore <andrew.moore@liblime.com>
Signed-off-by: Joshua Ferraro <jmf@liblime.com>
This commit is contained in:
Galen Charlton 2008-05-19 09:59:02 -05:00 committed by Joshua Ferraro
parent a53aa294f7
commit 8645d38f41
3 changed files with 39 additions and 1 deletions

View File

@ -13,6 +13,7 @@ PERL = /usr/bin/perl
# TEST_FILES = *.t
TEST_FILES = database_dependent.pl
TEST_CLASS =
RUN_EXPENSIVE_TESTS = 0
PROVE = /usr/bin/prove
PROVE_FLAGS = -v
PERL5LIB = ..
@ -58,7 +59,11 @@ $(SCRIPTS) ::
$(CHMOD) 755 $(TEST_SCRIPT_DIR)/$@
test :: config_file $(ZEBRA_CONF_FILES) $(SCRIPTS)
KOHA_CONF=$(TEST_CONF_FILE) PERL5LIB=$(PERL5LIB) TEST_CLASS=$(TEST_CLASS) $(PROVE) $(PROVE_FLAGS) $(TEST_FILES)
KOHA_CONF=$(TEST_CONF_FILE) PERL5LIB=$(PERL5LIB) TEST_CLASS=$(TEST_CLASS) RUN_EXPENSIVE_TESTS=$(RUN_EXPENSIVE_TESTS) \
$(PROVE) $(PROVE_FLAGS) $(TEST_FILES)
fulltest :: RUN_EXPENSIVE_TESTS = 1
fulltest :: test
test_run_dirs ::
$(MKPATH) run/etc

View File

@ -25,6 +25,37 @@ use File::Temp qw/ tempdir /;
# things faster.
__PACKAGE__->SKIP_CLASS( 1 );
use Attribute::Handlers;
=head2 Expensive test method attribute
If a test method is decorated with an Expensive
attribute, it is skipped unless the RUN_EXPENSIVE_TESTS
environment variable is defined.
To declare an entire test class and its subclasses expensive,
define a SKIP_CLASS with the Expensive attribute:
sub SKIP_CLASS : Expensive { }
=cut
sub Expensive : ATTR(CODE) {
my ($package, $symbol, $sub, $attr, $data, $phase) = @_;
my $name = *{$symbol}{NAME};
if ($name eq 'SKIP_CLASS') {
if ($ENV{'RUN_EXPENSIVE_TESTS'}) {
*{$symbol} = sub { 0; }
} else {
*{$symbol} = sub { "Skipping expensive test classes $package (and subclasses)"; }
}
} else {
unless ($ENV{'RUN_EXPENSIVE_TESTS'}) {
# a test method that runs no tests and just returns a scalar is viewed by Test::Class as a skip
*{$symbol} = sub { "Skipping expensive test $package\:\:$name"; }
}
}
}
=head2 startup methods

View File

@ -8,6 +8,8 @@ use Test::More;
use C4::Languages;
use C4::Installer;
sub SKIP_CLASS : Expensive { }
sub testing_class { 'C4::Installer' };
sub methods : Test( 1 ) {