From 6bd3dc3d9fc1bf9628fe5bb239be9d1dfdcebe34 Mon Sep 17 00:00:00 2001 From: Michiel Borkent Date: Fri, 12 Jun 2020 23:47:38 +0200 Subject: [PATCH] [#471] add version info to nrepl describe op --- babashka.nrepl | 2 +- src/babashka/main.clj | 12 ++++++++---- test/babashka/impl/nrepl_server_test.clj | 17 ++++++++++++++--- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/babashka.nrepl b/babashka.nrepl index a0996a16..0ee3c85e 160000 --- a/babashka.nrepl +++ b/babashka.nrepl @@ -1 +1 @@ -Subproject commit a0996a1654459ee69032a8a3afd41c080fb4a729 +Subproject commit 0ee3c85e734e26fde1cbf78fb64b84a678831c13 diff --git a/src/babashka/main.clj b/src/babashka/main.clj index 5fffaac8..0f70d597 100644 --- a/src/babashka/main.clj +++ b/src/babashka/main.clj @@ -206,12 +206,14 @@ (defn shell-seq [in] (line-seq (java.io.BufferedReader. in))) +(def version (str/trim (slurp (io/resource "BABASHKA_VERSION")))) + (defn print-version [] - (println (str "babashka v"(str/trim (slurp (io/resource "BABASHKA_VERSION")))))) + (println (str "babashka v" version))) (defn print-help [] - (println (str "Babashka v" (str/trim (slurp (io/resource "BABASHKA_VERSION"))))) + (println (str "Babashka v" version)) ;; (println (str "sci v" (str/trim (slurp (io/resource "SCI_VERSION"))))) (println) (println "Options must appear in the order of groups mentioned below.") @@ -264,7 +266,7 @@ If neither -e, -f, or --socket-repl are specified, then the first argument that :feature/jdbc %s :feature/postgresql %s :feature/hsqldb %s}") - (str/trim (slurp (io/resource "BABASHKA_VERSION"))) + version features/core-async? features/csv? features/java-nio? @@ -303,7 +305,9 @@ If neither -e, -f, or --socket-repl are specified, then the first argument that (defn start-nrepl! [address ctx] (let [dev? (= "true" (System/getenv "BABASHKA_DEV")) nrepl-opts (nrepl-server/parse-opt address) - nrepl-opts (assoc nrepl-opts :debug dev?)] + nrepl-opts (assoc nrepl-opts + :debug dev? + :describe {"versions" {"babashka" version}})] (nrepl-server/start-server! ctx nrepl-opts) (binding [*out* *err*] (println "For more info visit https://github.com/borkdude/babashka/blob/master/doc/repl.md#nrepl."))) diff --git a/test/babashka/impl/nrepl_server_test.clj b/test/babashka/impl/nrepl_server_test.clj index a2737e7e..9f18d0ca 100644 --- a/test/babashka/impl/nrepl_server_test.clj +++ b/test/babashka/impl/nrepl_server_test.clj @@ -54,12 +54,20 @@ new-id! #(swap! id inc)] (testing "session" (is session)) + (testing "describe" + (bencode/write-bencode os {"op" "describe" "session" session "id" (new-id!)}) + (let [msg (read-reply in session @id) + id (:id msg) + versions (:versions msg) + babashka-version (bytes->str (get versions "babashka"))] + (is (= 1 id)) + (is (= main/version babashka-version)))) (testing "eval" (bencode/write-bencode os {"op" "eval" "code" "(+ 1 2 3)" "session" session "id" (new-id!)}) (let [msg (read-reply in session @id) id (:id msg) value (:value msg)] - (is (= 1 id)) + (is (= 2 id)) (is (= value "6"))) (testing "creating a namespace and evaluating something in it" (bencode/write-bencode os {"op" "eval" @@ -179,10 +187,13 @@ server-state (atom nil)] (try (if tu/jvm? - (let [server (start-server! + (let [nrepl-opts (parse-opt "0.0.0.0:1668") + nrepl-opts (assoc nrepl-opts + :describe {"versions" {"babashka" main/version}}) + server (start-server! (init {:namespaces main/namespaces :features #{:bb}}) - (parse-opt "0.0.0.0:1668"))] + nrepl-opts)] (reset! server-state server)) (let [pb (ProcessBuilder. ["./bb" "--nrepl-server" "0.0.0.0:1668"]) _ (.redirectError pb ProcessBuilder$Redirect/INHERIT)