test suite: way to run single test file
authorGalen Charlton <galen.charlton@liblime.com>
Thu, 3 Jul 2008 18:34:03 +0000 (13:34 -0500)
committerJoshua Ferraro <jmf@liblime.com>
Fri, 4 Jul 2008 14:22:24 +0000 (09:22 -0500)
Added support for a new target in the test Makefile
to run a single test module.  If you do (for example)

make test-single TEST_FILES=lib/KohaTest/Biblio.pm

only the tests in that module will be run.  Unlike
the full test suite as run via 'make test', 'make test-single'
does not clear the test database before running the
tests.

Please note that "TEST_FILES=path/to/test/class.pm" is
required when using 'make test-single'.

Signed-off-by: Andrew Moore <andrew.moore@liblime.com>
Signed-off-by: Joshua Ferraro <jmf@liblime.com>
t/Makefile
t/lib/KohaTest.pm

index 213a513..b135359 100644 (file)
@@ -62,6 +62,10 @@ test :: config_file $(ZEBRA_CONF_FILES) $(SCRIPTS)
        KOHA_CONF=$(TEST_CONF_FILE) PERL5LIB=$(PERL5LIB) TEST_CLASS=$(TEST_CLASS) RUN_EXPENSIVE_TESTS=$(RUN_EXPENSIVE_TESTS) \
                $(PROVE) $(PROVE_FLAGS) $(TEST_FILES) 
 
+test-single :: config_file $(ZEBRA_CONF_FILES) $(SCRIPTS)
+       KOHA_CONF=$(TEST_CONF_FILE) PERL5LIB=$(PERL5LIB) RUN_EXPENSIVE_TESTS=1 SINGLE_TEST=1 \
+               $(PROVE) $(PROVE_FLAGS) -Ilib $(TEST_FILES)
+
 fulltest :: RUN_EXPENSIVE_TESTS = 1
 fulltest :: test
 
index 8ff9fd0..31183ee 100644 (file)
@@ -19,12 +19,28 @@ use C4::Search;
 use C4::Installer;
 use C4::Languages;
 use File::Temp qw/ tempdir /;
+use CGI;
 
 # Since this is an abstract base class, this prevents these tests from
 # being run directly unless we're testing a subclass. It just makes
 # things faster.
 __PACKAGE__->SKIP_CLASS( 1 );
 
+INIT {
+    if ($ENV{SINGLE_TEST}) {
+        # if we're running the tests in one
+        # or more test files specified via
+        #
+        #   make single-test TEST_FILES=lib/KohaTest/Foo.pm
+        #
+        # use this INIT trick taken from the POD for
+        # Test::Class::Load.
+        start_zebrasrv();
+        Test::Class->runtests;
+        stop_zebrasrv();
+    }
+}
+
 use Attribute::Handlers;
 
 =head2 Expensive test method attribute