29
29
(require 'cider )
30
30
(require 'nrepl-dict )
31
31
(require 'nrepl-tests-utils " test/utils/nrepl-tests-utils" )
32
-
33
- ; ; https://emacs.stackexchange.com/a/55031
34
- (defmacro with-temp-dir (temp-dir &rest body )
35
- " Create a temporary directory and bind it to TEMP-DIR while evaluating BODY.
36
- Remove the temp directory at the end of evaluation."
37
- `(let ((, temp-dir (make-temp-file " " t )))
38
- (unwind-protect
39
- (progn
40
- ,@body )
41
- (condition-case err
42
- (delete-directory , temp-dir t )
43
- (error
44
- (message " :with-temp-dir-error :cannot-remove-temp-dir %S " err))))))
45
-
46
- (defun nrepl-client-connected?-ref-make! ()
47
- " Return a reference to indicate when the client is connected to nREPL server.
48
- This is done by adding a hook to `cider-connected-hook` and is only active
49
- in the scope of the current buffer."
50
- (let (connected?)
51
- (add-hook 'cider-connected-hook
52
- (lambda ()
53
- (setq connected? t ))
54
- nil
55
- ; ; only set in the current buffer scope.
56
- t )))
57
-
32
+ (require 'integration-test-utils )
58
33
59
34
(describe " jack in"
60
- ; ; See "bb" case for basic commentary
35
+ ; ; See "babashka" case for commentary on the base template used by all other
36
+ ; ; tests.
61
37
; ;
62
38
; ; It has been observed that some REPLs (Clojure cli, shadow) might take a
63
39
; ; very long time to bring up/respond/shutdown, and thus sleep duration values
64
40
; ; are set rather high.
65
41
66
42
(it " to babashka"
43
+ (with-cider-test-sandbox
67
44
(with-temp-dir temp-dir
68
45
; ; set up a project directory in temp
69
46
(let* ((project-dir temp-dir)
@@ -75,18 +52,20 @@ in the scope of the current buffer."
75
52
(setq-local default-directory project-dir)
76
53
77
54
(unwind-protect
78
- ; ; jack in and get repl buffer
79
- (let* ((client-connected?* (nrepl-client-connected?- ref-make!))
55
+ (let* (; ; Get a gv reference so as to poll if the client has
56
+ ; ; connected to the nREPL server.
57
+ (client-is-connected* (cider-itu-nrepl-client-connected-ref-make!))
58
+
59
+ ; ; jack in and get repl buffer
80
60
(nrepl-proc (cider-jack-in-clj '()))
81
61
(nrepl-buf (process-buffer nrepl-proc)))
82
62
83
63
; ; wait until the client has successfully connected to the
84
64
; ; nREPL server.
85
- (nrepl-tests-sleep-until 5 client-connected?* )
86
- (expect client-connected?* )
65
+ (cider-itu-poll-until (eq (gv-deref client-is-connected*) 'connected ) 5 )
87
66
88
67
; ; give it some time to setup the clj REPL
89
- (nrepl-tests-sleep -until 5 (cider-repls 'clj nil ))
68
+ (cider-itu-poll -until (cider-repls 'clj nil ) 5 )
90
69
91
70
; ; send command to the REPL, and stdout/stderr to
92
71
; ; corresponding eval- variables.
@@ -107,7 +86,7 @@ in the scope of the current buffer."
107
86
(when out (push out eval-out)))) )
108
87
109
88
; ; wait for the response to come back.
110
- (nrepl-tests-sleep -until 5 eval-out)
89
+ (cider-itu-poll -until eval-out 5 )
111
90
112
91
; ; ensure there are no errors and response is as expected.
113
92
(expect eval-err :to-equal '())
@@ -117,30 +96,29 @@ in the scope of the current buffer."
117
96
(cider-quit repl-buffer)
118
97
119
98
; ; wait for the REPL to exit
120
- (nrepl-tests-sleep -until 5 (not (eq (process-status nrepl-proc) 'run )))
99
+ (cider-itu-poll -until (not (eq (process-status nrepl-proc) 'run )) 5 )
121
100
(expect (member (process-status nrepl-proc) '(exit signal)))))
122
101
123
102
; ; useful for debugging on errors
124
103
(when-let ((nrepl-error-buffer (get-buffer " *nrepl-error*" )))
125
104
(with-current-buffer nrepl-error-buffer
126
- (message " :*nrepl-error* %S " (substring-no-properties (buffer-string ))))))))))
105
+ (message " :*nrepl-error* %S " (substring-no-properties (buffer-string )))))))))))
127
106
128
107
(it " to clojure tools cli"
108
+ (with-cider-test-sandbox
129
109
(with-temp-dir temp-dir
130
110
(let* ((project-dir temp-dir)
131
111
(deps-edn (expand-file-name " deps.edn" project-dir)))
132
112
(write-region " {}" nil deps-edn)
133
113
(with-temp-buffer
134
114
(setq-local default-directory project-dir)
135
115
(unwind-protect
136
- (let* ((client-connected? * (nrepl-client-connected? - ref-make!))
116
+ (let* ((client-is- connected* (cider-itu- nrepl-client-connected-ref-make!))
137
117
(nrepl-proc (cider-jack-in-clj `()))
138
118
(nrepl-buf (process-buffer nrepl-proc)))
139
- (nrepl-tests-sleep-until 5 client-connected?* )
140
- (expect client-connected?* )
141
-
142
119
; ; high duration since on windows it takes a long time to startup
143
- (nrepl-tests-sleep-until 90 (cider-repls 'clj nil ))
120
+ (cider-itu-poll-until (eq (gv-deref client-is-connected*) 'connected ) 90 )
121
+ (cider-itu-poll-until (cider-repls 'clj nil ) 90 )
144
122
(let ((repl-buffer (cider-current-repl))
145
123
(eval-err '())
146
124
(eval-out '()))
@@ -153,17 +131,18 @@ in the scope of the current buffer."
153
131
(out err)
154
132
(when err (push err eval-err))
155
133
(when out (push out eval-out)))) )
156
- (nrepl-tests-sleep -until 10 eval-out)
134
+ (cider-itu-poll -until eval-out 10 )
157
135
(expect eval-err :to-equal '())
158
136
(expect eval-out :to-equal '(" :clojure? true" ))
159
137
(cider-quit repl-buffer)
160
- (nrepl-tests-sleep -until 15 (not (eq (process-status nrepl-proc) 'run )))
138
+ (cider-itu-poll -until (not (eq (process-status nrepl-proc) 'run )) 15 )
161
139
(expect (member (process-status nrepl-proc) '(exit signal)))))
162
140
(when-let ((nrepl-error-buffer (get-buffer " *nrepl-error*" )))
163
141
(with-current-buffer nrepl-error-buffer
164
- (message " :*nrepl-error* %S " (substring-no-properties (buffer-string ))))))))))
142
+ (message " :*nrepl-error* %S " (substring-no-properties (buffer-string )))))))))))
165
143
166
144
(it " to leiningen"
145
+ (with-cider-test-sandbox
167
146
(with-temp-dir temp-dir
168
147
(let* ((project-dir temp-dir)
169
148
(project-clj (expand-file-name " project.clj" project-dir)))
@@ -173,12 +152,11 @@ in the scope of the current buffer."
173
152
(with-temp-buffer
174
153
(setq-local default-directory project-dir)
175
154
(unwind-protect
176
- (let* ((client-connected? * (nrepl-client-connected? - ref-make!))
155
+ (let* ((client-is- connected* (cider-itu- nrepl-client-connected-ref-make!))
177
156
(nrepl-proc (cider-jack-in-clj `()))
178
157
(nrepl-buf (process-buffer nrepl-proc)))
179
- (nrepl-tests-sleep-until 5 client-connected?* )
180
- (expect client-connected?* )
181
- (nrepl-tests-sleep-until 90 (cider-repls 'clj nil ))
158
+ (cider-itu-poll-until (eq (gv-deref client-is-connected*) 'connected ) 90 )
159
+ (cider-itu-poll-until (cider-repls 'clj nil ) 90 )
182
160
(let ((repl-buffer (cider-current-repl))
183
161
(eval-err '())
184
162
(eval-out '()))
@@ -191,68 +169,67 @@ in the scope of the current buffer."
191
169
(out err)
192
170
(when err (push err eval-err))
193
171
(when out (push out eval-out)))) )
194
- (nrepl-tests-sleep -until 10 eval-out)
172
+ (cider-itu-poll -until eval-out 10 )
195
173
(expect eval-err :to-equal '())
196
174
(expect eval-out :to-equal '(" :clojure? true" ))
197
175
(cider-quit repl-buffer)
198
- (nrepl-tests-sleep -until 15 (not (eq (process-status nrepl-proc) 'run )))
176
+ (cider-itu-poll -until (not (eq (process-status nrepl-proc) 'run )) 15 )
199
177
(expect (member (process-status nrepl-proc) '(exit signal)))
200
178
(sleep-for 0.5 )))
201
179
(when-let ((nrepl-error-buffer (get-buffer " *nrepl-error*" )))
202
180
(with-current-buffer nrepl-error-buffer
203
181
(message " :*nrepl-error* %S "
204
- (substring-no-properties (buffer-string ))))))))))
182
+ (substring-no-properties (buffer-string )))))))))))
205
183
206
184
(it " to shadow"
207
185
; ; shadow asks user whether they want to open a browser, force to no
208
186
(spy-on 'y-or-n-p )
209
187
210
- (with-temp-dir temp-dir
211
- (let* ((project-dir temp-dir)
212
- (shadow-cljs-edn (expand-file-name " shadow-cljs.edn" project-dir))
213
- (package-json (expand-file-name " package.json" project-dir)))
214
- (write-region " {}" nil shadow-cljs-edn)
215
- (write-region " {\" dependencies\" :{\" shadow-cljs\" : \" ^2.20.13\" }}" nil package-json)
216
- (let ((default-directory project-dir))
217
- (message " :npm-install... " )
218
- (shell-command " npm install" )
219
- (message " :npm-install :done " ))
220
- (let ((cider-preferred-build-tool 'shadow-cljs )
221
- ; ; request for a node repl, so that shadow forks one.
222
- (cider-shadow-default-options " :node-repl" ))
223
- (with-temp-buffer
224
- (setq-local default-directory project-dir)
225
- (unwind-protect
226
- (let* ((client-connected?* (nrepl-client-connected?- ref-make!))
227
- (nrepl-proc (cider-jack-in-cljs '(:cljs-repl-type shadow )))
228
- (nrepl-buf (process-buffer nrepl-proc)))
229
- (nrepl-tests-sleep-until 5 client-connected?* )
230
- (expect client-connected?* )
231
- (nrepl-tests-sleep-until 120 (cider-repls 'cljs nil ))
232
- (expect (cider-repls 'cljs nil ) :not :to-be nil )
233
- (let ((repl-buffer (cider-current-repl))
234
- (eval-err '())
235
- (eval-out '()))
236
- (expect repl-buffer :not :to-be nil )
237
- (sleep-for 2 )
238
- (cider-interactive-eval
239
- " (print :cljs? (some? *clojurescript-version*))"
240
- (lambda (return )
241
- (nrepl-dbind-response
242
- return
243
- (out err)
244
- (when err (push err eval-err))
245
- (when out (push out eval-out)))) )
246
- (nrepl-tests-sleep-until 10 eval-out)
247
- (expect eval-err :to-equal '())
248
- (expect eval-out :to-equal '(" :cljs? true\n " ))
249
- (cider-quit repl-buffer)
250
- (nrepl-tests-sleep-until 15 (not (eq (process-status nrepl-proc) 'run )))
251
- (expect (member (process-status nrepl-proc) '(exit signal)))))
252
- (when-let ((nrepl-error-buffer (get-buffer " *nrepl-error*" )))
253
- (with-current-buffer nrepl-error-buffer
254
- (message " :*nrepl-error* %S "
255
- (substring-no-properties (buffer-string ))))))))))))
188
+ (with-cider-test-sandbox
189
+ (with-temp-dir temp-dir
190
+ (let* ((project-dir temp-dir)
191
+ (shadow-cljs-edn (expand-file-name " shadow-cljs.edn" project-dir))
192
+ (package-json (expand-file-name " package.json" project-dir)))
193
+ (write-region " {}" nil shadow-cljs-edn)
194
+ (write-region " {\" dependencies\" :{\" shadow-cljs\" : \" ^2.20.13\" }}" nil package-json)
195
+ (let ((default-directory project-dir))
196
+ (message " :npm-install... " )
197
+ (shell-command " npm install" )
198
+ (message " :npm-install :done " ))
199
+ (let ((cider-preferred-build-tool 'shadow-cljs )
200
+ ; ; request for a node repl, so that shadow forks one.
201
+ (cider-shadow-default-options " :node-repl" ))
202
+ (with-temp-buffer
203
+ (setq-local default-directory project-dir)
204
+ (unwind-protect
205
+ (let* ((client-is-connected* (cider-itu-nrepl-client-connected-ref-make!))
206
+ (nrepl-proc (cider-jack-in-cljs '(:cljs-repl-type shadow )))
207
+ (nrepl-buf (process-buffer nrepl-proc)))
208
+ (cider-itu-poll-until (eq (gv-deref client-is-connected*) 'connected ) 120 )
209
+ (cider-itu-poll-until (cider-repls 'cljs nil ) 120 )
210
+ (let ((repl-buffer (cider-current-repl))
211
+ (eval-err '())
212
+ (eval-out '()))
213
+ (expect repl-buffer :not :to-be nil )
214
+ (sleep-for 2 )
215
+ (cider-interactive-eval
216
+ " (print :cljs? (some? *clojurescript-version*))"
217
+ (lambda (return )
218
+ (nrepl-dbind-response
219
+ return
220
+ (out err)
221
+ (when err (push err eval-err))
222
+ (when out (push out eval-out)))) )
223
+ (cider-itu-poll-until eval-out 10 )
224
+ (expect eval-err :to-equal '())
225
+ (expect eval-out :to-equal '(" :cljs? true\n " ))
226
+ (cider-quit repl-buffer)
227
+ (cider-itu-poll-until (not (eq (process-status nrepl-proc) 'run )) 15 )
228
+ (expect (member (process-status nrepl-proc) '(exit signal)))))
229
+ (when-let ((nrepl-error-buffer (get-buffer " *nrepl-error*" )))
230
+ (with-current-buffer nrepl-error-buffer
231
+ (message " :*nrepl-error* %S "
232
+ (substring-no-properties (buffer-string )))))))))))))
256
233
257
234
(provide 'integration-tests )
258
235
0 commit comments