summaryrefslogtreecommitdiff
path: root/dh_elpa_test
diff options
context:
space:
mode:
authorSean Whitton <spwhitton@spwhitton.name>2016-04-10 08:15:54 -0700
committerSean Whitton <spwhitton@spwhitton.name>2016-04-10 08:15:54 -0700
commit4ee6e92c977d60ed66ed5e9e7d3e19d93f947c8a (patch)
treef775a0af06b6db5b43ddcd9b38b270971e96bfa9 /dh_elpa_test
parenta3eb8c6aa39be5cd2f27bd6f21156fad8c2b6e5e (diff)
merge (unreleased) src:dh-elpa-test into dh-elpa
Diffstat (limited to 'dh_elpa_test')
-rwxr-xr-xdh_elpa_test174
1 files changed, 174 insertions, 0 deletions
diff --git a/dh_elpa_test b/dh_elpa_test
new file mode 100755
index 0000000..b06c485
--- /dev/null
+++ b/dh_elpa_test
@@ -0,0 +1,174 @@
+#!/usr/bin/perl
+
+=head1 NAME
+
+dh_elpa_test - run ELPA package testsuites
+
+=cut
+
+use strict;
+use warnings;
+
+=head1 SYNOPSIS
+
+B<dh_elpa_test> [S<I<debhelper options>>] [S<I<pkg-file>>]
+
+=head1 DESCRIPTION
+
+B<dh_elpa_test> 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 or are supplied by an environment
+variable (see below).
+
+=head1 ENVIRONMENT VARIABLES
+
+B<dh_elpa_test> 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<DH_ELPA_TEST_BUTTERCUP_LOAD_PATH>
+
+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<DH_ELPA_TEST_BUTTERCUP_PATTERNS>
+
+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<DH_ELPA_TEST_ERT_EXCLUDE>
+
+A comma-separated list of file globs matching files containing ERT
+tests that should not be run.
+
+=item B<DH_ELPA_TEST_ERT_HELPER>
+
+The name of a *.el file containing Emacs Lisp code that will run the
+ERT test suite. When this variable is not defined, B<dh_elpa_test>
+calls the function B<(ert-run-tests-batch-and-exit)>.
+
+=item B<DH_ELPA_TEST_ERT_EVAL>
+
+Emacs Lisp code to be run prior to running ERT tests by the Emacs
+instance spawned by B<dh_elpa_test> to run those tests.
+
+=item B<DH_ELPA_TEST_ERT_LOAD_PATH>
+
+A comma-separated list of directories to add to the load-path when
+B<dh_elpa_test> 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" .`);
+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 packages 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" ));
+
+ 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_LOAD_PATH'}) {
+ foreach my $dir (split(',', $ENV{'DH_ELPA_TEST_ERT_LOAD_PATH'})) {
+ push @args, ('-L', "$dir");
+ }
+ }
+ 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