From 8645d38f41b11ff4c35c51bf967fa2d83a4c850e Mon Sep 17 00:00:00 2001 From: Galen Charlton Date: Mon, 19 May 2008 09:59:02 -0500 Subject: [PATCH] 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 Signed-off-by: Joshua Ferraro --- t/Makefile | 7 ++++++- t/lib/KohaTest.pm | 31 +++++++++++++++++++++++++++++++ t/lib/KohaTest/Installer.pm | 2 ++ 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/t/Makefile b/t/Makefile index cfe15d2fd7..213a513e4d 100644 --- a/t/Makefile +++ b/t/Makefile @@ -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 diff --git a/t/lib/KohaTest.pm b/t/lib/KohaTest.pm index 440db79833..8c857c9b20 100644 --- a/t/lib/KohaTest.pm +++ b/t/lib/KohaTest.pm @@ -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 diff --git a/t/lib/KohaTest/Installer.pm b/t/lib/KohaTest/Installer.pm index 97d4ebb2a0..2a0f9f93d8 100644 --- a/t/lib/KohaTest/Installer.pm +++ b/t/lib/KohaTest/Installer.pm @@ -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 ) { -- 2.39.5