1
- ; ; nrepl-server-mock.el -*- lexical-binding : t ; -*-
1
+ ; ; nrepl-server-mock.el --- Mock nREPL server -*- lexical-binding : t ; -*-
2
2
3
3
; ; Copyright © 2021-2025 Ioannis Kappas
4
4
24
24
; ; A mock nREPL server that sends dummy replies back to clients with just enough
25
25
; ; information onboard to accommodate testing requirements.
26
26
; ;
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.
28
28
29
29
; ;; Code:
30
30
34
34
(require 'cl )
35
35
36
36
(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
39
39
requirements."
40
40
; ; (mock/log! ":mock.filter/output %s :msg %s" proc output)
41
41
@@ -47,21 +47,21 @@ requirements."
47
47
`(dict " id" , id
48
48
" session" " a-session"
49
49
" status" (" done" )
50
- " new-session" " a-new-session" ))
50
+ " new-session" " a-new-session" ))
51
51
52
52
(`(dict " op" " describe" " session" , session " id" , id )
53
53
`(dict " id" , id " session" , session " status"
54
- (" done" )))
54
+ (" done" )))
55
55
; ; Eval op can include other fields in addition to the
56
56
; ; code, we only need the signature and the session and
57
57
; ; id fields at the end.
58
58
(`(dict " op" " eval" " code" , _code . , rest )
59
59
(cl-destructuring-bind (_ session _ id) (seq-drop rest (- (seq-length rest) 4 ))
60
60
`(dict " id" , id " session" , session " status"
61
- (" done" ))))
61
+ (" done" ))))
62
62
(`(dict " op" " close" " session" , session " id" , id )
63
63
`(dict " id" , id " session" , session " status"
64
- (" done" ))))))
64
+ (" done" ))))))
65
65
66
66
(mock/log! " :mock.filter/msg :out %S" response)
67
67
(if (not response)
@@ -82,25 +82,26 @@ requirements."
82
82
))
83
83
84
84
(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"
87
88
88
89
; ; change first argument to non-nil to enable logging to file
89
90
(nrepl-tests-log/init! nil mock " ./nrepl-server-mock.log" 'new )
90
91
(mock/log! " :mock/starting..." )
91
92
92
93
(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
96
97
; ; 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 ))
104
105
(mock-message (format " nREPL server started on port %d on host %s "
105
106
(plist-get contact :service )
106
107
(plist-get contact :host ))))
@@ -115,3 +116,5 @@ the port and host it is started on. Exits after a 10 secs"
115
116
(make-string (- 4096 (length mock-message)) ?* )))
116
117
(sleep-for 10 )
117
118
(mock/log! " :mock/exiting..." )))
119
+
120
+ ; ;; nrepl-server-mock.el ends here
0 commit comments