Skip to content

Commit

Permalink
Add task arguments to file task.
Browse files Browse the repository at this point in the history
  • Loading branch information
takagi committed Sep 30, 2016
1 parent e84a621 commit 8057e32
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 16 deletions.
7 changes: 5 additions & 2 deletions src/lake.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -193,13 +193,16 @@

(defclass file-task (task) ())

(defun make-file-task (name namespace dependency desc action)
(defun make-file-task (name namespace args dependency desc action)
(dolist (arg args)
(check-type arg argument))
(check-type desc (or string null))
(check-type action function)
(let ((name1 (resolve-task-name name namespace))
(dependency1 (resolve-dependency-task-names dependency namespace)))
(make-instance 'file-task :name name1
:namespace namespace
:arguments args
:dependency dependency1
:description desc
:action action)))
Expand Down Expand Up @@ -227,7 +230,7 @@
(if (file-task-to-be-executed-p file-task)
(progn
;; Execute file task.
(funcall (task-action file-task))
(apply (task-action file-task) args)
;; Show message if verbose.
(verbose "done." t))
;; Skip file task to show message if verbose.
Expand Down
40 changes: 26 additions & 14 deletions t/lake.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@

(subtest "file-task"

(let ((task (lake::make-file-task "hello.o" '("hello") '("hello.c") "desc"
(let ((task (lake::make-file-task "hello.o" '("hello") nil '("hello.c") "desc"
#'(lambda ()
(sh "gcc -c hello.c")))))
(is (lake::task-name task)
Expand All @@ -366,56 +366,60 @@
(is (lake::task-description task)
"desc"))

(is-error (lake::make-file-task :foo nil nil nil #'noop)
(is-error (lake::make-file-task :foo nil nil nil nil #'noop)
type-error
"invalid task name.")

(is-error (lake::make-file-task "hello:hello.o" nil nil nil #'noop)
(is-error (lake::make-file-task "hello:hello.o" nil nil nil nil #'noop)
simple-error
"invalid task name.")

(is-error (lake::make-file-task "hello.o" :foo nil nil #'noop)
(is-error (lake::make-file-task "hello.o" :foo nil nil nil #'noop)
type-error
"invalid namespace.")

(is-error (lake::make-file-task "hello.o" '("foo:bar") nil nil #'noop)
(is-error (lake::make-file-task "hello.o" '("foo:bar") nil nil nil #'noop)
simple-error
"invalid namespace.")

(is-error (lake::make-file-task "hello.o" '(":foo") nil nil #'noop)
(is-error (lake::make-file-task "hello.o" '(":foo") nil nil nil #'noop)
simple-error
"invalid namespace.")

(is-error (lake::make-file-task "hello.o" nil :foo nil #'noop)
(is-error (lake::make-file-task "hello.o" nil :foo nil nil #'noop)
type-error
"invalid arguments.")

(is-error (lake::make-file-task "hello.o" nil nil :foo nil #'noop)
type-error
"invalid dependency.")

(is-error (lake::make-file-task "hello.o" nil nil :foo #'noop)
(is-error (lake::make-file-task "hello.o" nil nil nil :foo #'noop)
type-error
"invalid task description.")

(is-error (lake::make-file-task "hello.o" nil nil nil :foo)
(is-error (lake::make-file-task "hello.o" nil nil nil nil :foo)
type-error
"invalid task action."))

(subtest "file-task-out-of-date"

(with-test-directory
(let ((task (lake::make-file-task "foo" nil '("bar") nil #'noop)))
(let ((task (lake::make-file-task "foo" nil nil '("bar") nil #'noop)))
(sh "touch foo; sleep 1; touch bar")
(is (lake::file-task-out-of-date task)
t)
(sh "touch foo")
(is (lake::file-task-out-of-date task)
nil)))

(let ((task (lake::make-file-task "foo" nil '("bar") nil #'noop)))
(let ((task (lake::make-file-task "foo" nil nil '("bar") nil #'noop)))
(is-error (lake::file-task-out-of-date task)
error
"no target file exists."))

(with-test-directory
(let ((task (lake::make-file-task "foo" nil '("bar") nil #'noop)))
(let ((task (lake::make-file-task "foo" nil nil '("bar") nil #'noop)))
(sh "touch foo")
(is-error (lake::file-task-out-of-date task)
error
Expand All @@ -428,7 +432,7 @@
(subtest "execute-task - file-task"

(with-test-directory
(let ((task1 (lake::make-file-task "foo" nil '("bar") nil
(let ((task1 (lake::make-file-task "foo" nil nil '("bar") nil
#'(lambda ()
(sh "touch foo")
(echo "foo")))))
Expand All @@ -438,7 +442,15 @@
"base case 1.")
(is-print (lake::execute-task task1)
""
"base case 2."))))
"base case 2.")))

(with-test-directory
(let ((task (lake::make-file-task "foo" nil '(foo) nil nil
#'(lambda (foo)
(echo foo)))))
(is-print (lake::execute-task task '("123"))
(format nil "123~%")
"base case 3."))))


;;
Expand Down

0 comments on commit 8057e32

Please sign in to comment.