diff options
author | Justus Winter <[email protected]> | 2016-09-20 13:29:57 +0000 |
---|---|---|
committer | Justus Winter <[email protected]> | 2016-09-20 13:55:02 +0000 |
commit | 7e0379a75475abfd15e0623913795779ff0f40d7 (patch) | |
tree | da3e70e4f4c9b025f1d2c13b9be3b76fc6de29db | |
parent | tests: Drop the old shell-based tests. (diff) | |
download | gnupg-7e0379a75475abfd15e0623913795779ff0f40d7.tar.gz gnupg-7e0379a75475abfd15e0623913795779ff0f40d7.zip |
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 <[email protected]>
-rw-r--r-- | tests/openpgp/README | 44 | ||||
-rw-r--r-- | tests/openpgp/run-tests.scm | 2 |
2 files changed, 45 insertions, 1 deletions
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 <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 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) |