[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Bug in getopt-long?
From: |
Thien-Thi Nguyen |
Subject: |
Re: Bug in getopt-long? |
Date: |
Wed, 01 Aug 2001 03:13:11 -0700 |
From: Daniel Skarda <address@hidden>
Date: 28 Jul 2001 18:32:07 +0000
I found that I quite do not understand getopt-long - or to be exact -
`predicate' in getopt-long specification. Imagine this code:
i've incorporated the cases into getopt-long.test, appended (but not yet
checked in). please copy that file to test-suite/tests and from the
guile-core directory, do "./check-guile getopt-long.test". i'd like to
confirm that we see the same thing, namely one failure and one error...
note that you will need to check out a very recent (of 5 minutes ago)
guile in order to access new support in test-suite/lib.scm for errors of
the type getopt-long.scm produces.
thi
__________________________________________
;;;; getopt-long.test --- optional long arg processing -*- scheme -*-
;;;; Thien-Thi Nguyen <address@hidden> --- August 2001
;;;;
;;;; Copyright (C) 2001 Free Software Foundation, Inc.
;;;;
;;;; This program 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 2, or (at your option)
;;;; any later version.
;;;;
;;;; This program 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 software; see the file COPYING. If not, write to
;;;; the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
;;;; Boston, MA 02111-1307 USA
(use-modules (test-suite lib)
(ice-9 getopt-long)
(ice-9 regex))
(define exception:option-predicate-failed
(cons 'misc-error "^option predicate failed"))
(with-test-prefix "specifying predicate"
(define (test1 . args)
(getopt-long args `((test (value #t)
(predicate ,(lambda (x)
(string-match "^[0-9]+$" x)))))))
(pass-if "valid arg"
(equal? (test1 "foo" "bar" "--test=123")
'((() "bar") (test . "123"))))
(pass-if-exception "invalid arg"
exception:option-predicate-failed
(test1 "foo" "bar" "--test=foo"))
(pass-if-exception "option has no arg"
exception:option-predicate-failed
(test1 "foo" "bar"))
)
(with-test-prefix "not specifying predicate"
(define (test2 . args)
(getopt-long args `((test (value #t)))))
(pass-if "option has arg"
(equal? (test2 "foo" "bar" "--test=foo")
'((() "bar") (test . "foo"))))
(pass-if "option has no arg"
(equal? (test2 "foo" "bar")
'((() "bar"))))
)
(with-test-prefix "value optional, w/ single-char"
(define (test3 . args)
(getopt-long args '((foo (value optional) (single-char #\f))
(bar))))
(pass-if "long arg `foo' w/ option, long arg `bar'"
(equal? (test3 "prg" "--foo" "fooval" "--bar")
'((()) (bar . #t) (foo . "fooval"))))
(pass-if "short arg `foo' w/ option, long arg `bar'"
(equal? (test3 "prg" "-f" "fooval" "--bar")
'((()) (bar . #t) (foo . "fooval"))))
(pass-if "short arg `foo', long arg `bar', no options"
(equal? (test3 "prg" "-f" "--bar")
'((()) (bar . #t) (foo . #t))))
(pass-if "long arg `foo', long arg `bar', no options"
(equal? (test3 "prg" "--foo" "--bar")
'((()) (bar . #t) (foo . #t))))
; -=> ((()) (foo . "--bar")) ; HUH??? - BUG ??
(pass-if "long arg `bar', short arg `foo', no options"
(equal? (test3 "prg" "--bar" "-f")
'((()) (foo . #t) (bar . #t))))
(pass-if "long arg `bar', long arg `foo', no options"
(equal? (test3 "prg" "--bar" "--foo")
'((()) (foo . #t) (bar . #t))))
;
; [error] Not enough options ; HUH??? Value is optional!
;
)
;;; getopt-long.test ends here