test
This commit is contained in:
parent
91106b5401
commit
a44f07a665
3 changed files with 50 additions and 22 deletions
|
|
@ -362,18 +362,14 @@ Use -- to separate script command line args from bb command line args.
|
|||
(println msg)
|
||||
{:exec (fn [] [nil exit])}))
|
||||
|
||||
(def ^:dynamic *bb-edn*
|
||||
(delay
|
||||
(let [bb-edn-file (or (System/getenv "BABASHKA_EDN")
|
||||
"bb.edn")]
|
||||
(when (fs/exists? bb-edn-file)
|
||||
(edn/read-string (slurp bb-edn-file))))))
|
||||
(def bb-edn
|
||||
(atom nil))
|
||||
|
||||
(defn parse-opts [options]
|
||||
(let [fst (when options (first options))
|
||||
key? (when fst (str/starts-with? fst ":"))
|
||||
k (when key? (keyword (subs fst 1)))
|
||||
bb-edn (when k @*bb-edn*)
|
||||
bb-edn (when k @bb-edn)
|
||||
tasks (when (and k bb-edn)
|
||||
(:tasks bb-edn))
|
||||
user-task (when tasks (get tasks k))]
|
||||
|
|
@ -516,6 +512,21 @@ Use -- to separate script command line args from bb command line args.
|
|||
opts-map))]
|
||||
opts))))
|
||||
|
||||
(defn resolve-task [task {:keys [:command-line-args]}]
|
||||
(case (:task/type task)
|
||||
:babashka
|
||||
(let [cmd-line-args (get task :args)]
|
||||
(parse-opts (seq (map str (concat cmd-line-args command-line-args)))))
|
||||
:shell
|
||||
(let [args (get task :args)
|
||||
args (into (vec args) command-line-args)]
|
||||
{:exec (fn []
|
||||
[nil
|
||||
(-> (p/process args {:inherit true})
|
||||
p/check
|
||||
:exit)])})
|
||||
(error (str "No such task: " (:task/type task)) 1)))
|
||||
|
||||
(def should-load-inits?
|
||||
"if true, then we should still load preloads and user.clj"
|
||||
(volatile! true))
|
||||
|
|
@ -739,8 +750,12 @@ Use -- to separate script command line args from bb command line args.
|
|||
[& args]
|
||||
(handle-pipe!)
|
||||
(handle-sigint!)
|
||||
(when-let [bb-edn @*bb-edn*]
|
||||
(deps/add-deps bb-edn))
|
||||
(let [bb-edn-file (or (System/getenv "BABASHKA_EDN")
|
||||
"bb.edn")]
|
||||
(when (fs/exists? bb-edn-file)
|
||||
(let [edn (edn/read-string (slurp bb-edn-file))]
|
||||
(reset! bb-edn edn)
|
||||
(deps/add-deps edn))))
|
||||
(if-let [dev-opts (System/getenv "BABASHKA_DEV")]
|
||||
(let [{:keys [:n]} (if (= "true" dev-opts) {:n 1}
|
||||
(edn/read-string dev-opts))
|
||||
|
|
|
|||
|
|
@ -1,22 +1,26 @@
|
|||
(ns babashka.bb-edn-test
|
||||
{:clj-kondo/config '{:linters {:unresolved-symbol {:exclude [working?]}}}}
|
||||
(:require
|
||||
[babashka.fs :as fs]
|
||||
[babashka.test-utils :as test-utils]
|
||||
[clojure.edn :as edn]
|
||||
[clojure.java.io :as io]
|
||||
[clojure.java.shell :refer [sh]]
|
||||
[clojure.string :as str]
|
||||
[clojure.test :as test :refer [deftest is testing *report-counters*]]
|
||||
[flatland.ordered.map :refer [ordered-map]]
|
||||
[sci.core :as sci])
|
||||
)
|
||||
[clojure.test :as test :refer [deftest is]]))
|
||||
|
||||
(defn bb [input & args]
|
||||
(defn bb [& args]
|
||||
(edn/read-string
|
||||
{:readers *data-readers*
|
||||
:eof nil}
|
||||
(apply test-utils/bb (when (some? input) (str input)) (map str args))))
|
||||
(apply test-utils/bb nil (map str args))))
|
||||
|
||||
(deftest foobar-test
|
||||
(prn :foobar))
|
||||
(let [temp-dir (fs/create-temp-dir)
|
||||
temp-file (fs/create-file (fs/path temp-dir "temp-file.txt"))
|
||||
bb-edn-file (fs/file temp-dir "bb.edn")
|
||||
bb-edn `{:tasks {:clean {:task/type :shell
|
||||
:args ["rm" ~(str temp-file)]}}}]
|
||||
(spit bb-edn-file bb-edn)
|
||||
(is (fs/exists? temp-file))
|
||||
(binding [test-utils/*bb-edn-path* (str bb-edn-file)]
|
||||
(bb :clean))
|
||||
(is (not (fs/exists? temp-file)))))
|
||||
|
||||
|
|
|
|||
|
|
@ -3,14 +3,19 @@
|
|||
[babashka.impl.classpath :as cp]
|
||||
[babashka.main :as main]
|
||||
[babashka.process :as p]
|
||||
[clojure.edn :as edn]
|
||||
[sci.core :as sci]
|
||||
[sci.impl.vars :as vars]))
|
||||
|
||||
(set! *warn-on-reflection* true)
|
||||
|
||||
(def ^:dynamic *bb-edn-path* nil)
|
||||
|
||||
(defn bb-jvm [input-or-opts & args]
|
||||
(reset! cp/cp-state nil)
|
||||
(reset! main/env {})
|
||||
(when-let [path *bb-edn-path*]
|
||||
(reset! main/bb-edn (edn/read-string (slurp path))))
|
||||
(let [os (java.io.StringWriter.)
|
||||
es (if-let [err (:err input-or-opts)]
|
||||
err (java.io.StringWriter.))
|
||||
|
|
@ -44,9 +49,13 @@
|
|||
|
||||
(defn bb-native [input & args]
|
||||
(let [res (p/process (into ["./bb"] args)
|
||||
{:in input
|
||||
(cond-> {:in input
|
||||
:out :string
|
||||
:err :string})
|
||||
:err :string}
|
||||
*bb-edn-path*
|
||||
(assoc
|
||||
:env (assoc (into {} (System/getenv))
|
||||
"BABASHKA_EDN" *bb-edn-path*))))
|
||||
res (deref res)
|
||||
exit (:exit res)
|
||||
error? (pos? exit)]
|
||||
|
|
|
|||
Loading…
Reference in a new issue