Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable running (most of) bbin's test suite on a JVM #92

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No trailing final newline is ugly!

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"}}})
Comment on lines -20 to +22
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't expect these dependencies to make it into ./bbin - I propose to move these deps to the :dev alias to avoid adding depdendencies to bbin users.


(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))
Comment on lines +749 to +752
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ifbb is not in use, and should be deleted.


(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]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commented-out lines should be deleted!

[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 [<!]]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My editor did this without me noticing, I'll revert it!

[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]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delete out-commented line.

[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))
Comment on lines +327 to +330
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ifbb is not used, should be deleted.

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"))
Comment on lines 31 to +32
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to be a failing test on master too - 0.1.13 is the latest org.babashka/http-server version.


(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 {}