0.2.4 - tests

This commit is contained in:
Michiel Borkent 2020-11-27 09:48:31 +01:00
parent fc11d6d0cb
commit 42e3f44fcb
2 changed files with 78 additions and 67 deletions

View file

@ -34,3 +34,6 @@ lein test :only babashka.classpath-test/classpath-env-test
export BABASHKA_POD_TEST=true
lein test :only babashka.pod-test
export BABASHKA_SOCKET_REPL_TEST=true
lein test :only babashka.impl.socket-repl-test

View file

@ -40,81 +40,89 @@
(def server-process (volatile! nil))
(def exec? (System/getenv "BABASHKA_SOCKET_REPL_TEST"))
(deftest socket-repl-test
(try
(if tu/jvm?
(let [ctx (init {:namespaces {'clojure.core.server clojure-core-server}
:features #{:bb}})]
(vreset! common/ctx ctx)
(start-repl! "0.0.0.0:1666" ctx))
(do (vreset! server-process
(p/process ["./bb" "--socket-repl" "localhost:1666"]))
(w/wait-for-port "localhost" 1666)))
(Thread/sleep 50)
(is (socket-command "(+ 1 2 3)" "user=> 6"))
(testing "&env"
(socket-command "(defmacro bindings [] (mapv #(list 'quote %) (keys &env)))" "bindings")
(socket-command "(defn bar [x y z] (bindings))" "bar")
(is (socket-command "(bar 1 2 3)" "[x y z]")))
(testing "reader conditionals"
(is (socket-command "#?(:bb 1337 :clj 8888)" "1337")))
(testing "*1, *2, *3, *e"
(is (socket-command "1\n*1" "1")))
(testing "*ns*"
(is (socket-command "(ns foo.bar) (ns-name *ns*)" "foo.bar")))
(finally
(when exec?
(try
(if tu/jvm?
(do (stop-repl!)
(Thread/sleep 100))
(p/destroy-tree @server-process)))))
(let [ctx (init {:namespaces {'clojure.core.server clojure-core-server}
:features #{:bb}})]
(vreset! common/ctx ctx)
(start-repl! "0.0.0.0:1666" ctx))
(do (vreset! server-process
(p/process ["./bb" "--socket-repl" "localhost:1666"]))
(w/wait-for-port "localhost" 1666)))
(Thread/sleep 50)
(is (socket-command "(+ 1 2 3)" "user=> 6"))
(testing "&env"
(socket-command "(defmacro bindings [] (mapv #(list 'quote %) (keys &env)))" "bindings")
(socket-command "(defn bar [x y z] (bindings))" "bar")
(is (socket-command "(bar 1 2 3)" "[x y z]")))
(testing "reader conditionals"
(is (socket-command "#?(:bb 1337 :clj 8888)" "1337")))
(testing "*1, *2, *3, *e"
(is (socket-command "1\n*1" "1")))
(testing "*ns*"
(is (socket-command "(ns foo.bar) (ns-name *ns*)" "foo.bar")))
(finally
(if tu/jvm?
(do (stop-repl!)
(vreset! common/ctx nil)
(Thread/sleep 100))
(p/destroy-tree @server-process))))))
(deftest socket-repl-opts-test
(try
(if tu/jvm?
(let [ctx (init {:bindings {'*command-line-args*
["a" "b" "c"]}
:env (atom {})
:namespaces {'clojure.core.server clojure-core-server}
:features #{:bb}})]
(vreset! common/ctx ctx)
(start-repl! "{:address \"localhost\" :accept clojure.core.server/repl :port 1666}"
ctx))
(do (vreset! server-process
(p/process ["./bb" "--socket-repl" "{:address \"localhost\" :accept clojure.core.server/repl :port 1666}"]))
(w/wait-for-port "localhost" 1666)))
(Thread/sleep 50)
(is (socket-command "(+ 1 2 3)" "user=> 6"))
(finally
(when exec?
(try
(if tu/jvm?
(do (stop-repl!)
(Thread/sleep 100))
(p/destroy-tree @server-process)))))
(let [ctx (init {:bindings {'*command-line-args*
["a" "b" "c"]}
:env (atom {})
:namespaces {'clojure.core.server clojure-core-server}
:features #{:bb}})]
(vreset! common/ctx ctx)
(start-repl! "{:address \"localhost\" :accept clojure.core.server/repl :port 1666}"
ctx))
(do (vreset! server-process
(p/process ["./bb" "--socket-repl" "{:address \"localhost\" :accept clojure.core.server/repl :port 1666}"]))
(w/wait-for-port "localhost" 1666)))
(Thread/sleep 50)
(is (socket-command "(+ 1 2 3)" "user=> 6"))
(finally
(if tu/jvm?
(do (stop-repl!)
(vreset! common/ctx nil)
(Thread/sleep 100))
(p/destroy-tree @server-process))))))
(deftest socket-prepl-test
(try
(if tu/jvm?
(let [ctx (init {:bindings {'*command-line-args*
["a" "b" "c"]}
:env (atom {})
:namespaces {'clojure.core.server clojure-core-server}
:features #{:bb}})]
(vreset! common/ctx ctx)
(start-repl! "{:address \"localhost\" :accept clojure.core.server/io-prepl :port 1666}"
ctx))
(do (vreset! server-process
(p/process ["./bb" "--socket-repl" "{:address \"localhost\" :accept clojure.core.server/io-prepl :port 1666}"]))
(w/wait-for-port "localhost" 1666)))
(Thread/sleep 50)
(is (socket-command "(+ 1 2 3)" (fn [s]
(let [m (edn/read-string s)]
(and (= "6" (:val m))
(= "user" (:ns m))
(= "(+ 1 2 3)" (:form m)))))))
(finally
(when exec?
(try
(if tu/jvm?
(do (stop-repl!)
(Thread/sleep 100))
(p/destroy-tree @server-process)))))
(let [ctx (init {:bindings {'*command-line-args*
["a" "b" "c"]}
:env (atom {})
:namespaces {'clojure.core.server clojure-core-server}
:features #{:bb}})]
(vreset! common/ctx ctx)
(start-repl! "{:address \"localhost\" :accept clojure.core.server/io-prepl :port 1666}"
ctx))
(do (vreset! server-process
(p/process ["./bb" "--socket-repl" "{:address \"localhost\" :accept clojure.core.server/io-prepl :port 1666}"]))
(w/wait-for-port "localhost" 1666)))
(Thread/sleep 50)
(is (socket-command "(+ 1 2 3)" (fn [s]
(let [m (edn/read-string s)]
(and (= "6" (:val m))
(= "user" (:ns m))
(= "(+ 1 2 3)" (:form m)))))))
(finally
(if tu/jvm?
(do (stop-repl!)
(vreset! common/ctx nil)
(Thread/sleep 100))
(p/destroy-tree @server-process))))))
;;;; Scratch