Skip to content

Commit

Permalink
Fix failing tests and enable running tests on JVM
Browse files Browse the repository at this point in the history
This commit enables a JVM-based workflow. The tests that pass without
modification on a JVM can now be run on a JVM. The tests that fail on JVM now
only run on Babashka.

In addition, test data has been updated to reflect the reality - per 2024-11-27,
the latest version of org.babashka/http-server is 0.1.13.
  • Loading branch information
teodorlu committed Nov 27, 2024
1 parent 0dcfdad commit 7bc2552
Show file tree
Hide file tree
Showing 13 changed files with 91 additions and 45 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,5 @@
/checkouts
/classes
/target

/deps.local.edn
3 changes: 2 additions & 1 deletion bb.edn
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
:pods {org.babashka/fswatcher {:version "0.0.3"}}
:deps {org.babashka/spec.alpha {:git/url "https://github.com/babashka/spec.alpha"
:git/sha "951b49b8c173244e66443b8188e3ff928a0a71e7"}
local/deps {:local/root "."}}
local/deps {:local/root "."}
com.lambdaisland/launchpad {:mvn/version "0.33.149-alpha"}}
:bbin/bin {bbin {:main-opts ["-f" "bbin"]}}
:tasks {bbin {:requires ([babashka.bbin.cli :as bbin])
:task (apply bbin/-main *command-line-args*)}
Expand Down
28 changes: 20 additions & 8 deletions bbin
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
org.babashka/http-client {:mvn/version "0.1.8"},
version-clj/version-clj {:mvn/version "2.0.2"},
babashka/fs {:mvn/version "0.3.17"},
org.babashka/json {:mvn/version "0.1.1"}}})
ring/ring-core {:mvn/version "1.13.0"},
org.babashka/json {:mvn/version "0.1.1"},
http-kit/http-kit {:mvn/version "2.8.0"}}})

