[Koha-patches] [PATCH] test suite: allow skipping of expensive tests

Andrew Moore andrew.moore at liblime.com
Mon May 19 16:59:02 CEST 2008


From: Galen Charlton <galen.charlton at liblime.com>

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 at liblime.com>
---
 t/Makefile                  |    7 ++++++-
 t/lib/KohaTest.pm           |   31 +++++++++++++++++++++++++++++++
 t/lib/KohaTest/Installer.pm |    2 ++
 3 files changed, 39 insertions(+), 1 deletions(-)

diff --git a/t/Makefile b/t/Makefile
index cfe15d2..213a513 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 440db79..8c857c9 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 97d4ebb..2a0f9f9 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 ) {
-- 
1.5.5.rc0.16.g02b00




More information about the Koha-patches mailing list