Subject: Re: bug#23561: epg tests are (almost) always skipped

From: Daiki Ueno <[email-masked]>
Date: Tue, 17 May 2016 17:48:42 +0900

Glenn Morris <[email-masked]> writes:

> Since f93d669a, epg-gpg-program defaults to gpg2 if present (which it is
> on most systems, I guess). epg-tests-gpg-usable, however, requires gpg
> version 1 (in the 'require-passphrase case, which is what every test in
> epg-tests uses). As a result, every test in epg-tests is skipped on a
> system with "gpg2" present (even if "gpg" is also present).

I am actually not sure how to cleanly solve this issue, but as long as
"gpg2" is GnuPG 2.0, the attached patch should work around the issue (if
"gpg2" is upgraded to 2.1, another issue will arise, though).

Regards,
-- 
Daiki Ueno
>From d43d3e66b5582c1e5b8e61eaf7f3ac8866c997a4 Mon Sep 17 00:00:00 2001
From: Daiki Ueno <[email-masked]>
Date: Tue, 17 May 2016 17:46:31 +0900
Subject: [PATCH] Adjust to epg-configuration deprecation.

* test/lisp/epg-tests.el (epg-tests-gpg-usable): Use
`epg-find-configuration' instead of deprecated
`epg-configuration'.
---
 test/lisp/epg-tests.el | 22 +++++++++++++---------
 1 file changed, 13 insertions(+), 9 deletions(-)

diff --git a/test/lisp/epg-tests.el b/test/lisp/epg-tests.el
index 4a31797..06e6f25 100644
--- a/test/lisp/epg-tests.el
+++ b/test/lisp/epg-tests.el
@@ -30,16 +30,20 @@ epg-tests-data-directory
   (expand-file-name "data/epg" (getenv "EMACS_TEST_DIRECTORY"))
   "Directory containing epg test data.")
 
+;; If a passphrase is required, we can only use GnuPG 1.x, as GnuPG
+;; 2.0 or later involves gpg-agent, which prevents injecting
+;; passphrase reliably.
 (defun epg-tests-gpg-usable (&optional require-passphrase)
-  (and (executable-find epg-gpg-program)
-       (condition-case nil
-	   (progn
-	     (epg-check-configuration (epg-configuration))
-	     (if require-passphrase
-		 (string-match "\\`1\\."
-			       (cdr (assq 'version (epg-configuration))))
-	       t))
-	 (error nil))))
+  (let ((config (epg-find-configuration 'OpenPGP)))
+    (and config
+         (condition-case nil
+             (progn
+               (epg-check-configuration config)
+               (if require-passphrase
+                   (string-match "\\`1\\."
+                                 (cdr (assq 'version config)))
+                 t))
+           (error nil)))))
 
 (defun epg-tests-passphrase-callback (_c _k _d)
   ;; Need to create a copy here, since the string will be wiped out
-- 
2.5.5