[Pkg-gnupg-commit] [gnupg2] 48/292: tests: Add documentation, make interactive debugging possible.

Daniel Kahn Gillmor dkg at fifthhorseman.net
Mon Nov 21 06:31:24 UTC 2016


This is an automated email from the git hooks/post-receive script.

dkg pushed a commit to branch master
in repository gnupg2.

commit 7e0379a75475abfd15e0623913795779ff0f40d7
Author: Justus Winter <justus at g10code.com>
Date:   Tue Sep 20 15:29:57 2016 +0200

    tests: Add documentation, make interactive debugging possible.
    
    * tests/openpgp/README: Add documentation about debugging and
    interfacing with GnuPG.
    * tests/openpgp/run-tests.scm (test::run-sync): Hand stdin to the
    child so that we can use a repl in the tests.
    
    Signed-off-by: Justus Winter <justus at g10code.com>
---
 tests/openpgp/README        | 44 ++++++++++++++++++++++++++++++++++++++++++++
 tests/openpgp/run-tests.scm |  2 +-
 2 files changed, 45 insertions(+), 1 deletion(-)

diff --git a/tests/openpgp/README b/tests/openpgp/README
index 84faf1c..8845afd 100644
--- a/tests/openpgp/README
+++ b/tests/openpgp/README
@@ -89,6 +89,50 @@ element of list while displaying the progress appropriately.
 for-each-p' is similar, but accepts another callback before the 'list'
 argument to format each item.  for-each-p can be safely nested, and
 the inner progress indicator will be abbreviated using '.'.
+** Debugging tests
+
+Say you are working on a new test called 'your-test.scm', you can run
+it on its own using
+
+  obj $ make -C tests/openpgp check XTESTS=your-test.scm
+
+but something isn't working as expected.  There are several little
+gadgets that might help.  The first one is 'trace', a function that
+prints the value given to it and evaluates to it.  E.g.
+
+  (trace (+ 2 3))
+
+prints '5' and evaluates to 5.  Also, there is an 'assert' macro that
+aborts the execution if its argument does not evaluate to a trueish
+value.  Feel free to express invariants with it.
+
+You can also get an interactive repl by dropping
+
+  (interactive-repl (current-environment))
+
+anywhere you like.
+
+** Interfacing with gpg
+
+defs.scm defines several convenience functions.  Say you want to parse
+the colon output from gpg, there is gpg-with-colons that splits the
+result at newlines and colons, so you can use the result like this:
+
+ (define (fpr some-key)
+   (list-ref (assoc "fpr" (gpg-with-colons
+			   `(--with-fingerprint
+			     --list-secret-keys ,some-key)))
+	     9))
+
+Or if you want to count all non-revoked uids for a given key, do
+
+ (define (count-uids-of-secret-key some-key)
+   (length (filter (lambda (x) (and (string=? "uid" (car x))
+				    (string=? "u" (cadr x))))
+		   (gpg-with-colons
+		    `(--with-fingerprint
+		      --list-secret-keys ,some-key)))))
+
 ** Temporary files
 (lettmp <bindings> <body>) will create and delete temporary files that
 you can use in <body>.  (with-temporary-working-directory <body>) will
diff --git a/tests/openpgp/run-tests.scm b/tests/openpgp/run-tests.scm
index be22303..18f8b80 100644
--- a/tests/openpgp/run-tests.scm
+++ b/tests/openpgp/run-tests.scm
@@ -85,7 +85,7 @@
       (define (run-sync . args)
 	(with-working-directory directory
 	  (let* ((p (inbound-pipe))
-		 (pid (spawn-process-fd (append command args) CLOSED_FD
+		 (pid (spawn-process-fd (append command args) 0
 					(:write-end p) (:write-end p))))
 	    (close (:write-end p))
 	    (splice (:read-end p) STDERR_FILENO)

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-gnupg/gnupg2.git



More information about the Pkg-gnupg-commit mailing list