1- ; ; nrepl-server-mock.el -*- lexical-binding : t ; -*-
1+ ; ; nrepl-server-mock.el --- Mock nREPL server -*- lexical-binding : t ; -*-
22
33; ; Copyright © 2021-2025 Ioannis Kappas
44
2424; ; A mock nREPL server that sends dummy replies back to clients with just enough
2525; ; information onboard to accommodate testing requirements.
2626; ;
27- ; ; Meant to be invoked as the top-level fn of an emacs subprocess.
27+ ; ; Meant to be invoked as the top-level fn of an Emacs subprocess.
2828
2929; ;; Code:
3030
3434(require 'cl )
3535
3636(defun nrepl-server-mock-filter (proc output )
37- " Handle the nREPL message found in OUTPUT sent by the client
38- PROC. Minimal implementation, just enough for fulfilling clients' testing
37+ " Handle the nREPL message found in OUTPUT sent by the client PROC.
38+ Minimal implementation, just enough for fulfilling clients' testing
3939requirements."
4040 ; ; (mock/log! ":mock.filter/output %s :msg %s" proc output)
4141
@@ -47,21 +47,21 @@ requirements."
4747 `(dict " id" , id
4848 " session" " a-session"
4949 " status" (" done" )
50- " new-session" " a-new-session" ))
50+ " new-session" " a-new-session" ))
5151
5252 (`(dict " op" " describe" " session" , session " id" , id )
5353 `(dict " id" , id " session" , session " status"
54- (" done" )))
54+ (" done" )))
5555 ; ; Eval op can include other fields in addition to the
5656 ; ; code, we only need the signature and the session and
5757 ; ; id fields at the end.
5858 (`(dict " op" " eval" " code" , _code . , rest )
5959 (cl-destructuring-bind (_ session _ id) (seq-drop rest (- (seq-length rest) 4 ))
6060 `(dict " id" , id " session" , session " status"
61- (" done" ))))
61+ (" done" ))))
6262 (`(dict " op" " close" " session" , session " id" , id )
6363 `(dict " id" , id " session" , session " status"
64- (" done" ))))))
64+ (" done" ))))))
6565
6666 (mock/log! " :mock.filter/msg :out %S" response)
6767 (if (not response)
@@ -82,25 +82,26 @@ requirements."
8282 ))
8383
8484(defun nrepl-server-mock-start ()
85- " Start a mock nREPL server process. Prints out nREPL welcome message of
86- the port and host it is started on. Exits after a 10 secs"
85+ " Start a mock nREPL server process.
86+ Prints out nREPL welcome message of the port and host it is started
87+ on. Exits after a 10 secs"
8788
8889 ; ; change first argument to non-nil to enable logging to file
8990 (nrepl-tests-log/init! nil mock " ./nrepl-server-mock.log" 'new )
9091 (mock/log! " :mock/starting..." )
9192
9293 (let* ((server-process (make-network-process
93- :name " server-mock/process"
94- :server 't
95- :host 'local
94+ :name " server-mock/process"
95+ :server 't
96+ :host 'local
9697 ; ; listen to an unoccupied port
97- :service 't
98- :buffer " server-mock/buffer"
99- :filter #'nrepl-server-mock-filter
100- :sentinel
101- (lambda (_proc status-change-descr )
102- (mock/log! " :mock/process-status %s" status-change-descr))))
103- (contact (process-contact server-process 't ))
98+ :service 't
99+ :buffer " server-mock/buffer"
100+ :filter #'nrepl-server-mock-filter
101+ :sentinel
102+ (lambda (_proc status-change-descr )
103+ (mock/log! " :mock/process-status %s" status-change-descr))))
104+ (contact (process-contact server-process 't ))
104105 (mock-message (format " nREPL server started on port %d on host %s "
105106 (plist-get contact :service )
106107 (plist-get contact :host ))))
@@ -115,3 +116,5 @@ the port and host it is started on. Exits after a 10 secs"
115116 (make-string (- 4096 (length mock-message)) ?* )))
116117 (sleep-for 10 )
117118 (mock/log! " :mock/exiting..." )))
119+
120+ ; ;; nrepl-server-mock.el ends here
0 commit comments