Skip to content

Commit c887773

Browse files
committed
Simplify etest commands and lisp forms
1 parent 553cdfb commit c887773

File tree

9 files changed

+267
-270
lines changed

9 files changed

+267
-270
lines changed

test/ess-test-inf.el

Lines changed: 68 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,12 @@
7474

7575
(etest-deftest ess-command-test ()
7676
"`ess-command' saves output in specified buffer."
77-
:eval (let ((output-buffer (get-buffer-create " *ess-test-command-output*")))
78-
(ess-command "identity(TRUE)\n" output-buffer)
79-
(should (string= (with-current-buffer output-buffer
80-
(ess-kill-last-line)
81-
(buffer-string))
82-
"[1] TRUE")))
77+
(let ((output-buffer (get-buffer-create " *ess-test-command-output*")))
78+
(ess-command "identity(TRUE)\n" output-buffer)
79+
(should (string= (with-current-buffer output-buffer
80+
(ess-kill-last-line)
81+
(buffer-string))
82+
"[1] TRUE")))
8383
;; No impact on inferior output
8484
:inf-result "")
8585

@@ -117,22 +117,22 @@
117117

118118
(etest-deftest ess-command-incomplete-test ()
119119
"`ess-command' fails with incomplete input."
120-
:eval (should-error (ess-command "list(" nil nil nil nil nil nil 0.01))
120+
(should-error (ess-command "list(" nil nil nil nil nil nil 0.01))
121121

122122
;; No impact on inferior output
123123
:inf-result ""
124124

125125
;; Process has been interrupted, is no longer busy, and we can run a
126126
;; command again
127-
:eval ((should (inferior-ess-available-p))
128-
(should-error (ess-command "list(" nil nil nil nil nil nil 0.01)))
127+
(should (inferior-ess-available-p))
128+
(should-error (ess-command "list(" nil nil nil nil nil nil 0.01))
129129
:inf-result "")
130130

131131
(etest-deftest ess-command-hanging-test ()
132132
"`ess-command' fails with hanging command."
133-
:eval (should-error (ess-command "Sys.sleep(2)\n" nil nil nil nil nil nil 0.01))
133+
(should-error (ess-command "Sys.sleep(2)\n" nil nil nil nil nil nil 0.01))
134134
:inf-result ""
135-
:eval (should (inferior-ess-available-p)))
135+
(should (inferior-ess-available-p)))
136136

137137
(defun ess-test--browser ()
138138
(ess-send-string (ess-get-process) "{ browser(); NULL }\n")
@@ -146,103 +146,99 @@
146146
(etest-deftest ess--command-browser-timeout-test ()
147147
"`ess-command' fails with hanging command within browser (#1081)."
148148
:cleanup (ess-test--browser-cleanup)
149-
:eval (ess-test--browser)
149+
(ess-test--browser)
150150
:inf-result "Called from: top level
151151
Browse[1]> debug at #1: NULL
152152
Browse[1]> "
153153

154-
:eval (should-error (ess-command "Sys.sleep(2)\n" nil nil nil nil nil nil 0.01))
154+
(should-error (ess-command "Sys.sleep(2)\n" nil nil nil nil nil nil 0.01))
155155

156156
;; No impact on inferior
157157
:inf-result ""
158-
:eval (should (inferior-ess-available-p))
158+
(should (inferior-ess-available-p))
159159

160160
;; We're still in the browser
161-
:eval (progn
162-
(ess-send-string (ess-get-process) "NULL\n")
163-
(ess-wait-for-process))
161+
(ess-send-string (ess-get-process) "NULL\n")
162+
(ess-wait-for-process)
164163
:inf-result "NULL
165164
Browse[1]> ")
166165

167166
(etest-deftest ess-command-browser-curly-braces ()
168167
"`{` expressions when debugger is active do not interrupt command."
169168
:cleanup (ess-test--browser-cleanup)
170-
:eval (ess-test--browser)
169+
(ess-test--browser)
171170
:inf-result "Called from: top level
172171
Browse[1]> debug at #1: NULL
173172
Browse[1]> "
174173

175-
:eval (should (string= (ess-string-command "{ 1; 2 }\n")
176-
"[1] 2"))
174+
(should (string= (ess-string-command "{ 1; 2 }\n")
175+
"[1] 2"))
177176
:inf-result ""
178-
:eval (should (inferior-ess-available-p)))
177+
(should (inferior-ess-available-p)))
179178

180179
(etest-deftest ess-command-environment ()
181180
"Can access current env with `.ess.environment()`"
182181
:cleanup (ess-test--browser-cleanup)
183-
:eval (progn
184-
(ess-send-string (ess-get-process)
185-
"local({ foo <- 1; browser(); NULL })\n")
186-
(ess-wait-for-process))
187-
:eval (should (string= (ess-string-command "ls(envir = .ess.environment())\n")
188-
"[1] \"foo\"")))
182+
(ess-send-string (ess-get-process)
183+
"local({ foo <- 1; browser(); NULL })\n")
184+
(ess-wait-for-process)
185+
(should (string= (ess-string-command "ls(envir = .ess.environment())\n")
186+
"[1] \"foo\"")))
189187

