Skip to content

Commit

Permalink
Tests: refactor inclusion directives test. Add tests for new %context…
Browse files Browse the repository at this point in the history
… directive. #182
  • Loading branch information
chen-factual committed Oct 21, 2015
1 parent 7b447f3 commit ac0d980
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
36 changes: 28 additions & 8 deletions test/drake/test/parser.clj
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
[actual-tuple key expected-value]
(= (get-in (second actual-tuple) [:vars key]) expected-value))

(defn var-pattern?
[actual-tuple key pattern]
(re-find pattern (get-in (second actual-tuple) [:vars key])))

(deftest var-def-test
(let [actual-tuple (d/var-def-line (make-state "MYVAR=myvalue\n"))]
(is (prod-eq? actual-tuple nil))
Expand Down Expand Up @@ -223,27 +227,43 @@
filename
"\n"))

(deftest include-test
(let [actual-prod (d/call-or-include-line
(deftest directive-include-test
(let [actual-prod (d/inclusion-directive-line
(make-state
(locally "%include" "nested.d")))]
(is (var-eq? actual-prod "NESTEDVAR" "/foo"))
(is (var-eq? actual-prod "BASE" "/base/nest/"))
(is (contains? (:methods (second actual-prod))
"sample_method")))
(let [actual-prod (d/call-or-include-line
(make-state
(locally "%call" "nested.d")))]
(is (var-eq? actual-prod "NESTEDVAR" nil))
(is (var-eq? actual-prod "BASE" "/base"))
(is (empty? (:methods (second actual-prod)))))
(let [actual-prod
(first
(d/workflow
(make-state (str (locally "%include" "nested.d")
"sample <- [method:sample_method]\n"))))]
(is (contains? (:methods actual-prod) "sample_method"))))

(deftest directive-call-test
(let [actual-prod (d/inclusion-directive-line
(make-state
(locally "%call" "nested.d")))]
(is (var-eq? actual-prod "NESTEDVAR" nil))
(is (var-eq? actual-prod "BASE" "/base"))
(is (empty? (:methods (second actual-prod))))))

(deftest directive-context-test
(let [actual-prod
(d/inclusion-directive-line
(make-state (locally "%context" "nested.d")))]
(is (every? :exec-dir (:steps actual-prod)))
(is (every? #(re-find #"test/resources" (:exec-dir %)) (:steps actual-prod)))
(is (var-pattern? actual-prod "PWD" #"test/resources$")))
(let [actual-prod
(d/inclusion-directive-line
(make-state (locally "%include" "nested.d")))]
(is (not-any? :exec-dir (:steps actual-prod)))
(is (not (var-pattern? actual-prod "PWD" #"test/resources$")))))


(def INLINE-SHELL-TEST-DATA "$(for DUDE in dude.txt babe.txt belle.txt; do echo \\\"$DUDE <\\\"\\\"-\\\"; echo \\\" echo $DUDE\\\"; echo; done)\n")

(deftest inline-shell-test
Expand Down
2 changes: 1 addition & 1 deletion test/drake/test/resources/nested.d
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
; our base data directory
BASE=$[BASE]/nest/
NESTEDVAR=/foo

PWD=$(pwd)

; Merge data from all sources
b.csv <- a.csv
Expand Down

0 comments on commit ac0d980

Please sign in to comment.