Lib tests

This commit is contained in:
Michiel Borkent 2020-02-19 23:58:49 +01:00
parent 847a2d1922
commit 7ad6f3195f
11 changed files with 75 additions and 12 deletions

View file

@ -38,6 +38,7 @@ jobs:
name: Run JVM tests
command: |
script/test
script/run_lib_tests
# - run:
# name: Run as tools.deps dependency
# command: |

View file

@ -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

View file

@ -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\")))

View file

@ -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\")))
"

View file

@ -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

17
script/lib_tests/medley_test Executable file
View file

@ -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))
"

13
script/lib_tests/regal_test Executable file
View file

@ -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])"

View file

@ -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\"]))

View file

@ -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

View file

@ -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

View file

@ -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"]