Skip to content

Commit

Permalink
review feedback: move test-clj task code to file
Browse files Browse the repository at this point in the history
  • Loading branch information
lread committed Aug 12, 2024
1 parent 82e0f2d commit 3247155
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 34 deletions.
37 changes: 3 additions & 34 deletions bb.edn
Original file line number Diff line number Diff line change
@@ -1,38 +1,7 @@
{:tasks
{:paths ["script"]
:tasks
{test:clj {:doc "Run jvm tests, optionally specify clj-version (ex. :clj-1.10 :clj-1.11(default) or :clj-all)"
:requires ([clojure.string :as str]
[clojure.edn :as edn])
:task (let [args *command-line-args*
farg (first *command-line-args*)
;; allow for missing leading colon
farg (if (and farg (str/starts-with? farg "clj-"))
(str ":" farg)
farg)
clj-version-aliases (->> "deps.edn"
slurp
edn/read-string
:aliases
keys
(map str)
(filter (fn [a] (-> a name (str/starts-with? ":clj-"))))
sort
(into []))
[aliases args] (cond
(nil? farg) [[":clj-1.11"] []]

(= ":clj-all" farg) [clj-version-aliases (rest args)]

(and (str/starts-with? farg ":clj-")
(not (some #{farg} clj-version-aliases)))
(throw (ex-info (format "%s not recognized, valid clj- args are: %s or \":clj-all\"" farg clj-version-aliases) {}))

(some #{farg} clj-version-aliases) [[farg] (rest args)]

:else [[":clj-1.11"] args])]
(doseq [alias aliases]
(do
(println (format "-[Running jvm tests for %s]-" alias))
(apply clojure (str "-M:test" alias) args))))}
:task test-clj/-main}

test:bb {:extra-paths ["src" "test"]
:extra-deps {io.github.cognitect-labs/test-runner
Expand Down
41 changes: 41 additions & 0 deletions script/test_clj.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/usr/bin/env bb

(ns test-clj
(:require
[babashka.tasks :as tasks]
[clojure.edn :as edn]
[clojure.string :as str]))

(defn -main[& args]
(let [farg (first *command-line-args*)
;; allow for missing leading colon
farg (if (and farg (str/starts-with? farg "clj-"))
(str ":" farg)
farg)
clj-version-aliases (->> "deps.edn"
slurp
edn/read-string
:aliases
keys
(map str)
(filter (fn [a] (-> a name (str/starts-with? ":clj-"))))
sort
(into []))
[aliases args] (cond
(nil? farg) [[":clj-1.11"] []]

(= ":clj-all" farg) [clj-version-aliases (rest args)]

(and (str/starts-with? farg ":clj-")
(not (some #{farg} clj-version-aliases)))
(throw (ex-info (format "%s not recognized, valid clj- args are: %s or \":clj-all\"" farg clj-version-aliases) {}))

(some #{farg} clj-version-aliases) [[farg] (rest args)]

:else [[":clj-1.11"] args])]
(doseq [alias aliases]
(println (format "-[Running jvm tests for %s]-" alias))
(apply tasks/clojure (str "-M:test" alias) args))))

(when (= *file* (System/getProperty "babashka.file"))
(apply -main *command-line-args*))

0 comments on commit 3247155

Please sign in to comment.