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 21 commits 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
10 changes: 5 additions & 5 deletions bb.edn
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@
(run 'test))}
lint (shell "clj-kondo --lint .")
test {:depends [gen-script]
:extra-deps {io.github.cognitect-labs/test-runner
{:git/tag "v0.5.1" :git/sha "dfb30dd"}
ring/ring-core {:mvn/version "1.12.1"}}
:extra-deps {io.github.cognitect-labs/test-runner {:git/tag "v0.5.1" :git/sha "dfb30dd"}
http-kit/http-kit {:mvn/version "2.8.0"}
ring/ring-core {:mvn/version "1.13.0"}}
:task cognitect.test-runner/-main}
test:clj (apply clojure "-M:test" *command-line-args*)
gen-script {:doc "Build the bbin script"
:extra-deps {org.clojure/tools.namespace
{:mvn/version "1.5.0"}}
:extra-deps {org.clojure/tools.namespace {:mvn/version "1.5.0"}}
:requires ([babashka.bbin.gen-script :as gen-script])
:task (gen-script/gen-script)}
render-templates {:requires ([clojure.string :as str]
Expand Down
18 changes: 11 additions & 7 deletions bbin
Original file line number Diff line number Diff line change
Expand Up @@ -740,12 +740,15 @@ 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)))

(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.fs :as fs]
[clojure.edn :as edn]
[clojure.main :as main]
Expand Down Expand Up @@ -1040,8 +1043,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 +1253,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 +1341,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
11 changes: 10 additions & 1 deletion deps.edn
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,13 @@
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-deps {http-kit/http-kit {:mvn/version "2.8.0"}
io.github.cognitect-labs/test-runner {:git/tag "v0.5.1" :git/sha "dfb30dd"}
ring/ring-core {:mvn/version "1.13.0"}}
:extra-paths ["test" "test-resources" "dev"]}
:test {:extra-deps {http-kit/http-kit {:mvn/version "2.8.0"}
io.github.cognitect-labs/test-runner {:git/tag "v0.5.1" :git/sha "dfb30dd"}
ring/ring-core {:mvn/version "1.13.0"}}
:extra-paths ["test" "test-resources" "dev"]
:main-opts ["-m" "cognitect.test-runner"]}}}
8 changes: 4 additions & 4 deletions src/babashka/bbin/scripts/common.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
(: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.fs :as fs]
[clojure.edn :as edn]
[clojure.main :as main]
Expand Down Expand Up @@ -298,8 +297,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
4 changes: 4 additions & 0 deletions src/babashka/bbin/util.clj
Original file line number Diff line number Diff line change
Expand Up @@ -319,3 +319,7 @@

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

(defmacro whenbb [& forms]
(when (System/getProperty "babashka.version")
`(do ~@forms)))
4 changes: 2 additions & 2 deletions test/babashka/bbin/scripts/maven_jar_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
(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"))
teodorlu marked this conversation as resolved.
Show resolved Hide resolved

(deftest upgrade-maven-jar-test
(testing "upgrade (maven jar)"
Expand All @@ -42,4 +42,4 @@
(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))))))
(is (= {'http-server upgraded-lib} (tu/run-ls))))))
Loading