Skip to content

Commit

Permalink
Fix READ-ARGUMENT-FROM-STRING to read T and NIL only.
Browse files Browse the repository at this point in the history
  • Loading branch information
takagi committed Oct 4, 2016
1 parent 0735488 commit 53e1261
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 38 deletions.
15 changes: 6 additions & 9 deletions src/lake.lisp
Expand Up @@ -492,15 +492,12 @@
(funcall fn x)))

(defun read-argument-from-string (string)
(let* ((eof (gensym))
(value (handler-case (read-from-string string)
(end-of-file () eof))))
(cond
((eq t value) t)
((null value) nil)
((eq eof value) string)
((symbolp value) string)
(t value))))
(check-type string string)
(cond
((string= "T" (string-upcase string)) t)
((string= "NIL" (string-upcase string)) nil)
((string= "()" string) nil)
(t string)))

(defun get-task-arguments (task plist)
(check-type task task)
Expand Down
49 changes: 20 additions & 29 deletions t/lake.lisp
Expand Up @@ -898,39 +898,30 @@
(is (lake::read-argument-from-string "t")
t)

(is (lake::read-argument-from-string "T")
t)

(is (lake::read-argument-from-string " t")
" t")

(is (lake::read-argument-from-string "nil")
nil)

(is (lake::read-argument-from-string "()")
(is (lake::read-argument-from-string "NIL")
nil)

(is (lake::read-argument-from-string "123")
123)

(is (lake::read-argument-from-string "123 ")
123)

(is (lake::read-argument-from-string "123 a")
123)
(is (lake::read-argument-from-string " nil")
" nil")

(is (lake::read-argument-from-string "123a")
"123a")
(is (lake::read-argument-from-string "()")
nil)

(is (lake::read-argument-from-string "12.3")
12.3)
(is (lake::read-argument-from-string " ()")
" ()")

(is (lake::read-argument-from-string "foo")
"foo")

(is (lake::read-argument-from-string "\"foo\"")
"foo")

(is (lake::read-argument-from-string "(foo 456)")
'(foo 456))

(is (lake::read-argument-from-string "(123")
"(123")

(is-error (lake::read-argument-from-string :foo)
type-error
"invalid type."))
Expand All @@ -947,20 +938,20 @@

;; An task argument, get its value from plist.
(let ((task (lake::make-task "foo" nil '(foo) nil nil #'noop)))
(is (lake::get-task-arguments task '(foo 123))
'(123)))
(is (lake::get-task-arguments task '(foo "123"))
'("123")))

;; An task argument, get its value from environment variables.
#+ros.init
(with-environment-variables (("FOO" "123"))
(let ((task (lake::make-task "foo" nil '(foo) nil nil #'noop)))
(is (lake::get-task-arguments task nil)
'(123))))
'("123"))))

;; An task argument, get its value from its default.
(let ((task (lake::make-task "foo" nil '((foo 123)) nil nil #'noop)))
(let ((task (lake::make-task "foo" nil '((foo "123")) nil nil #'noop)))
(is (lake::get-task-arguments task nil)
'(123)))
'("123")))

;; An task argument, no value for it supplied.
(let ((task (lake::make-task "foo" nil '(foo) nil nil #'noop)))
Expand Down Expand Up @@ -1083,10 +1074,10 @@
'("foo" nil))

(is-values (lake::parse-target "foo[123]")
'("foo" (123)))
'("foo" ("123")))

(is-values (lake::parse-target "foo[123,456]")
'("foo" (123 456)))
'("foo" ("123" "456")))

(is-values (lake::parse-target "foo[ foo, bar ]")
'("foo" (" foo" "bar")))
Expand Down

0 comments on commit 53e1261

Please sign in to comment.