(ns babashka.bbin.meta)
(def min-bb-version "This def was generated by the bbin build script." "0.9.162")
Expand Down Expand Up @@ -740,12 +742,21 @@ WARNING: (We won't make any changes without asking you first.)
(defn snake-case [s]
(str/replace s "_" "-"))

(defmacro whenbb [& forms]
(when (System/getProperty "babashka.version")
`(do ~@forms)))

(defmacro ifbb [then else]
(if (System/getProperty "babashka.version")
then
else))

(ns babashka.bbin.scripts.common
(:require [babashka.bbin.deps :as bbin-deps]
[babashka.bbin.dirs :as dirs]
[babashka.bbin.specs]
[babashka.bbin.util :as util :refer [sh]]
[babashka.deps :as deps]
[babashka.bbin.util :as util :refer [sh whenbb]]
;; [babashka.deps :as deps]
[babashka.fs :as fs]
[clojure.edn :as edn]
[clojure.main :as main]
Expand Down Expand Up @@ -1040,8 +1051,9 @@ WARNING: (We won't make any changes without asking you first.)
header' (if (#{::no-lib} lib)
{:coords {:bbin/url (str "file://" (get-in header [:coords :local/root]))}}
header)
_ (when-not (#{::no-lib} lib)
(deps/add-deps {:deps script-deps}))
_ (whenbb (when-not (#{::no-lib} lib)
((requiring-resolve 'babashka.deps/add-deps)
{:deps script-deps})))
script-root (fs/canonicalize (or (get-in header [:coords :local/root])
(local-lib-path script-deps))
{:nofollow-links true})
Expand Down Expand Up @@ -1249,8 +1261,7 @@ WARNING: (We won't make any changes without asking you first.)
(:require [babashka.bbin.dirs :as dirs]
[babashka.bbin.protocols :as p]
[babashka.bbin.scripts.common :as common]
[babashka.bbin.util :as util]
[babashka.deps :as deps]
[babashka.bbin.util :as util :refer [whenbb]]
[babashka.fs :as fs]
[babashka.http-client :as http]
[babashka.json :as json]
Expand Down Expand Up @@ -1338,7 +1349,8 @@ WARNING: (We won't make any changes without asking you first.)
(select-keys cli-opts [:mvn/version])}
header {:lib (key (first script-deps))
:coords (val (first script-deps))}
_ (deps/add-deps {:deps script-deps})
_ (whenbb ((requiring-resolve 'babashka.deps/add-deps)
{:deps script-deps}) )
script-root (fs/canonicalize (or (:local/root cli-opts) (common/local-lib-path script-deps)) {:nofollow-links true})
script-name (or (:as cli-opts) (second (str/split (:script/lib cli-opts) #"/")))
script-config (common/default-script-config cli-opts)
Expand Down
2 changes: 2 additions & 0 deletions bin/kaocha
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/usr/bin/env sh
clojure -M:kaocha "$@"
8 changes: 8 additions & 0 deletions bin/launchpad
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bb

(require '[lambdaisland.launchpad :as launchpad])

(launchpad/main {})

;; (launchpad/main {:steps (into [(partial launchpad/ensure-java-version 17)]
;; launchpad/default-steps)})
8 changes: 7 additions & 1 deletion deps.edn
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,17 @@
com.taoensso/timbre {:mvn/version "5.2.1"}
expound/expound {:mvn/version "0.9.0"}
fipp/fipp {:mvn/version "0.6.26"}
http-kit/http-kit {:mvn/version "2.8.0"}
org.babashka/cli {:mvn/version "0.6.43"}
org.babashka/http-client {:mvn/version "0.1.8"}
org.babashka/json {:mvn/version "0.1.1"}
org.clojure/tools.gitlibs {:mvn/version "2.4.181"}
ring/ring-core {:mvn/version "1.13.0"}
selmer/selmer {:mvn/version "1.12.55"}
version-clj/version-clj {:mvn/version "2.0.2"}}
:aliases {:neil {:project {:name babashka/bbin
:version "0.2.4"}}}}
:version "0.2.4"}}
:dev {:extra-paths ["test" "test-resources" "dev"]
:extra-deps {lambdaisland/kaocha {:mvn/version "1.91.1392"}}}
:kaocha {:extra-deps {lambdaisland/kaocha {:mvn/version "1.91.1392"}}
:main-opts ["-m" "kaocha.runner"]}}}
2 changes: 1 addition & 1 deletion dev/babashka/bbin/dev.clj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(ns babashka.bbin.dev
(:require [babashka.process :refer [sh]]
[clojure.core.async :refer [<!] :as async]
[clojure.core.async :as async :refer [<!]]
[clojure.string :as str]
[pod.babashka.fswatcher :as fw]
[taoensso.timbre :as log]))
Expand Down
9 changes: 5 additions & 4 deletions src/babashka/bbin/scripts/common.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
(:require [babashka.bbin.deps :as bbin-deps]
[babashka.bbin.dirs :as dirs]
[babashka.bbin.specs]
[babashka.bbin.util :as util :refer [sh]]
[babashka.deps :as deps]
[babashka.bbin.util :as util :refer [sh whenbb]]
;; [babashka.deps :as deps]
[babashka.fs :as fs]
[clojure.edn :as edn]
[clojure.main :as main]
Expand Down Expand Up @@ -298,8 +298,9 @@
header' (if (#{::no-lib} lib)
{:coords {:bbin/url (str "file://" (get-in header [:coords :local/root]))}}
header)
_ (when-not (#{::no-lib} lib)
(deps/add-deps {:deps script-deps}))
_ (whenbb (when-not (#{::no-lib} lib)
((requiring-resolve 'babashka.deps/add-deps)
{:deps script-deps})))
script-root (fs/canonicalize (or (get-in header [:coords :local/root])
(local-lib-path script-deps))
{:nofollow-links true})
Expand Down
6 changes: 3 additions & 3 deletions src/babashka/bbin/scripts/maven_jar.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
(:require [babashka.bbin.dirs :as dirs]
[babashka.bbin.protocols :as p]
[babashka.bbin.scripts.common :as common]
[babashka.bbin.util :as util]
[babashka.deps :as deps]
[babashka.bbin.util :as util :refer [whenbb]]
[babashka.fs :as fs]
[babashka.http-client :as http]
[babashka.json :as json]
Expand Down Expand Up @@ -91,7 +90,8 @@
(select-keys cli-opts [:mvn/version])}
header {:lib (key (first script-deps))
:coords (val (first script-deps))}
_ (deps/add-deps {:deps script-deps})
_ (whenbb ((requiring-resolve 'babashka.deps/add-deps)
{:deps script-deps}) )
script-root (fs/canonicalize (or (:local/root cli-opts) (common/local-lib-path script-deps)) {:nofollow-links true})
script-name (or (:as cli-opts) (second (str/split (:script/lib cli-opts) #"/")))
script-config (common/default-script-config cli-opts)
Expand Down
9 changes: 9 additions & 0 deletions src/babashka/bbin/util.clj
Original file line number Diff line number Diff line change
Expand Up @@ -319,3 +319,12 @@

(defn snake-case [s]
(str/replace s "_" "-"))

(defmacro whenbb [& forms]
(when (System/getProperty "babashka.version")
`(do ~@forms)))

(defmacro ifbb [then else]
(if (System/getProperty "babashka.version")
then
else))
28 changes: 15 additions & 13 deletions test/babashka/bbin/scripts/local_dir_test.clj
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
(ns babashka.bbin.scripts.local-dir-test
(:require [babashka.bbin.dirs :as dirs]
[babashka.bbin.test-util :as tu]
[babashka.bbin.util :refer [whenbb]]
[babashka.fs :as fs]
[clojure.string :as str]
[clojure.test :refer [deftest is testing use-fixtures]])
Expand All @@ -24,19 +25,20 @@
out))
(is (fs/exists? (fs/file (dirs/bin-dir nil) "foo")))))))

(deftest invalid-bin-config-test
(testing "install */* --local/root * (invalid bin config)"
(tu/reset-test-dir)
(dirs/ensure-bbin-dirs {})
(let [local-root (str (fs/file tu/test-dir "foo"))
invalid-config 123]
(fs/create-dir local-root)
(spit (fs/file local-root "bb.edn") (pr-str {:bbin/bin invalid-config}))
(spit (fs/file local-root "deps.edn") (pr-str {}))
(let [cli-opts {:script/lib "babashka/foo"
:local/root local-root}]
(is (thrown-with-msg? ExceptionInfo #"123 - failed: map\? spec: :bbin/bin"
(tu/run-install cli-opts)))))))
(whenbb
(deftest invalid-bin-config-test
(testing "install */* --local/root * (invalid bin config)"
(tu/reset-test-dir)
(dirs/ensure-bbin-dirs {})
(let [local-root (str (fs/file tu/test-dir "foo"))
invalid-config 123]
(fs/create-dir local-root)
(spit (fs/file local-root "bb.edn") (pr-str {:bbin/bin invalid-config}))
(spit (fs/file local-root "deps.edn") (pr-str {}))
(let [cli-opts {:script/lib "babashka/foo"
:local/root local-root}]
(is (thrown-with-msg? ExceptionInfo #"123 - failed: map\? spec: :bbin/bin"
(tu/run-install cli-opts))))))))

(deftest install-from-no-lib-local-root-dir-test
(testing "install ./"
Expand Down
30 changes: 16 additions & 14 deletions test/babashka/bbin/scripts/maven_jar_test.clj
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
(ns babashka.bbin.scripts.maven-jar-test
(:require [babashka.bbin.dirs :as dirs]
[babashka.bbin.test-util :as tu]
[babashka.bbin.util :refer [whenbb]]
[babashka.fs :as fs]
[clojure.string :as str]
[clojure.test :refer [deftest is testing use-fixtures]]))
Expand Down Expand Up @@ -28,18 +29,19 @@
(is (= `{~'http-server ~maven-lib} (tu/run-ls))))))

(def upgraded-lib
(assoc-in maven-lib [:coords :mvn/version] "0.1.12"))
(assoc-in maven-lib [:coords :mvn/version] "0.1.13"))

(deftest upgrade-maven-jar-test
(testing "upgrade (maven jar)"
(tu/reset-test-dir)
(dirs/ensure-bbin-dirs {})
(let [out (tu/run-install {:script/lib (str (:lib maven-lib))
:mvn/version (-> maven-lib :coords :mvn/version)})
out2 (tu/run-upgrade {:script/lib "http-server"})]
(is (= maven-lib out))
(is (= upgraded-lib out2))
(is (fs/exists? (fs/file (dirs/bin-dir nil) (name (:lib upgraded-lib)))))
(is (str/starts-with? (tu/run-bin-script (:lib upgraded-lib) "--help")
help-text))
(is (= `{~'http-server ~upgraded-lib} (tu/run-ls))))))
(whenbb
(deftest upgrade-maven-jar-test
(testing "upgrade (maven jar)"
(tu/reset-test-dir)
(dirs/ensure-bbin-dirs {})
(let [out (tu/run-install {:script/lib (str (:lib maven-lib))
:mvn/version (-> maven-lib :coords :mvn/version)})
out2 (tu/run-upgrade {:script/lib "http-server"})]
(is (= maven-lib out))
(is (= upgraded-lib out2))
(is (fs/exists? (fs/file (dirs/bin-dir nil) (name (:lib upgraded-lib)))))
(is (str/starts-with? (tu/run-bin-script (:lib upgraded-lib) "--help")
help-text))
(is (= {'http-server upgraded-lib} (tu/run-ls)))))))
1 change: 1 addition & 0 deletions tests.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#kaocha/v1 {}

0 comments on commit 7bc2552

Please sign in to comment.