mirror of
git://git.gnupg.org/gnupg.git
synced 2024-12-22 10:19:57 +01:00
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@g10code.com>
This commit is contained in:
parent
c644962fcf
commit
7e0379a754
@ -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
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user