Skip to content

Commit

Permalink
Add a tiny JVM test runner
Browse files Browse the repository at this point in the history
  • Loading branch information
PEZ committed Dec 17, 2024
1 parent aa87b99 commit 63b9f91
Showing 1 changed file with 27 additions and 7 deletions.
34 changes: 27 additions & 7 deletions scripts/tasks.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
(:require
[babashka.fs :as fs]
[babashka.http-client :as http]
[babashka.process :as p]))
[babashka.process :as p]
[clojure.string :as string]))


(def inspector-zip-url "https://github.com/cjohansen/gadget-inspector/archive/refs/heads/master.zip")
Expand Down Expand Up @@ -69,14 +70,33 @@
["LICENSE.md"]])
(p/shell "tree" app-dir)))

; Adapted from https://gist.github.com/thiagokokada/fee513a7b8578c87c05469267c48e612

(defn test-file->test-ns
[file]
(as-> file $
(fs/components $)
(drop 1 $)
(mapv str $)
(string/join "." $)
(string/replace $ #"_" "-")
(string/replace $ #"\.cljc?$" "")
(str "'" $)))

(defn quoted-test-namespaces []
(->> (fs/glob "test" "**/*_test.clj{,c}")
(mapv test-file->test-ns)))

(defn ns->require-str [qns]
(str "(require " qns ")"))

(defn ^:export run-tests-jvm! []
(println "Running view tests with JVM Clojure...")
(let [command ["clojure" "-M:test" "-e"
"(require 'clojure.test)
(require 'pez.baldr)
(require 'todomvc.views-test)
(require 'todomvc.actions-test)
(clojure.test/run-tests 'todomvc.actions-test 'todomvc.views-test)"]
(let [qnss (quoted-test-namespaces)
command ["clojure" "-M:test" "-e"
(str "(require 'clojure.test)"
(string/join "\n" (map ns->require-str qnss))
"(clojure.test/run-tests " (string/join " " qnss) ")")]
{:keys [err exit]} (apply p/shell command)]
(when-not (zero? exit)
(println err))))

0 comments on commit 63b9f91

Please sign in to comment.