forked from babashka/pods
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sci_test.clj
39 lines (37 loc) · 1.82 KB
/
sci_test.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
(ns babashka.pods.sci-test
(:require [babashka.pods.sci :as pods]
[babashka.pods.test-common :refer [test-program assertions pod-registry]]
[clojure.string :as str]
[clojure.test :refer [deftest is]]
[sci.core :as sci]))
(deftest sci-test
(let [out (java.io.StringWriter.)
err (java.io.StringWriter.)
ctx-ref (volatile! nil)
ctx (sci/init {:namespaces {'babashka.pods
{'load-pod (fn [& args]
(apply pods/load-pod @ctx-ref args))
'invoke pods/invoke
'unload-pod pods/unload-pod
'add-transit-read-handler! pods/add-transit-read-handler!
'add-transit-write-handler! pods/add-transit-write-handler!
'set-default-transit-write-handler! pods/set-default-transit-write-handler!}}
:classes {'System System
'java.time.LocalDateTime java.time.LocalDateTime
'java.lang.Class Class}})
_ (vreset! ctx-ref ctx)
ret (sci/binding [sci/out out
sci/err err]
(sci/eval-string* ctx test-program))]
(assertions out err ret)))
(deftest pod-registry-test
(let [out (java.io.StringWriter.)
err (java.io.StringWriter.)
ex (binding [*out* out
*err* err]
(try (load-string
pod-registry)
(catch Exception e
e)))]
(is (str/includes? (str out) "c3ab8ff13720e8ad9047dd39466b3c8974e592c2fa383d4a3960714caef0c4f2"))
(is (str/includes? (pr-str ex) "Version or path must be provided"))))