190188
(etest-deftest ess-command-quit-test ()
191189
"`ess-command' does not leak output on quit (#794, #842).
192190
This is especially important within `while-no-input' used by
193191
packages like eldoc and company-quickhelp. `throw-on-input' sets
194192
`quit-flag'."
195193
;; Simulate a quit by throwing from a timer
196-
:eval ((run-at-time 0.1 nil (lambda () (throw 'my-quit 'thrown)))
197-
(should (eq (catch 'my-quit
198-
(ess-command "{ cat('output\n'); Sys.sleep(10) }\n" nil nil nil nil nil nil 0.5))
199-
'thrown)))
194+
(run-at-time 0.1 nil (lambda () (throw 'my-quit 'thrown)))
195+
(should (eq (catch 'my-quit
196+
(ess-command "{ cat('output\n'); Sys.sleep(10) }\n" nil nil nil nil nil nil 0.5))
197+
'thrown))
200198
;; There should be no output after the early exit
201199
:inf-result ""
202-
:eval (should (inferior-ess-available-p)))
200+
(should (inferior-ess-available-p)))
203201

204202
(etest-deftest ess-command-quit-async-interrupt-test ()
205203
"`ess-command' interrupts asynchronously on quits (#1091, #1102).
206204
Needed with slow-responding processes."
207-
:eval
208-
(progn
209-
(should (eq (identity (marker-buffer (process-mark (ess-get-process))))
210-
(ess-get-process-buffer)))
211-
(run-at-time 0.1 nil (lambda () (throw 'my-quit 'thrown)))
212-
(should (eq (catch 'my-quit
213-
(ess-command "{
205+
(should (eq (identity (marker-buffer (process-mark (ess-get-process))))
206+
(ess-get-process-buffer)))
207+
(run-at-time 0.1 nil (lambda () (throw 'my-quit 'thrown)))
208+
(should (eq (catch 'my-quit
209+
(ess-command "{
214210
cat('output\n')
215211
withCallingHandlers(
216212
interrupt = function(...) Sys.sleep(0.2),
217213
Sys.sleep(10)
218214
)
219215
}
220216
"
221-
nil nil nil nil nil nil 0.5))
222-
'thrown))
223-
;; Wait for the async interrupt
224-
(should (ess-wait-for-process (ess-get-process) nil nil 0.5))
225-
;; Check that marker buffer was properly restored
226-
(should (eq (marker-buffer (process-mark (ess-get-process)))
227-
(ess-get-process-buffer))))
217+
nil nil nil nil nil nil 0.5))
218+
'thrown))
219+
;; Wait for the async interrupt
220+
(should (ess-wait-for-process (ess-get-process) nil nil 0.5))
221+
;; Check that marker buffer was properly restored
222+
(should (eq (marker-buffer (process-mark (ess-get-process)))
223+
(ess-get-process-buffer)))
228224

229225
;; There should be no output after the early exit or async restoration
230226
:inf-result "")
231227

232228
(etest-deftest ess-command-newlines-test ()
233229
"`ess-command' doesn't garble new lines (#1110)."
234-
:eval ((should (string= (ess--strip-final-newlines "1\n2")
235-
"1\n2"))
236-
(should (equal (ess-get-words-from-vector "{ 'foo'\n'bar'\n }\n")
237-
(list "bar")))))
230+
(should (string= (ess--strip-final-newlines "1\n2")
231+
"1\n2"))
232+
(should (equal (ess-get-words-from-vector "{ 'foo'\n'bar'\n }\n")
233+
(list "bar"))))
238234

239235
(etest-deftest ess-command-multiline-test ()
240236
"`ess-command' output doesn't include continuation prompts (#1116)."
241-
:eval ((let ((buf (generate-new-buffer "ess-command-multiline-test")))
242-
(ess-command "{ 1\n 2 }\n" buf)
243-
(should (string= (with-current-buffer buf
244-
(buffer-string))
245-
"[1] 2")))))
237+
(let ((buf (generate-new-buffer "ess-command-multiline-test")))
238+
(ess-command "{ 1\n 2 }\n" buf)
239+
(should (string= (with-current-buffer buf
240+
(buffer-string))
241+
"[1] 2"))))
246242

247243
(ert-deftest ess--command-output-info-test ()
248244
;; No output
@@ -306,34 +302,32 @@ new output")
306302
With delimiters it might be possible to figure out the output.
307303
However if they are not available then the output is
308304
indistinguishable from the prompt."
309-
:eval ((should-error (ess-command "cat(1)\n"))
310-
(ess-wait-for-process))
305+
(should-error (ess-command "cat(1)\n"))
306+
(ess-wait-for-process)
311307
;; Leaks output after the error but that seems fine since errors in
312308
;; filters are bugs
313309
:inf-result "
314310
> ")
315311

316312
(etest-deftest ess-command-intervening-input-test ()
317313
"Test that user can send input while command is interrupting (#1119)."
318-
:eval
319-
(progn
320-
(run-at-time 0.1 nil (lambda () (throw 'my-quit 'thrown)))
321-
(should (eq (catch 'my-quit
322-
(ess-command "{
314+
(run-at-time 0.1 nil (lambda () (throw 'my-quit 'thrown)))
315+
(should (eq (catch 'my-quit
316+
(ess-command "{
323317
cat('output\n')
324318
withCallingHandlers(
325319
interrupt = function(...) Sys.sleep(0.2),
326320
Sys.sleep(10)
327321
)
328322
}
329323
"
330-
nil nil nil nil nil nil 0.5))
331-
'thrown))
332-
;; Send intervening input right away. Since we wait on the R side
333-
;; on interrupt, the process hasn't been restored yet
334-
(ess-send-string (ess-get-process) "cat('foobar\\n')\n")
335-
;; Wait for the async interrupt
336-
(should (ess-wait-for-process nil nil nil 0.5)))
324+
nil nil nil nil nil nil 0.5))
325+
'thrown))
326+
;; Send intervening input right away. Since we wait on the R side
327+
;; on interrupt, the process hasn't been restored yet
328+
(ess-send-string (ess-get-process) "cat('foobar\\n')\n")
329+
;; Wait for the async interrupt
330+
(should (ess-wait-for-process nil nil nil 0.5))
337331
;; The output for the intervening input should be shown in the
338332
;; process buffer
339333
:inf-result "foobar
@@ -528,13 +522,13 @@ some. text
528522
;;*;; Help
529523

530524
(etest-deftest ess-help-aliases-test ()
531-
:eval (let ((aliases (ess-get-help-aliases-list)))
532-
(should (member "list" aliases)))
525+
(let ((aliases (ess-get-help-aliases-list)))
526+
(should (member "list" aliases)))
533527
:inf-result ""
534528

535-
:eval ((ess-help--reset-cache)
536-
(let ((aliases (ess-get-help-aliases-list)))
537-
(should (member "list" aliases)))))
529+
(ess-help--reset-cache)
530+
(let ((aliases (ess-get-help-aliases-list)))
531+
(should (member "list" aliases))))
538532

539533

540534
;;*;; Inferior utils

0 commit comments

Comments
 (0)