Task tests
This commit is contained in:
parent
1020a8c335
commit
cf55681114
2 changed files with 15 additions and 5 deletions
|
|
@ -1,5 +1,6 @@
|
||||||
(ns babashka.bb-edn-test
|
(ns babashka.bb-edn-test
|
||||||
(:require
|
(:require
|
||||||
|
[babashka.fs :as fs]
|
||||||
[babashka.test-utils :as test-utils]
|
[babashka.test-utils :as test-utils]
|
||||||
[clojure.edn :as edn]
|
[clojure.edn :as edn]
|
||||||
[clojure.string :as str]
|
[clojure.string :as str]
|
||||||
|
|
@ -32,6 +33,16 @@
|
||||||
(is (= "src"
|
(is (= "src"
|
||||||
(bb "-cp" "src" "-e" "(babashka.classpath/get-classpath)"))))))
|
(bb "-cp" "src" "-e" "(babashka.classpath/get-classpath)"))))))
|
||||||
|
|
||||||
|
(deftest task-test
|
||||||
|
(test-utils/with-config '{:tasks {foo (+ 1 2 3)}}
|
||||||
|
(is (= 6 (bb "foo"))))
|
||||||
|
(let [tmp-dir (fs/create-temp-dir)
|
||||||
|
out (str (fs/file tmp-dir "out.txt"))]
|
||||||
|
(test-utils/with-config {:tasks {'foo (list 'shell {:out out}
|
||||||
|
"echo hello")}}
|
||||||
|
(bb "foo")
|
||||||
|
(is (= "hello\n" (slurp out))))))
|
||||||
|
|
||||||
;; TODO:
|
;; TODO:
|
||||||
;; Do we want to support the same parsing as the clj CLI?
|
;; Do we want to support the same parsing as the clj CLI?
|
||||||
;; Or do we want `--aliases :foo:bar`
|
;; Or do we want `--aliases :foo:bar`
|
||||||
|
|
|
||||||
|
|
@ -51,7 +51,6 @@
|
||||||
(if (string? input-or-opts)
|
(if (string? input-or-opts)
|
||||||
(with-in-str input-or-opts (apply main/main args))
|
(with-in-str input-or-opts (apply main/main args))
|
||||||
(apply main/main args)))]
|
(apply main/main args)))]
|
||||||
;; (prn :err (str es))
|
|
||||||
(if (zero? res)
|
(if (zero? res)
|
||||||
(str os)
|
(str os)
|
||||||
(do
|
(do
|
||||||
|
|
@ -67,12 +66,12 @@
|
||||||
(defn bb-native [input & args]
|
(defn bb-native [input & args]
|
||||||
(let [res (p/process (into ["./bb"] args)
|
(let [res (p/process (into ["./bb"] args)
|
||||||
(cond-> {:in input
|
(cond-> {:in input
|
||||||
:out :string
|
:out :string
|
||||||
:err :string}
|
:err :string}
|
||||||
*bb-edn-path*
|
*bb-edn-path*
|
||||||
(assoc
|
(assoc
|
||||||
:env (assoc (into {} (System/getenv))
|
:extra-env (assoc (into {} (System/getenv))
|
||||||
"BABASHKA_EDN" *bb-edn-path*))))
|
"BABASHKA_EDN" *bb-edn-path*))))
|
||||||
res (deref res)
|
res (deref res)
|
||||||
exit (:exit res)
|
exit (:exit res)
|
||||||
error? (pos? exit)]
|
error? (pos? exit)]
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue