gpgscm,tests: Add new functions to the test environment.

* tests/gpgscm/lib.scm (first, last, powerset): New functions.
* tests/gpgscm/tests.scm (interactive-shell): New function.
* tests/openpgp/Makefile.am (EXTRA_DIST): Add new file.
* tests/openpgp/README: Document 'interactive-shell'.
* tests/openpgp/shell.scm: New file.

Signed-off-by: Justus Winter <justus@g10code.com>
This commit is contained in:
Justus Winter 2016-11-03 14:37:15 +01:00
parent d10b67b9bc
commit 1ec07cbc20
5 changed files with 63 additions and 2 deletions

View File

@ -42,6 +42,24 @@
((not (p (car l))) #f)
(else (all p (cdr l)))))
;; Return the first element of a list.
(define first car)
;; Return the last element of a list.
(define (last lst)
(if (null? (cdr lst))
(car lst)
(last (cdr lst))))
;; Compute the powerset of a list.
(define (powerset set)
(if (null? set)
'(())
(let ((rst (powerset (cdr set))))
(append (map (lambda (x) (cons (car set) x))
rst)
rst))))
;; Is PREFIX a prefix of S?
(define (string-prefix? s prefix)
(and (>= (string-length s) (string-length prefix))

View File

@ -481,3 +481,11 @@
(catch (list tmpfiles source *error*)
(apply function `(,(call-with-input-file source read-all) ,@args)))
(list tmpfiles source #f)))
;;
;; Developing and debugging tests.
;;
;; Spawn an os shell.
(define (interactive-shell)
(call-with-fds `(,(getenv "SHELL")) 0 1 2))

View File

@ -188,7 +188,7 @@ sample_msgs = samplemsgs/issue2419.asc
EXTRA_DIST = defs.scm $(XTESTS) $(TEST_FILES) \
mkdemodirs signdemokey $(priv_keys) $(sample_keys) \
$(sample_msgs) ChangeLog-2011 run-tests.scm \
setup.scm finish.scm
setup.scm finish.scm shell.scm
CLEANFILES = prepared.stamp x y yy z out err $(data_files) \
plain-1 plain-2 plain-3 trustdb.gpg *.lock .\#lk* \

View File

@ -110,7 +110,10 @@ You can also get an interactive repl by dropping
(interactive-repl (current-environment))
anywhere you like.
anywhere you like. Or, if you want to examine the environment from an
operating system shell, use
(interactive-shell)
** Interfacing with gpg

32
tests/openpgp/shell.scm Normal file
View File

@ -0,0 +1,32 @@
#!/usr/bin/env gpgscm
;; Copyright (C) 2016 g10 Code GmbH
;;
;; This file is part of GnuPG.
;;
;; GnuPG is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 3 of the License, or
;; (at your option) any later version.
;;
;; GnuPG is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with this program; if not, see <http://www.gnu.org/licenses/>.
(load (with-path "defs.scm"))
;; This is not a test, but can be used to inspect the test
;; environment. Simply execute
;;
;; make -Ctests/openpgp check XTESTS=shell.scm
;;
;; to run it.
(echo "Note that gpg.conf includes 'batch'. If you want to use gpg")
(echo "interactively you should drop that.")
(echo)
(interactive-shell)