diff --git a/.circleci/config.yml b/.circleci/config.yml index cc4f3b34..a7cb1471 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -38,6 +38,7 @@ jobs: name: Run JVM tests command: | script/test + script/run_lib_tests # - run: # name: Run as tools.deps dependency # command: | diff --git a/README.md b/README.md index fc373499..0f70449f 100644 --- a/README.md +++ b/README.md @@ -519,14 +519,19 @@ $ bb script.clj -h ## Reader conditionals -Babashka supports reader conditionals using the `:bb` feature: +Babashka supports reader conditionals by taking either the `:bb` or `:clj` +branch, whichever comes first. NOTE: the `:clj` branch behavior was added in +version 0.0.71, before that version the `:clj` branch was ignored. ``` clojure -$ cat example.clj -#?(:clj (in-ns 'foo) :bb (println "babashka doesn't support in-ns yet!")) +$ bb "#?(:bb :hello :clj :bye)" +:hello -$ ./bb example.clj -babashka doesn't support in-ns yet! +$ bb "#?(:clj :bye :bb :hello)" +:bye + +$ bb "[1 2 #?@(:bb [] :clj [1])]" +[1 2] ``` ## Running tests diff --git a/script/lib_tests/clj_http_lite_test b/script/lib_tests/clj_http_lite_test index 43821d03..8ca39fb0 100755 --- a/script/lib_tests/clj_http_lite_test +++ b/script/lib_tests/clj_http_lite_test @@ -4,7 +4,13 @@ set -eo pipefail export BABASHKA_CLASSPATH=$(clojure -Sdeps '{:deps {clj-http-lite {:git/url "https://github.com/borkdude/clj-http-lite" :sha "f44ebe45446f0f44f2b73761d102af3da6d0a13e"}}}' -Spath) -./bb -e " +if [ "$BABASHKA_TEST_ENV" = "native" ]; then + BB_CMD="./bb" +else + BB_CMD="lein bb" +fi + +$BB_CMD -e " (require '[clj-http.lite.client :as client]) (prn (:status (client/get \"https://www.clojure.org\"))) diff --git a/script/lib_tests/clojure_csv_test b/script/lib_tests/clojure_csv_test index 3b8c6e26..c9b6adf0 100755 --- a/script/lib_tests/clojure_csv_test +++ b/script/lib_tests/clojure_csv_test @@ -4,7 +4,13 @@ set -eo pipefail export BABASHKA_CLASSPATH="$(clojure -Sdeps '{:deps {clojure-csv {:mvn/version "RELEASE"}}}' -Spath)" -./bb -e " +if [ "$BABASHKA_TEST_ENV" = "native" ]; then + BB_CMD="./bb" +else + BB_CMD="lein bb" +fi + +$BB_CMD -e " (require '[clojure-csv.core :as csv]) (prn (csv/write-csv (csv/parse-csv \"a,b,c\n1,2,3\"))) " diff --git a/script/lib_tests/deps_clj_test b/script/lib_tests/deps_clj_test index 29d78dc3..d23ae8b6 100755 --- a/script/lib_tests/deps_clj_test +++ b/script/lib_tests/deps_clj_test @@ -2,8 +2,14 @@ set -eo pipefail +if [ "$BABASHKA_TEST_ENV" = "native" ]; then + BB_CMD="./bb" +else + BB_CMD="lein bb" +fi + curl -sL https://raw.githubusercontent.com/borkdude/deps.clj/master/deps.clj -o deps_test.clj chmod +x deps_test.clj -./bb deps_test.clj -Sdescribe +$BB_CMD deps_test.clj -Sdescribe rm deps_test.clj diff --git a/script/lib_tests/medley_test b/script/lib_tests/medley_test new file mode 100755 index 00000000..9bdd30fd --- /dev/null +++ b/script/lib_tests/medley_test @@ -0,0 +1,17 @@ +#!/usr/bin/env bash + +set -eo pipefail + +export BABASHKA_CLASSPATH="$(clojure -Sdeps '{:deps {medley {:git/url "https://github.com/weavejester/medley" :sha "a4e5fb5383f5c0d83cb2d005181a35b76d8a136d"}}}' -Spath)" + +if [ "$BABASHKA_TEST_ENV" = "native" ]; then + BB_CMD="./bb" +else + BB_CMD="lein bb" +fi + +$BB_CMD " +(require '[medley.core :refer [index-by random-uuid]]) +(prn (index-by :id [{:id 1} {:id 2}])) +(prn (random-uuid)) +" diff --git a/script/lib_tests/regal_test b/script/lib_tests/regal_test new file mode 100755 index 00000000..17de219e --- /dev/null +++ b/script/lib_tests/regal_test @@ -0,0 +1,13 @@ +#!/usr/bin/env bash + +set -eo pipefail + +export BABASHKA_CLASSPATH="$(clojure -Sdeps '{:deps {regal {:git/url "https://github.com/lambdaisland/regal" :sha "e179f20a2ec78d47c8c24257e644ac80a70e33cb"}}}' -Spath)" + +if [ "$BABASHKA_TEST_ENV" = "native" ]; then + BB_CMD="./bb" +else + BB_CMD="lein bb" +fi + +$BB_CMD "(require '[lambdaisland.regal :as re]) (re/regex [:range \a \z])" diff --git a/script/lib_tests/spartan_spec_test b/script/lib_tests/spartan_spec_test index 617368d9..0100ca83 100755 --- a/script/lib_tests/spartan_spec_test +++ b/script/lib_tests/spartan_spec_test @@ -4,7 +4,13 @@ set -eo pipefail export BABASHKA_CLASSPATH=$(clojure -Sdeps '{:deps {spartan.spec {:git/url "https://github.com/borkdude/spartan.spec" :sha "16f7eec4b6589c77c96c9fcf989f78fffcee7c4c"}}}' -Spath) -./bb -e " +if [ "$BABASHKA_TEST_ENV" = "native" ]; then + BB_CMD="./bb" +else + BB_CMD="lein bb" +fi + +$BB_CMD -e " (time (require '[spartan.spec :as s])) (time (s/explain (s/cat :i int? :s string?) [1 :foo])) (time (s/conform (s/cat :i int? :s string?) [1 \"foo\"])) diff --git a/script/run_lib_tests b/script/run_lib_tests index e1a95e0b..8e0695a9 100755 --- a/script/run_lib_tests +++ b/script/run_lib_tests @@ -6,3 +6,5 @@ script/lib_tests/clj_http_lite_test script/lib_tests/deps_clj_test script/lib_tests/spartan_spec_test script/lib_tests/clojure_csv_test +script/lib_tests/regal_test +script/lib_tests/medley_test diff --git a/src/babashka/main.clj b/src/babashka/main.clj index 3cbf4259..b0b1a3a2 100644 --- a/src/babashka/main.clj +++ b/src/babashka/main.clj @@ -329,7 +329,7 @@ Everything after that is bound to *command-line-args*.")) #(when-let [{:keys [:loader]} @cp-state] (cp/getResource loader % {:url? true})))) :bindings bindings :env env - :features #{:bb} + :features #{:bb :clj} :classes classes/class-map :imports '{ArithmeticException java.lang.ArithmeticException AssertionError java.lang.AssertionError diff --git a/test/babashka/main_test.clj b/test/babashka/main_test.clj index 795b64f9..7d0e2e17 100644 --- a/test/babashka/main_test.clj +++ b/test/babashka/main_test.clj @@ -236,8 +236,9 @@ (is (zero? (bb nil "(try (/ 1 0) (catch ArithmeticException _ 0))")))) (deftest reader-conditionals-test - (is (= :hello (bb nil "#?(:clj (in-ns 'foo)) (println :hello)"))) - (is (= :hello (bb nil "#?(:bb :hello :default :bye)")))) + (is (= :hello (bb nil "#?(:bb :hello :default :bye)"))) + (is (= :hello (bb nil "#?(:clj :hello :bb :bye)"))) + (is (= [1 2] (bb nil "[1 2 #?@(:bb [] :clj [1])]")))) (deftest csv-test (is (= '(["Adult" "87727"] ["Elderly" "43914"] ["Child" "33411"] ["Adolescent" "29849"]