#!/usr/bin/perl =head1 NAME dh_elpa_test - run ELPA package testsuites =cut use strict; use warnings; =head1 SYNOPSIS B [S>] [S>] =head1 DESCRIPTION B is a debhelper program that is responsible for running the testsuites of ELPA packages, when those test suites use ERT or buttercup(1). dh_auto_test is rarely suitable. Testing with buttercup(1) will be activated if the package build-depends on elpa-buttercup. Testing with ERT will be activated if ERT test files can be found. =head1 ENVIRONMENT VARIABLES B will respond to the following variables set, for example, at the top of your debian/rules file. Do not surround variable values with double-quotation marks. E.g. =over 4 export DH_ELPA_TEST_BUTTERCUP_LOAD_PATH=lib,other_lib =back =over 4 =item B If this variable is set, dh_elpa(1) will not invoke B. =item B A comma-separated list of directories to add to the load-path when buttercup(1) invokes Emacs. Will be passed to buttercup(1) with its B<-L> command line argument. =item B A comma-separated list of Emacs regular expressions (not containing any commas) jointly matching all and only the files containing Buttercup tests that you wish to run. If this variable is not defined, all tests that can be found will be run. Will be passed to buttercup(1) with its B<-p> command line argument. =item B A comma-separated list of file globs matching files containing ERT tests that should not be run. =item B The name of a *.el file containing Emacs Lisp code that will run the ERT test suite. When this variable is not defined, B calls the function B<(ert-run-tests-batch-and-exit)>. Note that this is not the way to load test helpers that do needed work but don't actually run the tests. For that, you can use something like =over 4 export DH_ELPA_TEST_ERT_EVAL=(load-file "test-helper.el") =back =item B Emacs Lisp code to be run prior to running ERT tests by the Emacs instance spawned by B to run those tests. =item B A comma-separated list of directories to add to the load-path when B invokes Emacs to run ERT tests. =back =cut use Text::Glob qw{ match_glob }; use Array::Utils qw{ array_minus }; use Debian::Debhelper::Dh_Lib; use Debian::Control; if (get_buildoption("nocheck")) { exit 0; } my $control = Debian::Control->new(); $control->read("debian/control"); # these are from dh_elpa # TODO have dh_elpa export them so we can import them, instead of copy/paste my $dhelpadir="/usr/share/emacs/site-lisp/elpa"; my $elpadir="/usr/share/emacs/site-lisp/elpa-src"; # ---- Buttercup if ($control->source->Build_Depends->has( "elpa-buttercup" )) { my @args = qw{ buttercup -L . }; if (defined $ENV{'DH_ELPA_TEST_BUTTERCUP_LOAD_PATH'}) { foreach my $dir (split(',', $ENV{'DH_ELPA_TEST_BUTTERCUP_LOAD_PATH'})) { push @args, ('-L', "$dir"); } } if (defined $ENV{'DH_ELPA_TEST_BUTTERCUP_PATTERNS'}) { foreach my $pattern (split(',', $ENV{'DH_ELPA_TEST_BUTTERCUP_PATTERNS'})) { push @args, ('-p', "$pattern"); } } print_and_doit(@args); } # ---- ERT $Text::Glob::strict_wildcard_slash = 0; my @ert_files = map { s|^\./||r } split("\n", `grep -lr "ert-deftest" . --exclude-dir=.pc --exclude-dir=debian`); if (defined $ENV{'DH_ELPA_TEST_ERT_EXCLUDE'}) { foreach my $glob (split(',', $ENV{'DH_ELPA_TEST_ERT_EXCLUDE'})) { if ( my @matches = match_glob( $glob, @ert_files ) ) { @ert_files = array_minus( @ert_files, @matches ); } } } if (@ert_files) { my @args = qw{ emacs -batch -Q -l package }; push @args, ("--eval", "(add-to-list 'package-directory-list \"$dhelpadir\")"); push @args, ("--eval", "(add-to-list 'package-directory-list \"$elpadir\")"); push @args, ("-f", "package-initialize"); # work around the fact that s-el and dash-el are not packaged with # dh_elpa so aren't in $dhelpadir push @args, ("-L", "/usr/share/emacs/site-lisp/s-el") if ($control->source->Build_Depends->has( "s-el" )); push @args, ("-L", "/usr/share/emacs/site-lisp/dash-el") if ($control->source->Build_Depends->has( "dash-el" )); # add the user's load-path entries if (defined $ENV{'DH_ELPA_TEST_ERT_LOAD_PATH'}) { foreach my $dir (split(',', $ENV{'DH_ELPA_TEST_ERT_LOAD_PATH'})) { push @args, ('-L', "$dir"); } } # make some guesses about where stuff that needs to be in # load-path will be push @args, ("-L", "."); push @args, ("-L", "test") if ( -d "test" ); push @args, ("-L", "tests") if ( -d "tests" ); # TODO maybe we should just add all dirs containing files in @ert_files? # now finish adding the user's stuff push @args, ("--eval", "$ENV{'DH_ELPA_TEST_ERT_EVAL'}") if (defined $ENV{'DH_ELPA_TEST_ERT_EVAL'}); foreach my $ert_file (@ert_files) { push @args, ("-l", "$ert_file"); } if (defined $ENV{'DH_ELPA_TEST_ERT_HELPER'}) { push @args, ("-l", "$ENV{'DH_ELPA_TEST_ERT_HELPER'}"); } else { push @args, ("--eval", "(ert-run-tests-batch-and-exit)"); } print_and_doit(@args); } =head1 EXAMPLES Here is an example of using the helper in a dh(1) style debian/rules =over 4 #!/usr/bin/make -f export DH_ELPA_TEST_BUTTERCUP_LOAD_PATH=lib,other_lib %: dh $@ --with elpa_plus_test =back =cut