Refactor tests
This commit is contained in:
parent
52e86aff48
commit
4d484dc126
4 changed files with 38 additions and 48 deletions
|
|
@ -3,8 +3,14 @@
|
|||
A library to load babashka pods. Used by babashka but also usable from the JVM
|
||||
or other [sci](https://github.com/borkdude/sci)-based projects.
|
||||
|
||||
More information about babashka pods can be found
|
||||
[here](https://github.com/borkdude/babashka/blob/master/doc/pods.md).
|
||||
|
||||
## Usage
|
||||
|
||||
Using [pod-babashka-hsqldb](https://github.com/borkdude/pod-babashka-hsqldb) as
|
||||
an example pod.
|
||||
|
||||
On the JVM:
|
||||
|
||||
``` clojure
|
||||
|
|
|
|||
|
|
@ -1,36 +1,15 @@
|
|||
(ns babashka.pods.jvm-test
|
||||
(:require [clojure.test :refer [deftest is]]))
|
||||
(:require [babashka.pods.test-common :refer [test-program]]
|
||||
[clojure.string :as str]
|
||||
[clojure.test :refer [deftest is]]))
|
||||
|
||||
(deftest jvm-test2
|
||||
(deftest jvm-test
|
||||
(let [out (java.io.StringWriter.)
|
||||
err (java.io.StringWriter.)
|
||||
ret (binding [*out* out
|
||||
*err* err]
|
||||
(try (load-string
|
||||
"
|
||||
(require '[babashka.pods.jvm :as pods])
|
||||
|
||||
(require '[clojure.core.async :as async])
|
||||
|
||||
(pods/load-pod [\"clojure\" \"-A:test-pod\" \"--run-as-pod\"])
|
||||
|
||||
(require '[pod.test-pod :as pod])
|
||||
(def stream-results (atom []))
|
||||
(let [chan (pod.test-pod/range-stream 1 10)]
|
||||
(loop []
|
||||
(when-let [x (async/<!! chan)]
|
||||
(swap! stream-results conj x)
|
||||
(recur))))
|
||||
(def ex-result
|
||||
(try (pod.test-pod/error 1 2 3)
|
||||
(catch clojure.lang.ExceptionInfo e
|
||||
(str (ex-message e) \" / \" (ex-data e)))))
|
||||
(pod.test-pod/print \"hello\" \"print\" \"this\" \"debugging\" \"message\")
|
||||
(pod.test-pod/print-err \"hello\" \"print\" \"this\" \"error\")
|
||||
[(pod/assoc {:a 1} :b 2)
|
||||
(pod.test-pod/add-sync 1 2 3)
|
||||
@stream-results
|
||||
ex-result]")
|
||||
(str/replace test-program "babashka.pods" "babashka.pods.jvm"))
|
||||
(catch Exception e (prn e))))]
|
||||
|
||||
(is (= '[{:a 1, :b 2}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
(ns babashka.pods.sci-test
|
||||
(:require [babashka.pods.sci :as pods]
|
||||
[babashka.pods.test-common :refer [test-program]]
|
||||
[clojure.core.async :as async]
|
||||
[clojure.test :refer [deftest is]]
|
||||
[sci.core :as sci]))
|
||||
|
|
@ -10,28 +11,7 @@
|
|||
ret (sci/binding [sci/out out
|
||||
sci/err err]
|
||||
(sci/eval-string
|
||||
"
|
||||
(require '[babashka.pods :as pods])
|
||||
(require '[clojure.core.async :as async])
|
||||
|
||||
(pods/load-pod [\"clojure\" \"-A:test-pod\" \"--run-as-pod\"])
|
||||
(require '[pod.test-pod :as pod])
|
||||
(def stream-results (atom []))
|
||||
(let [chan (pod.test-pod/range-stream 1 10)]
|
||||
(loop []
|
||||
(when-let [x (async/<!! chan)]
|
||||
(swap! stream-results conj x)
|
||||
(recur))))
|
||||
(def ex-result
|
||||
(try (pod.test-pod/error 1 2 3)
|
||||
(catch clojure.lang.ExceptionInfo e
|
||||
(str (ex-message e) \" / \" (ex-data e)))))
|
||||
(pod.test-pod/print \"hello\" \"print\" \"this\" \"debugging\" \"message\")
|
||||
(pod.test-pod/print-err \"hello\" \"print\" \"this\" \"error\")
|
||||
[(pod/assoc {:a 1} :b 2)
|
||||
(pod.test-pod/add-sync 1 2 3)
|
||||
@stream-results
|
||||
ex-result]"
|
||||
test-program
|
||||
{:namespaces {'babashka.pods
|
||||
{'load-pod pods/load-pod}
|
||||
'clojure.core.async
|
||||
|
|
|
|||
25
test/babashka/pods/test_common.clj
Normal file
25
test/babashka/pods/test_common.clj
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
(ns babashka.pods.test-common)
|
||||
|
||||
(def test-program
|
||||
"
|
||||
(require '[babashka.pods :as pods])
|
||||
(require '[clojure.core.async :as async])
|
||||
|
||||
(pods/load-pod [\"clojure\" \"-A:test-pod\" \"--run-as-pod\"])
|
||||
(require '[pod.test-pod :as pod])
|
||||
(def stream-results (atom []))
|
||||
(let [chan (pod.test-pod/range-stream 1 10)]
|
||||
(loop []
|
||||
(when-let [x (async/<!! chan)]
|
||||
(swap! stream-results conj x)
|
||||
(recur))))
|
||||
(def ex-result
|
||||
(try (pod.test-pod/error 1 2 3)
|
||||
(catch clojure.lang.ExceptionInfo e
|
||||
(str (ex-message e) \" / \" (ex-data e)))))
|
||||
(pod.test-pod/print \"hello\" \"print\" \"this\" \"debugging\" \"message\")
|
||||
(pod.test-pod/print-err \"hello\" \"print\" \"this\" \"error\")
|
||||
[(pod/assoc {:a 1} :b 2)
|
||||
(pod.test-pod/add-sync 1 2 3)
|
||||
@stream-results
|
||||
ex-result]")
|
||||
Loading…
Reference in a new issue