From 7e0379a75475abfd15e0623913795779ff0f40d7 Mon Sep 17 00:00:00 2001 From: Justus Winter Date: Tue, 20 Sep 2016 15:29:57 +0200 Subject: [PATCH] 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 --- 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 84faf1cdd..8845afd34 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 ) will create and delete temporary files that you can use in . (with-temporary-working-directory ) will diff --git a/tests/openpgp/run-tests.scm b/tests/openpgp/run-tests.scm index be22303cf..18f8b8081 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)