From dbueno at common-lisp.net Sat Mar 19 22:17:33 2005 From: dbueno at common-lisp.net (Denis Bueno) Date: Sat, 19 Mar 2005 23:17:33 +0100 (CET) Subject: [cl-cli-parser-cvs] CVS update: cl-cli-parser/unit-test.lisp Message-ID: <20050319221733.5BB0E88704@common-lisp.net> Update of /project/cl-cli-parser/cvsroot/cl-cli-parser In directory common-lisp.net:/tmp/cvs-serv7072 Modified Files: unit-test.lisp Log Message: (defpackage): Export `check'. Date: Sat Mar 19 23:17:32 2005 Author: dbueno Index: cl-cli-parser/unit-test.lisp diff -u cl-cli-parser/unit-test.lisp:1.1 cl-cli-parser/unit-test.lisp:1.2 --- cl-cli-parser/unit-test.lisp:1.1 Sat Mar 19 22:41:45 2005 +++ cl-cli-parser/unit-test.lisp Sat Mar 19 23:17:32 2005 @@ -2,7 +2,7 @@ (defpackage :lunit (:use :cl) - (:export #:deftest)) + (:export #:deftest #:check)) (in-package :lunit) ;;; from peter seibel's book, practical common lisp From dbueno at common-lisp.net Sat Mar 19 22:18:44 2005 From: dbueno at common-lisp.net (Denis Bueno) Date: Sat, 19 Mar 2005 23:18:44 +0100 (CET) Subject: [cl-cli-parser-cvs] CVS update: cl-cli-parser/cli-parser-test.lisp Message-ID: <20050319221844.7F49D88704@common-lisp.net> Update of /project/cl-cli-parser/cvsroot/cl-cli-parser In directory common-lisp.net:/tmp/cvs-serv7094 Modified Files: cli-parser-test.lisp Log Message: refactored to use unit-test.lisp, instead of the stupid thing I wrote when I was learning lisp. Date: Sat Mar 19 23:18:43 2005 Author: dbueno Index: cl-cli-parser/cli-parser-test.lisp diff -u cl-cli-parser/cli-parser-test.lisp:1.1 cl-cli-parser/cli-parser-test.lisp:1.2 --- cl-cli-parser/cli-parser-test.lisp:1.1 Sat Mar 19 22:41:45 2005 +++ cl-cli-parser/cli-parser-test.lisp Sat Mar 19 23:18:43 2005 @@ -1,4 +1,4 @@ -;;; $Id: cli-parser-test.lisp,v 1.1 2005/03/19 21:41:45 dbueno Exp $ +;;; $Id: cli-parser-test.lisp,v 1.2 2005/03/19 22:18:43 dbueno Exp $ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; AGNS - Automatic (G-something) N-gram Spelling Corrector ;;; Denis Bueno @@ -8,7 +8,6 @@ (in-package :cli-parser) (use-package :lunit) -(set-current-unit :cli) (deftest test-opt-p () @@ -33,40 +32,41 @@ (opt2 "--jthingie=123") (opt3 "--thing=1 2 3") (opt4 "--k")) - (check (full-opt-p opt1)) - (check (full-opt-p opt2)) - (check (full-opt-p opt3)) - (check (full-opt-p "--thing 1 2 3")) - (check (full-opt-p "--thing 1,2,3")) + (check (full-opt-p opt1)) + (check (full-opt-p opt2)) + (check (full-opt-p opt3)) + (check (full-opt-p "--thing 1 2 3")) + (check (full-opt-p "--thing 1,2,3")) (check (full-opt-p opt4)) (check (full-opt-p "-cookycrisp")) (check (full-opt-p "-k=3")) (check (full-opt-p "-k 3")))) (deftest test-end-opt-name () - (check 7 (end-opt-name "--crazy")) - (check 2 (end-opt-name "-c")) - (check 7 (end-opt-name "--happy=25")) - (check 7 (end-opt-name "--happy 25"))) + (check (= 7 (end-opt-name "--crazy")) + (= 2 (end-opt-name "-c")) + (= 7 (end-opt-name "--happy=25")) + (= 7 (end-opt-name "--happy 25")))) (deftest test-opt-name () - (check "crazy" (opt-name "--crazy")) - (check "o" (opt-name "-o")) - (check "crazy" (opt-name "--crazy=1299")) - (check "o" (opt-name "-o=678")) - (check "crazy" (opt-name "--crazy 1299")) - (check "o" (opt-name "-o 678"))) + (check (string="crazy" (opt-name "--crazy")) + (string= "o" (opt-name "-o")) + (string= "crazy" (opt-name "--crazy=1299")) + (string= "o" (opt-name "-o=678")) + (string= "crazy" (opt-name "--crazy 1299")) + (string= "o" (opt-name "-o 678")))) (deftest test-opt-values () - (check (opt-values "--some-option")) - (check '("x" "y" "z") (opt-values "--some-option=x y z ")) - (check '("x" "y" "z") (opt-values "--opt=x,y,z")) - (check '("x" "y" "z") (opt-values "--opt x,y,z")) - (check '("x" "y" "z") (opt-values "--opt x y z")) - (check '("1" "2") (opt-values "-x=1 2")) - (check '("1") (opt-values "-x=1")) - (check '("1") (opt-values "-x 1")) - (check '("1") (opt-values "--stupid 1"))) + (check + (null (opt-values "--some-option")) + (equalp '("x" "y" "z") (opt-values "--some-option=x y z ")) + (equalp '("x" "y" "z") (opt-values "--opt=x,y,z")) + (equalp '("x" "y" "z") (opt-values "--opt x,y,z")) + (equalp '("x" "y" "z") (opt-values "--opt x y z")) + (equalp '("1" "2") (opt-values "-x=1 2")) + (equalp '("1") (opt-values "-x=1")) + (equalp '("1") (opt-values "-x 1")) + (equalp '("1") (opt-values "--stupid 1")))) (defparameter *test-cli-opts* (list @@ -79,26 +79,28 @@ :example "-a, --artaxerxes"))) (deftest test-abbr->full-opt-name () - (check= "artaxerxes" - (abbr->full-opt-name "a" *test-cli-opts*)) - (check= "ornithology" - (abbr->full-opt-name "o" *test-cli-opts*)) - (check= "ornithology" - (abbr->full-opt-name "ornithology" *test-cli-opts*)) - (check (abbr->full-opt-name "k" *test-cli-opts*))) + (check + (string= "artaxerxes" + (abbr->full-opt-name "a" *test-cli-opts*)) + (string= "ornithology" + (abbr->full-opt-name "o" *test-cli-opts*)) + (string= "ornithology" + (abbr->full-opt-name "ornithology" *test-cli-opts*)) + (string= "k" (abbr->full-opt-name "k" *test-cli-opts*)))) (deftest test-coalesce-options () - (check '("--files=1 2 3") - (coalesce-options '("--files=1" "2" "3"))) - (check '("--files 1 2 3") - (coalesce-options '("--files" "1" "2" "3"))) - (check '("--files 1, 2, 3") - (coalesce-options '("--files" "1," "2," "3"))) - (check '("--genre=fatty.xml" - "--files=file1 file2 file3" - "--some-other-things=1 2 3") - (coalesce-options '("--genre=fatty.xml" "--files=file1" "file2" - "file3" "--some-other-things=1" "2" "3")))) + (check + (equalp'("--files=1 2 3") + (coalesce-options '("--files=1" "2" "3"))) + (equalp '("--files 1 2 3") + (coalesce-options '("--files" "1" "2" "3"))) + (equalp '("--files 1, 2, 3") + (coalesce-options '("--files" "1," "2," "3"))) + (equalp '("--genre=fatty.xml" + "--files=file1 file2 file3" + "--some-other-things=1 2 3") + (coalesce-options '("--genre=fatty.xml" "--files=file1" "file2" + "file3" "--some-other-things=1" "2" "3"))))) (deftest test-cli-parse-hash () (let ((test1 (list "--ornithology=x-value" "-a y-value")) From dbueno at common-lisp.net Sat Mar 19 22:24:03 2005 From: dbueno at common-lisp.net (Denis Bueno) Date: Sat, 19 Mar 2005 23:24:03 +0100 (CET) Subject: [cl-cli-parser-cvs] CVS update: cl-cli-parser/cli-parser-test.lisp Message-ID: <20050319222403.8B25688665@common-lisp.net> Update of /project/cl-cli-parser/cvsroot/cl-cli-parser In directory common-lisp.net:/tmp/cvs-serv7146 Modified Files: cli-parser-test.lisp Log Message: reindentation. Date: Sat Mar 19 23:24:02 2005 Author: dbueno Index: cl-cli-parser/cli-parser-test.lisp diff -u cl-cli-parser/cli-parser-test.lisp:1.2 cl-cli-parser/cli-parser-test.lisp:1.3 --- cl-cli-parser/cli-parser-test.lisp:1.2 Sat Mar 19 23:18:43 2005 +++ cl-cli-parser/cli-parser-test.lisp Sat Mar 19 23:24:02 2005 @@ -1,4 +1,4 @@ -;;; $Id: cli-parser-test.lisp,v 1.2 2005/03/19 22:18:43 dbueno Exp $ +;;; $Id: cli-parser-test.lisp,v 1.3 2005/03/19 22:24:02 dbueno Exp $ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; AGNS - Automatic (G-something) N-gram Spelling Corrector ;;; Denis Bueno @@ -43,18 +43,20 @@ (check (full-opt-p "-k 3")))) (deftest test-end-opt-name () - (check (= 7 (end-opt-name "--crazy")) - (= 2 (end-opt-name "-c")) - (= 7 (end-opt-name "--happy=25")) - (= 7 (end-opt-name "--happy 25")))) + (check + (= 7 (end-opt-name "--crazy")) + (= 2 (end-opt-name "-c")) + (= 7 (end-opt-name "--happy=25")) + (= 7 (end-opt-name "--happy 25")))) (deftest test-opt-name () - (check (string="crazy" (opt-name "--crazy")) - (string= "o" (opt-name "-o")) - (string= "crazy" (opt-name "--crazy=1299")) - (string= "o" (opt-name "-o=678")) - (string= "crazy" (opt-name "--crazy 1299")) - (string= "o" (opt-name "-o 678")))) + (check + (string="crazy" (opt-name "--crazy")) + (string= "o" (opt-name "-o")) + (string= "crazy" (opt-name "--crazy=1299")) + (string= "o" (opt-name "-o=678")) + (string= "crazy" (opt-name "--crazy 1299")) + (string= "o" (opt-name "-o 678")))) (deftest test-opt-values () (check @@ -108,6 +110,6 @@ (setf (gethash "ornithology" resl1) (list"x-value") (gethash "artaxerxes" resl1) (list "y-value")) - (check resl1 (cli-parse-hash test1 *test-cli-opts*)))) + (check (equalp resl1 (cli-parse-hash test1 *test-cli-opts*))))) ;;;; EOF From dbueno at common-lisp.net Sat Mar 19 22:41:07 2005 From: dbueno at common-lisp.net (Denis Bueno) Date: Sat, 19 Mar 2005 23:41:07 +0100 (CET) Subject: [cl-cli-parser-cvs] CVS update: Module imported: public_html Message-ID: <20050319224107.4EBF688665@common-lisp.net> Update of /project/cl-cli-parser/cvsroot/public_html In directory common-lisp.net:/tmp/cvs-serv8003 Log Message: Initial import. Status: Vendor Tag: dbueno Release Tags: start N public_html/index.html N public_html/style.css No conflicts created by this import Date: Sat Mar 19 23:41:06 2005 Author: dbueno New module public_html added From dbueno at common-lisp.net Sat Mar 19 23:08:27 2005 From: dbueno at common-lisp.net (Denis Bueno) Date: Sun, 20 Mar 2005 00:08:27 +0100 (CET) Subject: [cl-cli-parser-cvs] CVS update: cl-cli-parser/cli-parser-test.lisp Message-ID: <20050319230827.30CFB88665@common-lisp.net> Update of /project/cl-cli-parser/cvsroot/cl-cli-parser In directory common-lisp.net:/tmp/cvs-serv10105 Modified Files: cli-parser-test.lisp Log Message: Fix up a test which was failing because it wasn't coded up correctly in the first place. Date: Sun Mar 20 00:08:25 2005 Author: dbueno Index: cl-cli-parser/cli-parser-test.lisp diff -u cl-cli-parser/cli-parser-test.lisp:1.3 cl-cli-parser/cli-parser-test.lisp:1.4 --- cl-cli-parser/cli-parser-test.lisp:1.3 Sat Mar 19 23:24:02 2005 +++ cl-cli-parser/cli-parser-test.lisp Sun Mar 20 00:08:23 2005 @@ -1,4 +1,4 @@ -;;; $Id: cli-parser-test.lisp,v 1.3 2005/03/19 22:24:02 dbueno Exp $ +;;; $Id: cli-parser-test.lisp,v 1.4 2005/03/19 23:08:23 dbueno Exp $ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; AGNS - Automatic (G-something) N-gram Spelling Corrector ;;; Denis Bueno @@ -7,7 +7,7 @@ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (in-package :cli-parser) -(use-package :lunit) +#.(use-package :lunit) (deftest test-opt-p () @@ -37,10 +37,10 @@ (check (full-opt-p opt3)) (check (full-opt-p "--thing 1 2 3")) (check (full-opt-p "--thing 1,2,3")) - (check (full-opt-p opt4)) - (check (full-opt-p "-cookycrisp")) - (check (full-opt-p "-k=3")) - (check (full-opt-p "-k 3")))) + (check (not (full-opt-p opt4))) + (check (not (full-opt-p "-cookycrisp"))) + (check (not (full-opt-p "-k=3"))) + (check (not (full-opt-p "-k 3"))))) (deftest test-end-opt-name () (check From dbueno at common-lisp.net Sat Mar 19 23:08:39 2005 From: dbueno at common-lisp.net (Denis Bueno) Date: Sun, 20 Mar 2005 00:08:39 +0100 (CET) Subject: [cl-cli-parser-cvs] CVS update: cl-cli-parser/unit-test.lisp cl-cli-parser/cli-parser.lisp cl-cli-parser/ChangeLog Message-ID: <20050319230839.C590688665@common-lisp.net> Update of /project/cl-cli-parser/cvsroot/cl-cli-parser In directory common-lisp.net:/tmp/cvs-serv10121 Modified Files: unit-test.lisp cli-parser.lisp ChangeLog Log Message: see changelog. Date: Sun Mar 20 00:08:37 2005 Author: dbueno Index: cl-cli-parser/unit-test.lisp diff -u cl-cli-parser/unit-test.lisp:1.2 cl-cli-parser/unit-test.lisp:1.3 --- cl-cli-parser/unit-test.lisp:1.2 Sat Mar 19 23:17:32 2005 +++ cl-cli-parser/unit-test.lisp Sun Mar 20 00:08:37 2005 @@ -34,5 +34,5 @@ (defun report-result (result form) "Report the results of a single test case. Called by `check'." - (format t "~:[FAIL~;pass~] ... ~a: ~a~%" result *test-name* form) + (format t "~:[FAIL~;pass~] ... ~a: ~w~%" result *test-name* form) result) Index: cl-cli-parser/cli-parser.lisp diff -u cl-cli-parser/cli-parser.lisp:1.2 cl-cli-parser/cli-parser.lisp:1.3 --- cl-cli-parser/cli-parser.lisp:1.2 Sat Mar 19 21:07:00 2005 +++ cl-cli-parser/cli-parser.lisp Sun Mar 20 00:08:37 2005 @@ -1,4 +1,4 @@ -;;;; $Id: cli-parser.lisp,v 1.2 2005/03/19 20:07:00 dbueno Exp $ +;;;; $Id: cli-parser.lisp,v 1.3 2005/03/19 23:08:37 dbueno Exp $ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;; Denis Bueno ;;;; @@ -62,17 +62,17 @@ #:make-cli-option) (:documentation "Used for command-line-interface parsing, in the same tradition -as getopt, but, a bit more convenient. The three exported main -functions are: +as getopt, but, a bit more convenient. The three main functions +are: -CLI-PARSE -CLI-PARSE-HASH -CLI-PARSE-ASSOC +* CLI-PARSE +* CLI-PARSE-HASH +* CLI-PARSE-ASSOC -cli-parse actually just calls cli-parse-hash, which will parse a +CLI-PARSE actually just calls CLI-PARSE-HASH, which will parse a list of command-line arguments against a list of cli-option -objects. cli-parse-assoc, instead of returning a hash table of -results like cli-parse-hash does, returns an assoc list of +objects. CLI-PARSE-ASSOC, instead of returning a hash table of +results like CLI-PARSE-HASH does, returns an assoc list of results. The idea is that you create a bunch of cli-option instances (via @@ -87,34 +87,21 @@ (in-package :cli-parser) -(defstruct cli-option - (abbr nil :type (or string null)) - (full "" :type string) - (requires-arguments nil :type boolean) - (description "" :type string) - (example "" :type string)) - -(setf (documentation 'cli-option-abbr 'function) - "Abbreviation for this command-line option." - (documentation 'cli-option-full 'function) - "The full name of this command-line option." - (documentation 'cli-option-requires-arguments 'function) - "Whether this command-line option requires arguments." - (documentation 'cli-option-description 'function) - "A sentence of description of this command-line option." - (documentation 'cli-option-example 'function) - "An example of the usage of this command-line option." - (documentation 'cli-option-p 'function) - "Test whether the argument is a cli-option.") - -;; (defclass cli-option () -;; ((abbreviation :initarg :abbr :accessor cli-option-abbr) -;; (longname :initarg :long :accessor cli-option-long) -;; (argumentsp :initform nil -;; :initarg :argumentsp :accessor cli-option-argumentsp) -;; (description :initform "Default description." -;; :initarg :description :accesssor cli-option-description) -;; (example :initarg :example :accessor cli-option-example))) +;;; TODO: decide what to do if see an option like -cookycrisp: continuable +;;; error/condition restart, ignore? + +(defclass cli-option () + ((abbreviation :initarg :abbr :accessor cli-option-abbr) + (longname :initarg :full :accessor cli-option-full) + (argumentsp :initform nil + :initarg :requires-arguments + :accessor cli-option-requires-arguments) + (description :initform "Default description." + :initarg :description :accessor cli-option-description) + (example :initarg :example :accessor cli-option-example))) + +(defun make-cli-option (&rest initargs) + (apply #'make-instance 'cli-option initargs)) (defvar *single-dash* #\- "Short option prefix.") @@ -144,7 +131,8 @@ and you give \"--opt1=value1\" and \"-n\" to cli-parse-assoc, it returns and assoc-list of the form ((\"opt1\" (\"value1\" \"value2\")) (\"n\" nil))." - (to-full-opt-names (cli-parse-assoc-aux (coalesce-options args) nil) cli-opts)) + (to-full-opt-names (cli-parse-assoc-aux (coalesce-options args) nil) + cli-opts)) (defun cli-parse-assoc-aux (args results) "Helper for cli-parse." (cond ((endp args) (reverse results)) Index: cl-cli-parser/ChangeLog diff -u cl-cli-parser/ChangeLog:1.1 cl-cli-parser/ChangeLog:1.2 --- cl-cli-parser/ChangeLog:1.1 Sat Mar 19 21:07:15 2005 +++ cl-cli-parser/ChangeLog Sun Mar 20 00:08:37 2005 @@ -1,5 +1,11 @@ 2005-03-19 Denis Bueno + * cli-parser.lisp (Global): Using CLOS classes instead of structs + now. + + * unit-test.lisp: Unit testing framework (Seibel's). + (report-result): Write forms literally, not aesthetically. + * cli-parser-test.lisp: Unit test added. * cli-parser.lisp: Stubbed out the class to replace the CLI-OPTION