summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--debian/changelog1
-rwxr-xr-xdh_elpa_test130
2 files changed, 119 insertions, 12 deletions
diff --git a/debian/changelog b/debian/changelog
index fba407d..1e5d576 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -12,6 +12,7 @@ dh-elpa (1.0) UNRELEASED; urgency=medium
Previously, only the basename was matched, so it was not possible to
use a glob like "broken-tests/*.el".
- New dependency on libtext-glob-perl.
+ * Add --autopkgtest switch to dh_elpa_test for autodep8.
* Add example usage of ert_exclude to dh_elpa_test(1).
[ David Bremner ]
diff --git a/dh_elpa_test b/dh_elpa_test
index 170932e..09fe39d 100755
--- a/dh_elpa_test
+++ b/dh_elpa_test
@@ -8,16 +8,17 @@ dh_elpa_test - run ELPA package testsuites
use strict;
use warnings;
+no warnings "experimental::smartmatch";
=head1 SYNOPSIS
-B<dh_elpa_test> [S<I<debhelper options>>] [S<I<pkg-file>>]
+B<dh_elpa_test> [S<I<debhelper options>>] [S<I<--autopkgtest>>] [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.
+buttercup(1). dh_auto_test(1) is rarely suitable.
Testing with buttercup(1) will be activated if the package
build-depends on elpa-buttercup. Testing with ERT will be activated
@@ -50,7 +51,7 @@ can figure out how to run the test suite itself.
=item B<disable>
-If this variable is set to any value, dh_elpa(1) will not invoke
+If this key is set to any value, dh_elpa(1) will not invoke
B<dh_elpa_test>.
=item B<buttercup_load_path>
@@ -63,7 +64,7 @@ B<-L> command line argument.
A comma-separated list of Emacs regular expressions 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
+run. If this key 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.
@@ -72,10 +73,13 @@ line argument.
A comma-separated list of file globs matching files containing ERT
tests that should not be run.
+The '*' character in globs in this configuration key does NOT match
+'/' directory separators.
+
=item B<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>
+ERT test suite. When this key is not defined, B<dh_elpa_test>
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
@@ -97,15 +101,40 @@ instance spawned by B<dh_elpa_test> to run those tests.
A comma-separated list of directories to add to the load-path when
B<dh_elpa_test> invokes Emacs to run ERT tests.
+=item B<autopkgtest_keep>
+
+A comma-separated list of file globs matching files that should not be
+moved out of the source tree before running DEP8 tests (see the
+B<--autopkgtest> option below).
+
+The '*' character in globs in this configuration key matches '/'
+directory separators.
+
+=back
+
+=head1 OPTIONS
+
+=over 4
+
+=item B<--autopkgtest>
+
+Operate in autopkgtest mode. B<dh_elpa_test> will rename non-test *.el
+files so that Emacs will not load them. This ensures that the test
+test the installed binary package rather than the unpacked source
+package.
+
+To exclude files from this removal, specify them in the
+B<autopkgtest_keep> configuration option (see above).
+
=back
=head1 ENVIRONMENT VARIABLES
Older versions of B<dh_elpa_test> were configured using environment
-variables corresponding to the above configuration keys. For example,
-the B<ert_eval> configuration key replaced environment variable
-B<DH_ELPA_TEST_ERT_EVAL>. Their use is now deprecated. If the
-debian/elpa-test file exists, they will be ignored.
+variables corresponding to some of the above configuration keys. For
+example, the B<ert_eval> configuration key replaced environment
+variable B<DH_ELPA_TEST_ERT_EVAL>. Their use is now deprecated. If
+the debian/elpa-test file exists, they will be ignored.
=cut
@@ -139,6 +168,9 @@ sub long_name {
# ---- Script setup
+# check command line opts for autopkgtest mode
+my $autopkgtest = ( "--autopkgtest" ~~ @ARGV );
+
# This checks whether the debhelper compat is 10 or above. With
# debhelper compat below 9, dh_elpa_test will get run more in more
# than one sequence, including inside fakeroot, which can cause tests
@@ -147,9 +179,6 @@ if ( get_buildoption("nocheck") || compat(9) ) {
exit 0;
}
-my $control = Debian::Control->new();
-$control->read("debian/control");
-
# note that we don't need package.elpa-test since we are testing all
# lisp we can find in the *source* package
my $options = Config::Tiny->new;
@@ -174,11 +203,72 @@ if ( -f "debian/elpa-test") {
}
}
+my @non_test_files;
+if ($autopkgtest) {
+ # Since we were not invoked by the dh sequencer, we need to check
+ # here whether tests have been disabled. Note that we can't
+ # replace the test in elpa.pm with this one because we can't
+ # (cleanly) disable dh_auto_test from within dh_elpa_test
+ if ( defined $options->{_}->{ "disable" } ) {
+ exit 0;
+ }
+
+ my $rule = File::Find::Rule->new;
+ $rule
+ ->or(File::Find::Rule
+ ->name('.pc', 'debian')
+ ->directory->prune->discard,
+ File::Find::Rule->new);
+ $rule
+ ->file()
+ ->name( '*.el' )
+ ->none(File::Find::Rule->grep( "ert-deftest" ), # ERT
+ File::Find::Rule->grep( "\\(describe \"" ) # Buttercup
+ );
+
+ if ( defined $options->{_}->{'autopkgtest_keep'} ) {
+ foreach my $glob (split(',', $options->{_}->{'autopkgtest_keep'} )) {
+ # We want the user to be able to say
+ # autopkgtest_keep = test/resources/*
+ # and have that affect all subdirs of resources
+ $Text::Glob::strict_wildcard_slash = 0;
+ # TODO should we do this for ert_exclude too?
+ $rule->not_exec( long_name($glob) );
+ }
+ }
+
+ @non_test_files = $rule->in('.');
+
+ foreach my $old ( @non_test_files ) {
+ my $new = $old =~ s|\.el$|.disabled|r;
+ rename $old, $new or die "Failed to rename: $!\n";
+ }
+}
+
# 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";
+my $control = Debian::Control->new();
+$control->read("debian/control");
+
+if ($autopkgtest) {
+ # save stderr handle for restoration
+ {
+ no warnings 'once';
+ open(OLDERR, ">&", \*STDERR);
+ }
+ # redirect stderr to stdout while we run our tests
+ # emacs --batch and ERT itself both produce a lot of output on
+ # stderr even when there has been no error, and adt-run interprets
+ # this as a test failure
+ open(STDERR, ">&STDOUT");
+ # unbuffer them to ensure lines appear in the right order
+ select STDERR; $| = 1;
+ select STDOUT; $| = 1;
+}
+
# ---- Buttercup
if ($control->source->Build_Depends->has( "elpa-buttercup" )) {
@@ -256,3 +346,19 @@ if (@ert_files) {
print_and_doit(@args);
}
+
+# ---- Cleanup
+
+END {
+ if ($autopkgtest) {
+ # restore stderr now we've finished running tests
+ open(STDERR, ">&OLDERR");
+
+ # Restore files that we renamed so that we comply with DEP8
+ # rw-build-tree
+ foreach my $new ( @non_test_files ) {
+ my $old = $new =~ s|\.el$|.disabled|r;
+ rename $old, $new or die "Failed to rename: $!\n";
+ }
+ }
+}