Skip to content

Instantly share code, notes, and snippets.

@djtango
Created August 27, 2019 17:11
Show Gist options
  • Save djtango/f5b81183d269eaf5eaa73122796cc061 to your computer and use it in GitHub Desktop.
Save djtango/f5b81183d269eaf5eaa73122796cc061 to your computer and use it in GitHub Desktop.
Clojure Socket Repl + clojure.test exception
(ns socket-test.core)
(defn foo
"I don't do a whole lot."
[x]
(println x "Hello, World!"))
(ns socket-test.core-test
(:require [clojure.test :refer :all]
[socket-test.core :refer :all]))
(deftest a-test
(testing "FIXME, I fail."
(is (= 0 1))))
(comment
(do ;; pipe this to socket repl with (ns socket-test.core-test) prepended
(require 'socket-test.core-test :reload)
(run-tests)
)
)
(defproject socket-test "0.1.0-SNAPSHOT"
:dependencies [[org.clojure/clojure "1.10.0"]])
@djtango
Copy link
Author

djtango commented Aug 27, 2019

Pipe code to nc:

$ nc localhost 50505 << EOF                                                                                    
heredoc> (ns socket-test.core-test) (do (require 'socket-test.core-test :reload) (run-tests))
heredoc> EOF
user=> nil

Testing socket-test.core-test

FAIL in (a-test) (core_test.clj:7)
FIXME, I fail.
expected: (= 0 1)
  actual: (not (= 0 1))

Ran 1 tests containing 1 assertions.
1 failures, 0 errors.
{:test 1, :pass 0, :fail 1, :error 0, :type :summary}
socket-test.core-test=> %
$ nc localhost 50505 << EOF
(ns socket-test.core-test) (do (require 'socket-test.core-test :reload) (run-tests))
EOF
user=> nil
Execution error (SocketException) at java.net.SocketOutputStream/socketWrite (SocketOutputStream.java:118).
Socket closed
socket-test.core-test=> %

@djtango
Copy link
Author

djtango commented Aug 27, 2019

Stacktrace:

;; user=> java.net.SocketException: Socket closed
;;         at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:118)
;;         at java.net.SocketOutputStream.write(SocketOutputStream.java:155)
;;         at sun.nio.cs.StreamEncoder.writeBytes(StreamEncoder.java:221)
;;         at sun.nio.cs.StreamEncoder.implFlushBuffer(StreamEncoder.java:291)
;;         at sun.nio.cs.StreamEncoder.implFlush(StreamEncoder.java:295)
;;         at sun.nio.cs.StreamEncoder.flush(StreamEncoder.java:141)
;;         at java.io.OutputStreamWriter.flush(OutputStreamWriter.java:229)
;;         at java.io.BufferedWriter.flush(BufferedWriter.java:254)
;;         at clojure.core$flush.invokeStatic(core.clj:3711)
;;         at clojure.core$prn.invokeStatic(core.clj:3721)
;;         at clojure.core$prn.doInvoke(core.clj:3714)
;;         at clojure.lang.RestFn.applyTo(RestFn.java:137)
;;         at clojure.core$apply.invokeStatic(core.clj:665)
;;         at clojure.core$println.invokeStatic(core.clj:3733)
;;         at clojure.test$fn__9635.invokeStatic(test.clj:405)
;;         at clojure.test$fn__9635.invoke(test.clj:403)
;;         at clojure.lang.MultiFn.invoke(MultiFn.java:229)
;;         at clojure.test$do_report.invokeStatic(test.clj:357)
;;         at clojure.test$test_ns.invokeStatic(test.clj:743)
;;         at clojure.test$test_ns.invoke(test.clj:743)
;;         at clojure.core$map$fn__5851.invoke(core.clj:2755)
;;         at clojure.lang.LazySeq.sval(LazySeq.java:42)
;;         at clojure.lang.LazySeq.seq(LazySeq.java:51)
;;         at clojure.lang.Cons.next(Cons.java:39)
;;         at clojure.lang.RT.boundedLength(RT.java:1788)
;;         at clojure.lang.RestFn.applyTo(RestFn.java:130)
;;         at clojure.core$apply.invokeStatic(core.clj:667)
;;         at clojure.test$run_tests.invokeStatic(test.clj:768)
;;         at clojure.test$run_tests.doInvoke(test.clj:768)
;;         at clojure.lang.RestFn.invoke(RestFn.java:408)
;;         at clojure.test$run_tests.invokeStatic(test.clj:773)
;;         at clojure.test$run_tests.invoke(test.clj:768)
;;         at socket_test.core_test$eval5938.invokeStatic(NO_SOURCE_FILE:5)
;;         at socket_test.core_test$eval5938.invoke(NO_SOURCE_FILE:3)
;;         at clojure.lang.Compiler.eval(Compiler.java:7176)
;;         at clojure.lang.Compiler.eval(Compiler.java:7166)
;;         at clojure.lang.Compiler.eval(Compiler.java:7131)
;;         at clojure.core$eval.invokeStatic(core.clj:3214)
;;         at clojure.core$eval.invoke(core.clj:3210)
;;         at clojure.main$repl$read_eval_print__9068$fn__9071.invoke(main.clj:414)
;;         at clojure.main$repl$read_eval_print__9068.invoke(main.clj:414)
;;         at clojure.main$repl$fn__9077.invoke(main.clj:435)
;;         at clojure.main$repl.invokeStatic(main.clj:435)
;;         at clojure.core.server$repl.invokeStatic(server.clj:180)
;;         at clojure.core.server$repl.invoke(server.clj:180)
;;         at clojure.lang.AFn.applyToHelper(AFn.java:152)
;;         at clojure.lang.AFn.applyTo(AFn.java:144)
;;         at clojure.lang.Var.applyTo(Var.java:705)
;;         at clojure.core$apply.invokeStatic(core.clj:665)
;;         at clojure.core.server$accept_connection.invokeStatic(server.clj:73)
;;         at clojure.core.server$start_server$fn__8864$fn__8865$fn__8867.invoke(server.clj:117)
;;         at clojure.lang.AFn.run(AFn.java:22)
;;         at java.lang.Thread.run(Thread.java:748)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment