aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJustus Winter <[email protected]>2016-12-20 13:01:35 +0000
committerJustus Winter <[email protected]>2016-12-20 15:25:35 +0000
commit5f16dec938ac6e337c6ff72981285385d75ec455 (patch)
treed938a1a5dc82bd29ff57ac5de18f1e560d05ede9
parentgpgscm: Change associativity of ::. (diff)
downloadlibgpg-error-5f16dec938ac6e337c6ff72981285385d75ec455.tar.gz
libgpg-error-5f16dec938ac6e337c6ff72981285385d75ec455.zip
tests: Move argument parser.
* tests/gpgme/gpgme-defs.scm (flag): Move... * tests/gpgscm/tests.scm: ... over here. Signed-off-by: Justus Winter <[email protected]>
-rw-r--r--tests.scm25
1 files changed, 25 insertions, 0 deletions
diff --git a/tests.scm b/tests.scm
index 7b8d489..f127a93 100644
--- a/tests.scm
+++ b/tests.scm
@@ -658,3 +658,28 @@
(test' (test::set-directory wd)))
(loop (pool::add (test'::run-sync '--unpack-tarball gpghome-tar))
(cdr tests')))))))
+
+;; Command line flag handling. Returns the elements following KEY in
+;; ARGUMENTS up to the next argument, or #f if KEY is not in
+;; ARGUMENTS.
+(define (flag key arguments)
+ (cond
+ ((null? arguments)
+ #f)
+ ((string=? key (car arguments))
+ (let loop ((acc '())
+ (args (cdr arguments)))
+ (if (or (null? args) (string-prefix? (car args) "--"))
+ (reverse acc)
+ (loop (cons (car args) acc) (cdr args)))))
+ ((string=? "--" (car arguments))
+ #f)
+ (else
+ (flag key (cdr arguments)))))
+(assert (equal? (flag "--xxx" '("--yyy")) #f))
+(assert (equal? (flag "--xxx" '("--xxx")) '()))
+(assert (equal? (flag "--xxx" '("--xxx" "yyy")) '("yyy")))
+(assert (equal? (flag "--xxx" '("--xxx" "yyy" "zzz")) '("yyy" "zzz")))
+(assert (equal? (flag "--xxx" '("--xxx" "yyy" "zzz" "--")) '("yyy" "zzz")))
+(assert (equal? (flag "--xxx" '("--xxx" "yyy" "--" "zzz")) '("yyy")))
+(assert (equal? (flag "--" '("--" "xxx" "yyy" "--" "zzz")) '("xxx" "yyy")))