Compare commits

...

20 commits

Author SHA1 Message Date
Michiel Borkent
663052bda3 wip [skip ci] 2023-04-21 10:47:57 +02:00
Michiel Borkent
631f54e4e2 wip 2023-04-21 10:43:42 +02:00
Michiel Borkent
89e1351456 Add --install-exit-handlers to support shutdown hook + SIGTERM (#1540) 2023-04-21 10:42:24 +02:00
Michiel Borkent
f58c0fcff4 Bump http-client 2023-04-21 10:42:24 +02:00
Bob
e933a5aef3 vary ports across socket repl tests (#1539)
* use different port for socket repl tests

- update socket-command to socket-command-on-port, which
 takes a port and then returns the socket-command function
- change port numbers across tests

* undo little formatting change

* grr... newlines
2023-04-21 10:42:24 +02:00
Michiel Borkent
9a6f48b986 Bump CLI 2023-04-21 10:42:24 +02:00
Michiel Borkent
73805703a2 docs [skip ci] 2023-04-21 10:42:24 +02:00
Michiel Borkent
5f0a822a55 docs 2023-04-21 10:42:24 +02:00
Michiel Borkent
a05004b9a2 Add UnsupportedOperationException 2023-04-21 10:42:24 +02:00
Michiel Borkent
5f3da77669 Bump edamame 2023-04-21 10:42:24 +02:00
Michiel Borkent
74b6b736d5 Bump edamame to 1.3.21 2023-04-21 10:42:24 +02:00
Michiel Borkent
6bb48134f4 built-in deps.edn 2023-04-21 10:42:24 +02:00
Michiel Borkent
07a0c03593 Bump clj-yaml to 1.0.26 2023-04-21 10:42:24 +02:00
Michiel Borkent
8f96f23e35 deps.clj upgrade 2023-04-21 10:42:24 +02:00
Michiel Borkent
4db8f7cc92 sci [skip ci] 2023-04-21 10:42:24 +02:00
Michiel Borkent
15df72344d Add java.security.cert.CertificateFactory (#1531) 2023-04-21 10:42:24 +02:00
Michiel Borkent
0dd55dc556 news 2023-04-21 10:42:24 +02:00
Michiel Borkent
4cfe188861 news 2023-04-21 10:42:24 +02:00
Benni Schwerdtner
60af6a3a94 Add middleware example, reaadme 2023-04-07 12:11:29 +02:00
Benni Schwerdtner
dbb28b86e1 Add middleware arg #1529 2023-04-07 12:02:25 +02:00
21 changed files with 277 additions and 118 deletions

@ -1 +1 @@
Subproject commit ad763a78f1bc327a493ff0b650aa5408ecbf4819
Subproject commit 52a5a2daa4cc048c8d5d93a36e0ac05d52dfa21d

@ -1 +1 @@
Subproject commit 9bae77d5b346089f4fd2108933971c5a342ed39e
Subproject commit 2f93fe8ba712c855feb6ecf26d2ed70646b34356

View file

@ -31,7 +31,7 @@
org.clojure/data.csv {:mvn/version "1.0.0"},
cheshire/cheshire {:mvn/version "5.11.0"}
org.clojure/data.xml {:mvn/version "0.2.0-alpha8"}
clj-commons/clj-yaml {:mvn/version "0.7.169"}
clj-commons/clj-yaml {:mvn/version "1.0.26"}
com.cognitect/transit-clj {:mvn/version "1.0.333"}
org.clojure/test.check {:mvn/version "1.1.1"}
nrepl/bencode {:mvn/version "1.1.0"}
@ -50,8 +50,8 @@
org.clojure/data.priority-map {:mvn/version "1.1.0"}
insn/insn {:mvn/version "0.5.2"}
org.clojure/core.rrb-vector {:mvn/version "0.1.2"}
org.babashka/cli {:mvn/version "0.6.50"}
org.babashka/http-client {:mvn/version "0.1.8"}
org.babashka/cli {:mvn/version "0.7.51"}
org.babashka/http-client {:mvn/version "0.2.9"}
;; native image bloat with ordered 1.5.10
org.flatland/ordered {:mvn/version "1.5.9"}}
:aliases {:babashka/dev

View file

@ -5,6 +5,55 @@ you have anything to add. Also see
[#babashka](https://twitter.com/hashtag/babashka?src=hashtag_click&f=live) on
Twitter.
## 2023-03 ([Twitter](https://twitter.com/search?q=(%23babashka%20OR%20babashka)%20since%3A2023-03-01%20until%3A2023-04-01&src=typed_query&f=top), [Mastodon](https://mastodon.social/tags/babashka))
### Releases
1.3.176, 1.3.175, 1.2.174:
Biggest highlight: Switch to GraalVM 19 and enable virtual threads!
### Videos
- [Blambda! The sound of babashka and AWS colliding](https://pitch.com/public/03fa9c7e-2b0e-45fb-8a22-d4a4d4d79d24), by Josh Glover from Pitch!
### Projects
- [babashka.json](https://github.com/babashka/json): JSON abstraction library
- [martian](https://github.com/oliyh/martian) is now babashka compatible!
- [panas.reload](https://github.com/keychera/panas.reload): a hot reload for babashka serving html+css (or htmx)
- [cljs-exif-reader](https://git.sr.ht/~rwv/cljs-exif-reader): Extract information from TIFF and JPEG images (works in babashka, despite the name)
### Jobs
- Write babashka at [Cognician](https://twitter.com/RobStuttaford/status/1641694501793038336)!
## 2023-02 ([Twitter](https://twitter.com/search?q=(%23babashka%20OR%20babashka)%20since%3A2023-02-01%20until%3A2023-03-01&src=typed_query&f=live), [Mastodon](https://mastodon.social/tags/babashka))
## Releases
1.1.173: mostly bugfixes
### Articles
- [A technique for live coding simple web pages](https://github.com/whacked/cow/blob/main/a%20technique%20for%20live%20coding%20simple%20web%20pages.md) with babashka
### Videos
- [Stockholm Clojure Meetup Feb 23: Blambda! The sound of Babashka and Lambda colliding](https://www.youtube.com/watch?v=NfgYon96dsE)
### Projects
- [debux](https://github.com/philoskim/debux) is now babaskha-compatible
- [lines-of-code-bb](https://github.com/matthewdowney/linesofcode-bb): Babashka script to count lines of Clojure code, docs, comments, and more
- [deps-try](https://github.com/eval/deps-try): a babashka-script to try out Clojure libraries in rebel-readline
- [bb-dialog](https://github.com/pixelated-noise/bb-dialog) adds support for `--treeview`
- [A duckduck go CLI with babashka and (bbl)gum](https://mastodon.me.uk/@choffee/109845697304457129)
- [babashka http-client](https://github.com/babashka/http-client) now supports multipart uploads
- [sublime-pretty-edn](https://github.com/oakmac/sublime-pretty-edn): Format, Validate, Minify EDN files in Sublime Text
- [Play console tetris in babashka!](https://twitter.com/borkdude/status/1628473136969576449)
- [kaocha test runner](https://github.com/lambdaisland/kaocha) became babashka compatible!
## 2023-01 ([Twitter](https://twitter.com/search?q=%28%23babashka%20OR%20babashka%29%20until%3A2023-02-01%20since%3A2023-01-01&src=typed_query&f=live), [Mastodon](https://mastodon.social/tags/babashka))
### Releases

View file

@ -0,0 +1,33 @@
# User Middleware
- Your middleware is defined in bb user sources.
- Middleware is a function in wrap-middleware style.
# Example
Middleware should be a function in the form of:
```clojure
(defn my-middleware [handler]
(fn [request]
;; ...
(handler request)
;; ...
))
```
# Usage
```shell
bb nrepl-server --middleware [my.middleware/println-middleware]
```
--middleware is a vector of fully qualified function symbols.
They are required to be located on the babashka classpath.
This will start babashka with a nrepl server with the middlware defined in `user_middleware/my_middleware/src/my/middleware.clj`.
You can now connect to the nrepl like usual.
It is possible to redefine the middleware function from within the running nrepl, because we keep a reference
to the sci-var of the middlware.

View file

@ -0,0 +1 @@
{:paths ["src"]}

View file

@ -0,0 +1,6 @@
(ns my.middleware)
(defn println-middleware [handler]
(fn [request]
(println (:op (:msg request)))
(handler request)))

View file

@ -0,0 +1,2 @@
{:deps
{my/middleware {:local/root "../my_middleware/"}}}

View file

@ -0,0 +1 @@
(ns hello-middleware)

@ -1 +1 @@
Subproject commit 63bef86c76098366531ab973a79d04c51ae0856b
Subproject commit dadcff417675c84dcd32448e22e6270d1555af5d

View file

@ -22,7 +22,7 @@
:flaky :flaky}
:jvm-opts ["--enable-preview"]
:dependencies [[org.clojure/clojure "1.11.1"]
[borkdude/edamame "1.3.20"]
[borkdude/edamame "1.3.22"]
[borkdude/graal.locking "0.0.2"]
[org.clojure/tools.cli "1.0.214"]
[cheshire "5.11.0"]
@ -35,14 +35,14 @@
[com.github.clj-easy/graal-build-time "0.1.0"]
[rewrite-clj/rewrite-clj "1.1.46"]
[insn/insn "0.5.2"]
[org.babashka/cli "0.6.50"]
[org.babashka/http-client "0.1.8"]]
[org.babashka/cli "0.7.51"]
[org.babashka/http-client "0.2.9"]]
:plugins [[org.kipz/lein-meta-bom "0.1.1"]]
:metabom {:jar-name "metabom.jar"}
:profiles {:feature/xml {:source-paths ["feature-xml"]
:dependencies [[org.clojure/data.xml "0.2.0-alpha8"]]}
:feature/yaml {:source-paths ["feature-yaml"]
:dependencies [[clj-commons/clj-yaml "0.7.169"
:dependencies [[clj-commons/clj-yaml "1.0.26"
:exclusions [org.flatland/ordered]#_#_clj-commons/clj-yaml "0.7.110"]
;; 1.15.10 cause native image bloat problem
[org.flatland/ordered "1.5.9"]]}

View file

@ -31,8 +31,8 @@
org.clojure/data.csv {:mvn/version "1.0.0"},
cheshire/cheshire {:mvn/version "5.11.0"}
org.clojure/data.xml {:mvn/version "0.2.0-alpha8"}
clj-commons/clj-yaml {:mvn/version "0.7.169"}
com.cognitect/transit-clj {:mvn/version "1.0.329"}
clj-commons/clj-yaml {:mvn/version "1.0.26"}
com.cognitect/transit-clj {:mvn/version "1.0.333"}
org.clojure/test.check {:mvn/version "1.1.1"}
nrepl/bencode {:mvn/version "1.1.0"}
seancorfield/next.jdbc {:mvn/version "1.1.610"}

2
sci

@ -1 +1 @@
Subproject commit ae1679ceee89acb00d05744355f501ffaa3cbddb
Subproject commit 987910fb38fdd166865458c3fd4b468a22fb9992

View file

@ -43,6 +43,7 @@ args=("-jar" "$BABASHKA_JAR"
"--verbose"
"--no-fallback"
"--native-image-info"
"--install-exit-handlers"
# --trace-class-initialization=jdk.internal.net.http.common.DebugLogger,jdk.internal.net.http.websocket.WebSocketImpl,jdk.internal.net.http.common.Utils
"$BABASHKA_XMX"
"--enable-preview")

View file

@ -30,6 +30,7 @@ call %GRAALVM_HOME%\bin\native-image.cmd ^
"--verbose" ^
"--no-fallback" ^
"--enable-preview" ^
"--install-exit-handlers" ^
"%BABASHKA_XMX%"
if %errorlevel% neq 0 exit /b %errorlevel%

View file

@ -210,6 +210,7 @@
java.net.http.WebSocket$Builder
java.net.http.WebSocket$Listener
java.security.cert.X509Certificate
java.security.cert.CertificateFactory
javax.crypto.Cipher
javax.crypto.Mac
javax.crypto.SecretKey
@ -317,7 +318,7 @@
java.lang.System
java.lang.Throwable
java.lang.Thread$UncaughtExceptionHandler
;; java.lang.UnsupportedOperationException
java.lang.UnsupportedOperationException
java.lang.ref.WeakReference
java.lang.ref.ReferenceQueue
java.lang.ref.Cleaner
@ -696,6 +697,8 @@
javax.crypto.SecretKey
(instance? java.lang.Thread v)
java.lang.Thread
(instance? java.security.cert.X509Certificate v)
java.security.cert.X509Certificate
;; keep commas for merge friendliness
,,,)))
m (assoc m (list 'quote 'clojure.lang.Var) 'sci.lang.Var)
@ -764,7 +767,7 @@
Throwable java.lang.Throwable
VirtualMachineError java.lang.VirtualMachineError
ThreadDeath java.lang.ThreadDeath
;; UnsupportedOperationException java.lang.UnsupportedOperationException
UnsupportedOperationException java.lang.UnsupportedOperationException
})
(defn reflection-file-entries []

View file

@ -313,8 +313,11 @@ Use bb run --help to show this help output.
(defn start-socket-repl! [address ctx]
(socket-repl/start-repl! address ctx))
(defn start-nrepl! [address]
(let [opts (nrepl-server/parse-opt address)]
(defn start-nrepl! [user-middleware address]
(let [user-middleware (when-not (str/blank? user-middleware)
(read-string user-middleware))
opts (nrepl-server/parse-opt address)
opts (assoc opts :middleware user-middleware)]
(babashka.impl.nrepl-server/start-server! opts))
(binding [*out* *err*]
(println "For more info visit: https://book.babashka.org/#_nrepl"))
@ -645,6 +648,11 @@ Use bb run --help to show this help output.
(recur options
(assoc opts-map
:nrepl (or opt "1667"))))
("--middleware")
(let [options (next options)]
(recur (next options)
(assoc opts-map
:middleware (first options))))
("--eval", "-e")
(let [options (next options)
opts-map (assoc opts-map :prn true)]
@ -839,7 +847,7 @@ Use bb run --help to show this help output.
:main :uberscript :describe?
:jar :uberjar :clojure
:doc :run :list-tasks
:print-deps :prepare]
:print-deps :prepare :middleware]
exec-fn :exec}
cli-opts
print-result? (:prn cli-opts)
@ -1018,7 +1026,7 @@ Use bb run --help to show this help output.
describe?
[(print-describe) 0]
repl [(repl/start-repl! sci-ctx) 0]
nrepl [(start-nrepl! nrepl) 0]
nrepl [(start-nrepl! middleware nrepl) 0]
uberjar [nil 0]
list-tasks [(tasks/list-tasks sci-ctx) 0]
print-deps [(print-deps/print-deps (:print-deps-format cli-opts)) 0]

View file

@ -0,0 +1,34 @@
-----BEGIN CERTIFICATE-----
MIIF0zCCBLugAwIBAgIQByqysLNGGzf4RXfWDxaxzTANBgkqhkiG9w0BAQsFADA8
MQswCQYDVQQGEwJVUzEPMA0GA1UEChMGQW1hem9uMRwwGgYDVQQDExNBbWF6b24g
UlNBIDIwNDggTTAyMB4XDTIzMDIyMTAwMDAwMFoXDTIzMTAxNDIzNTk1OVowFjEU
MBIGA1UEAxMLY2xvanVyZS5vcmcwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEK
AoIBAQC6JGRt221bAElnBPzSVOebsjPofEDQdLTfAr52LCQLCo/4x7cHsPTi9x4+
W3Pl7Fq0yrgimBhJHT34z7UeFqHEMnjsGxt7dLY0XJ87iikd8pz+v9xqXW8rrGaT
ykGx/85JFOGHJy+ZCparNYgUYN68IkaLe1QLb5w0GBcQa1U9JwpLqQVajrPDgD9Z
YRBJqgaFzJuRVsXo28rxHHFdNlP6PF2scMSFrAZEaex0bLXDxw/bHChzjypPODuO
ElsqxqI48Gsotqxe+iyP+Tu3B4GCHv2NKEFBYKiE+9UmNqQfXdVFvZFT+V2r4R9B
SMv3hpDNjmDcgpCVxmCI1sUttfQvAgMBAAGjggL1MIIC8TAfBgNVHSMEGDAWgBTA
MVLNWlDDgnx0cc7L6Zz5euuC4jAdBgNVHQ4EFgQUqkWGgRcK24T3gV3nNWwZ1EwQ
MPUwJwYDVR0RBCAwHoILY2xvanVyZS5vcmeCD3d3dy5jbG9qdXJlLm9yZzAOBgNV
HQ8BAf8EBAMCBaAwHQYDVR0lBBYwFAYIKwYBBQUHAwEGCCsGAQUFBwMCMDsGA1Ud
HwQ0MDIwMKAuoCyGKmh0dHA6Ly9jcmwucjJtMDIuYW1hem9udHJ1c3QuY29tL3Iy
bTAyLmNybDATBgNVHSAEDDAKMAgGBmeBDAECATB1BggrBgEFBQcBAQRpMGcwLQYI
KwYBBQUHMAGGIWh0dHA6Ly9vY3NwLnIybTAyLmFtYXpvbnRydXN0LmNvbTA2Bggr
BgEFBQcwAoYqaHR0cDovL2NydC5yMm0wMi5hbWF6b250cnVzdC5jb20vcjJtMDIu
Y2VyMAwGA1UdEwEB/wQCMAAwggF+BgorBgEEAdZ5AgQCBIIBbgSCAWoBaAB1AOg+
0No+9QY1MudXKLyJa8kD08vREWvs62nhd31tBr1uAAABhnTETgYAAAQDAEYwRAIg
IqyTlcuIQp6edqePX8mbZL42EgXfdTuFcBsoFdK9R5UCIEfKD8zISR0q08R2Zk6J
xnHAwBNsMXbebXu0ez3CjeDDAHcAs3N3B+GEUPhjhtYFqdwRCUp5LbFnDAuH3PAD
Dnk2pZoAAAGGdMROQQAABAMASDBGAiEAhVldSvw96LP/Qb48ZnHC0LqtsV77t/zd
7BCUNJY5bsACIQCENQ19xq5Yu7fWEB+qQQhjHlHD5yrocxqbdmMvdx9uggB2ALc+
+yTfnE26dfI5xbpY9Gxd/ELPep81xJ4dCYEl7bSZAAABhnTETg4AAAQDAEcwRQIh
APsLYOmzOz3qoDCqBULup/twLLmLLu5pK7R/zP1lyPP4AiBZ7PQzi4K2pD8Rfcv1
6Xm1oQwud8jmp1uQbnTCKHUPLjANBgkqhkiG9w0BAQsFAAOCAQEAdACtcuC2kFe0
sQU1m6nnjXdXpds25Xa+Rfbls2vyTqrmatFhSleOhzbkTOnWv/tNunHikttp3+DR
YOAbhJoUe4RVfuu1cQzL3kdc1q4MEmGgEl6V+jDO8657Ck1ld1ViGnqxKtncbV8b
k7hUOurO2saQhlzgylKyFL02Re+kXgw4x/U1n20MvvzHU6QCpU6KcAUeQfub3orQ
gEjmMxjOsnI38ZY8NX7guwhRiyFex3NOZ3avZxG6p8S5amXj8H6M8RBeQ07FVO3H
wj/WczPsGo6D8RG0nU4MiGCerMiY1oF9navINFTZptWiy/gVhR85XwQrKu+Pt+AM
47JAFeruig==
-----END CERTIFICATE-----

View file

@ -15,30 +15,31 @@
(set! *warn-on-reflection* true)
(defn socket-command [expr expected & [log?]]
(with-open [socket (java.net.Socket. "127.0.0.1" 1666)
reader (io/reader socket)
sw (java.io.StringWriter.)
writer (io/writer socket)]
(binding [*out* writer]
(println (str expr "\n")))
(loop []
(when-let [l (try (.readLine ^java.io.BufferedReader reader)
(catch java.net.SocketException _ nil))]
(when log?
(println "===" l))
(binding [*out* sw]
(println l))
(let [s (str sw)]
;; (prn :s s :expected expected (str/includes? s expected))
(if (if (fn? expected)
(expected s)
(str/includes? s expected))
(is true)
(recur)))))
(binding [*out* writer]
(println ":repl/quit\n"))
:success))
(defn socket-command-on-port [^long port]
(fn [expr expected & [log?]]
(with-open [socket (java.net.Socket. "127.0.0.1" port)
reader (io/reader socket)
sw (java.io.StringWriter.)
writer (io/writer socket)]
(binding [*out* writer]
(println (str expr "\n")))
(loop []
(when-let [l (try (.readLine ^java.io.BufferedReader reader)
(catch java.net.SocketException _ nil))]
(when log?
(println "===" l))
(binding [*out* sw]
(println l))
(let [s (str sw)]
;; (prn :s s :expected expected (str/includes? s expected))
(if (if (fn? expected)
(expected s)
(str/includes? s expected))
(is true)
(recur)))))
(binding [*out* writer]
(println ":repl/quit\n"))
:success)))
(def server-process (volatile! nil))
@ -46,87 +47,90 @@
(deftest ^:flaky socket-repl-test
(when exec?
(try
(if tu/jvm?
(let [ctx (init {:namespaces main/namespaces
:features #{:bb}})]
(ctx-store/reset-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")))
(testing "set dyn vars"
(is (socket-command "[(set! *warn-on-reflection* true) (set! *unchecked-math* true)]" "[true true]")))
(finally
(let [socket-command (socket-command-on-port 1666)]
(try
(if tu/jvm?
(do (stop-repl!)
(ctx-store/reset-ctx! nil)
(Thread/sleep 100))
(p/destroy-tree @server-process))))))
(let [ctx (init {:namespaces main/namespaces
:features #{:bb}})]
(ctx-store/reset-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")))
(testing "set dyn vars"
(is (socket-command "[(set! *warn-on-reflection* true) (set! *unchecked-math* true)]" "[true true]")))
(finally
(if tu/jvm?
(do (stop-repl!)
(ctx-store/reset-ctx! nil)
(Thread/sleep 100))
(p/destroy-tree @server-process)))))))
(deftest ^:flaky socket-repl-opts-test
(when exec?
(try
(if tu/jvm?
(let [ctx (init {:bindings {'*command-line-args*
["a" "b" "c"]}
:env (atom {})
:namespaces {'clojure.core.server clojure-core-server-namespace}
:features #{:bb}})]
(ctx-store/reset-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!)
(ctx-store/reset-ctx! nil)
(Thread/sleep 100))
(p/destroy-tree @server-process))))))
(let [socket-command (socket-command-on-port 1667)]
(try
(if tu/jvm?
(let [ctx (init {:bindings {'*command-line-args*
["a" "b" "c"]}
:env (atom {})
:namespaces {'clojure.core.server clojure-core-server-namespace}
:features #{:bb}})]
(ctx-store/reset-ctx! ctx)
(start-repl! "{:address \"localhost\" :accept clojure.core.server/repl :port 1667}"
ctx))
(do (vreset! server-process
(p/process ["./bb" "--socket-repl" "{:address \"localhost\" :accept clojure.core.server/repl :port 1667}"]))
(w/wait-for-port "localhost" 1667)))
(Thread/sleep 50)
(is (socket-command "(+ 1 2 3)" "user=> 6"))
(finally
(if tu/jvm?
(do (stop-repl!)
(ctx-store/reset-ctx! nil)
(Thread/sleep 100))
(p/destroy-tree @server-process)))))))
(deftest ^:flaky socket-prepl-test
(when exec?
(try
(if tu/jvm?
(let [ctx (init {:bindings {'*command-line-args*
["a" "b" "c"]}
:env (atom {})
:namespaces {'clojure.core.server clojure-core-server-namespace}
:features #{:bb}})]
(ctx-store/reset-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!)
(ctx-store/reset-ctx! nil)
(Thread/sleep 100))
(p/destroy-tree @server-process))))))
(let [socket-command (socket-command-on-port 1668)]
(try
(if tu/jvm?
(let [ctx (init {:bindings {'*command-line-args*
["a" "b" "c"]}
:env (atom {})
:namespaces {'clojure.core.server clojure-core-server-namespace}
:features #{:bb}})]
(ctx-store/reset-ctx! ctx)
(start-repl! "{:address \"localhost\" :accept clojure.core.server/io-prepl :port 1668}"
ctx))
(do (vreset! server-process
(p/process ["./bb" "--socket-repl" "{:address \"localhost\" :accept clojure.core.server/io-prepl :port 1668}"]))
(w/wait-for-port "localhost" 1668)))
(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!)
(ctx-store/reset-ctx! nil)
(Thread/sleep 100))
(p/destroy-tree @server-process)))))))
;;;; Scratch
@ -141,5 +145,5 @@
'*command-line-args*
["a" "b" "c"]}
:env (atom {})})
(socket-command "(+ 1 2 3)" "6")
((socket-command-on-port 1666) "(+ 1 2 3)" "6")
)

View file

@ -27,3 +27,17 @@
(is (true? (bb nil "(= (first {1 2})
(clojure.lang.MapEntry. 1 2)
(clojure.lang.MapEntry/create 1 2))"))))
(deftest X509Certificate-test
(is (true? (bb nil "(import java.security.cert.X509Certificate)
(import java.security.cert.CertificateFactory)
(require '[clojure.java.io :as io])
(defn x509-certificate
^X509Certificate
[f]
(let [input (io/input-stream f)
factory (CertificateFactory/getInstance \"X.509\")]
(.generateCertificate factory input)))
(def cert (x509-certificate (io/file \"test-resources/certificate.crt\")))
(some? (.getSubjectX500Principal cert))
"))))

View file

@ -25,6 +25,8 @@
(deftest parse-opts-test
(is (= "1667"
(:nrepl (parse-opts ["--nrepl-server"]))))
(is (= "[foo]"
(:middleware (parse-opts ["--middleware" "[foo]"]))))
(is (= "1666"
(:socket-repl (parse-opts ["--socket-repl"]))))
(is (= {:nrepl "1667", :classpath "src"}