Skip to content

Commit 8a6df8e

Browse files
committed
Add file-local config for etest
Macros like `etest-deftest-r` are not compatible with `etest-update`. Instead we use a file-local variable to provide mode configuration.
1 parent ecd2f43 commit 8a6df8e

File tree

9 files changed

+113
-47
lines changed

9 files changed

+113
-47
lines changed

test/ess-test-inf.el

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272

7373
;;*;; Evaluation
7474

75-
(etest-deftest-r ess-command-test ()
75+
(etest-deftest ess-command-test ()
7676
"`ess-command' saves output in specified buffer."
7777
:eval (let ((output-buffer (get-buffer-create " *ess-test-command-output*")))
7878
(ess-command "identity(TRUE)\n" output-buffer)
@@ -115,7 +115,7 @@
115115
(should (string-match "^\\[1\\] \"foo\"\nSourced file"
116116
(output nil (ess-load-file (expand-file-name "file.R" ess-test-fixtures-directory)))))))
117117

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

@@ -128,7 +128,7 @@
128128
(should-error (ess-command "list(" nil nil nil nil nil nil 0.01)))
129129
:inf-result "")
130130

131-
(etest-deftest-r ess-command-hanging-test ()
131+
(etest-deftest ess-command-hanging-test ()
132132
"`ess-command' fails with hanging command."
133133
:eval (should-error (ess-command "Sys.sleep(2)\n" nil nil nil nil nil nil 0.01))
134134
:inf-result ""
@@ -143,7 +143,7 @@
143143
(ess-wait-for-process)
144144
(etest-clear-inferior-buffer))
145145

146-
(etest-deftest-r ess--command-browser-timeout-test ()
146+
(etest-deftest ess--command-browser-timeout-test ()
147147
"`ess-command' fails with hanging command within browser (#1081)."
148148
:cleanup (ess-test--browser-cleanup)
149149
:eval (ess-test--browser)
@@ -164,7 +164,7 @@ Browse[1]> "
164164
:inf-result "NULL
165165
Browse[1]> ")
166166

167-
(etest-deftest-r ess-command-browser-curly-braces ()
167+
(etest-deftest ess-command-browser-curly-braces ()
168168
"`{` expressions when debugger is active do not interrupt command."
169169
:cleanup (ess-test--browser-cleanup)
170170
:eval (ess-test--browser)
@@ -177,7 +177,7 @@ Browse[1]> "
177177
:inf-result ""
178178
:eval (should (inferior-ess-available-p)))
179179

180-
(etest-deftest-r ess-command-environment ()
180+
(etest-deftest ess-command-environment ()
181181
"Can access current env with `.ess.environment()`"
182182
:cleanup (ess-test--browser-cleanup)
183183
:eval (progn
@@ -187,7 +187,7 @@ Browse[1]> "
187187
:eval (should (string= (ess-string-command "ls(envir = .ess.environment())\n")
188188
"[1] \"foo\"")))
189189

190-
(etest-deftest-r ess-command-quit-test ()
190+
(etest-deftest ess-command-quit-test ()
191191
"`ess-command' does not leak output on quit (#794, #842).
192192
This is especially important within `while-no-input' used by
193193
packages like eldoc and company-quickhelp. `throw-on-input' sets
@@ -201,7 +201,7 @@ packages like eldoc and company-quickhelp. `throw-on-input' sets
201201
:inf-result ""
202202
:eval (should (inferior-ess-available-p)))
203203

204-
(etest-deftest-r ess-command-quit-async-interrupt-test ()
204+
(etest-deftest ess-command-quit-async-interrupt-test ()
205205
"`ess-command' interrupts asynchronously on quits (#1091, #1102).
206206
Needed with slow-responding processes."
207207
:eval
@@ -229,14 +229,14 @@ Needed with slow-responding processes."
229229
;; There should be no output after the early exit or async restoration
230230
:inf-result "")
231231

232-
(etest-deftest-r ess-command-newlines-test ()
232+
(etest-deftest ess-command-newlines-test ()
233233
"`ess-command' doesn't garble new lines (#1110)."
234234
:eval ((should (string= (ess--strip-final-newlines "1\n2")
235235
"1\n2"))
236236
(should (equal (ess-get-words-from-vector "{ 'foo'\n'bar'\n }\n")
237237
(list "bar")))))
238238

239-
(etest-deftest-r ess-command-multiline-test ()
239+
(etest-deftest ess-command-multiline-test ()
240240
"`ess-command' output doesn't include continuation prompts (#1116)."
241241
:eval ((let ((buf (generate-new-buffer "ess-command-multiline-test")))
242242
(ess-command "{ 1\n 2 }\n" buf)
@@ -301,7 +301,7 @@ new output")
301301
(should (equal (ess--command-delimited-output-info (current-buffer) "my-sentinel")
302302
(list 20 27 49)))))
303303

304-
(etest-deftest-r command-without-trailing-newline-test ()
304+
(etest-deftest command-without-trailing-newline-test ()
305305
"It is a bug when a command doesn't output a trailing newline.
306306
With delimiters it might be possible to figure out the output.
307307
However if they are not available then the output is
@@ -313,7 +313,7 @@ indistinguishable from the prompt."
313313
:inf-result "
314314
> ")
315315

316-
(etest-deftest-r ess-command-intervening-input-test ()
316+
(etest-deftest ess-command-intervening-input-test ()
317317
"Test that user can send input while command is interrupting (#1119)."
318318
:eval
319319
(progn
@@ -527,7 +527,7 @@ some. text
527527

528528
;;*;; Help
529529

530-
(etest-deftest-r ess-help-aliases-test ()
530+
(etest-deftest ess-help-aliases-test ()
531531
:eval (let ((aliases (ess-get-help-aliases-list)))
532532
(should (member "list" aliases)))
533533
:inf-result ""
@@ -624,6 +624,11 @@ some. text
624624
(ess-switch-to-inferior-or-script-buffer nil)
625625
(should (derived-mode-p 'inferior-ess-mode))))
626626

627+
627628
(provide 'ess-test-inf)
628629

630+
;; Local Variables:
631+
;; etest-local-config: etest-r-config
632+
;; End:
633+
629634
;;; ess-test-inf.el ends here

test/ess-test-r-eval.el

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,11 +254,16 @@ TODO: Install company-mode dependency in CI."
254254
"C-c C-r")
255255
:inf-result "+ + + + + + > ")
256256

257-
(etest-deftest-r ess-string-command-test ()
257+
(etest-deftest ess-string-command-test ()
258258
"`ess-string-command` handles multiline outputs (#922)"
259259
:eval ((should (string= (ess-string-command "quote({ 1 })\n")
260260
"{\n 1\n}"))
261261
(should (string= (ess-string-command "list(1)\n")
262262
"[[1]]\n[1] 1\n"))))
263263

264+
265+
;; Local Variables:
266+
;; etest-local-config: etest-r-config
267+
;; End:
268+
264269
;;; ess-test-r-eval.el ends here

test/ess-test-r-mode.el

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,16 @@
1616
;;; Commentary:
1717
;;
1818

19-
(etest-deftest-r test-ess-inferior-r-backticked ()
19+
(etest-deftest test-ess-inferior-r-backticked ()
2020
"Backticked symbols are not fontified as strings."
2121
:case "¶`f¶oo¶`"
2222
:eval (progn
2323
(setq-local font-lock-syntactic-face-function
2424
'inferior-ess-r-font-lock-syntactic-face-function)
2525
(font-lock-ensure)
2626
(should (not (face-at-point)))))
27+
28+
29+
;; Local Variables:
30+
;; etest-local-config: etest-r-config
31+
;; End:

test/ess-test-r-syntax.el

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,32 +21,32 @@
2121
(require 'ess-r-mode)
2222
(require 'ess-test-r-utils)
2323

24-
(etest-deftest-r ess-r-syntax-backslash-test ()
24+
(etest-deftest ess-r-syntax-backslash-test ()
2525
:case "sapply(x, ¶\\(y) y"
2626
:eval (should (equal (syntax-after (point))
2727
(string-to-syntax ".")))
2828
:case "c(\"\\\"\")"
2929
:eval (should (equal (syntax-after (point))
3030
(string-to-syntax "\\"))))
3131

32-
(etest-deftest-r ess-r-font-lock-boolean-operator-test ()
32+
(etest-deftest ess-r-font-lock-boolean-operator-test ()
3333
:case "foo ¶| foo ¶|¶| foo ¶& foo ¶&¶& foo"
3434
:eval (ess-with-enabled-font-lock-keyword 'ess-fl-keyword:operators
3535
(font-lock-ensure)
3636
(should (eq (face-at-point) 'ess-operator-face))))
3737

38-
(etest-deftest-r ess-r-font-lock-pipe-operator-test ()
38+
(etest-deftest ess-r-font-lock-pipe-operator-test ()
3939
:case "a ¶|¶> b"
4040
:eval (ess-with-enabled-font-lock-keyword 'ess-fl-keyword:operators
4141
(font-lock-ensure)
4242
(should (eq (face-at-point) 'ess-operator-face))))
4343

44-
(etest-deftest-r ess-r-tokens-pipe-operator-test ()
44+
(etest-deftest ess-r-tokens-pipe-operator-test ()
4545
:case "a ¶|> b"
4646
:eval (should (token= "|>"))
4747
:result "a |>¶ b")
4848

49-
(etest-deftest-r ess-r-raw-strings-test ()
49+
(etest-deftest ess-r-raw-strings-test ()
5050
:case "
5151
\"(foo\"bar))¶\"
5252
\"(foo}\"bar))¶\"
@@ -90,3 +90,8 @@ r\"(foor¶'()¶'bar))\"
9090
"
9191
:eval (should (not (equal (syntax-after (point))
9292
(string-to-syntax "|")))))
93+
94+
95+
;; Local Variables:
96+
;; etest-local-config: etest-r-config
97+
;; End:

test/ess-test-r-utils.el

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323
(require 'tramp)
2424
(require 'seq)
2525

26+
(defvar etest-r-config
27+
'(:init ((mode . r)
28+
(eval . (ess-test-r-set-local-process)))))
29+
2630
(defvar ess-test-fixtures-directory
2731
(expand-file-name "fixtures"
2832
(file-name-directory (or load-file-name
@@ -300,17 +304,6 @@ representative to the common interactive use with tracebug on."
300304
(setq ess-local-process-name (process-name (get-buffer-process proc-buf)))
301305
(setq etest-local-inferior-buffer proc-buf)))
302306

303-
(cl-defmacro etest-deftest-r (name args &body body)
304-
(declare (doc-string 3)
305-
(indent 2))
306-
(let ((etest--docstring (when (stringp (car body))
307-
(list (pop body)))))
308-
`(etest-deftest ,name ,args
309-
,@etest--docstring
310-
:init ((mode . r)
311-
(eval . (ess-test-r-set-local-process)))
312-
,@body)))
313-
314307
;; Utilities for testing remote functionality
315308

316309
;; Define a mock TRAMP method to use for testing. This code is taken from
@@ -423,4 +416,9 @@ token."
423416

424417
(provide 'ess-test-r-utils)
425418

419+
420+
;; Local Variables:
421+
;; etest-local-config: etest-r-config
422+
;; End:
423+
426424
;;; ess-test-r-utils.el ends here

test/ess-test-r.el

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -807,7 +807,7 @@ https://github.com/emacs-ess/ESS/issues/725#issuecomment-431781558"
807807
(should (commandp 'R))
808808
(should (commandp 'R-newest)))
809809

810-
(etest-deftest-r ess-command-last-value-test ()
810+
(etest-deftest ess-command-last-value-test ()
811811
"`ess-command` preserves `.Last.value (#1058)"
812812
:case "100¶"
813813
:eval "C-c C-c"
@@ -826,15 +826,15 @@ https://github.com/emacs-ess/ESS/issues/725#issuecomment-431781558"
826826
[1] 100
827827
> ")
828828

829-
(etest-deftest-r ess-r-pager-test ()
829+
(etest-deftest ess-r-pager-test ()
830830
:eval ((should (string= (car (ess-get-words-from-vector "getOption('pager')\n"))
831831
"cat"))))
832832

833833
;; rdired
834834

835835
(require 'ess-rdired)
836836

837-
(etest-deftest-r ess-rdired-test ()
837+
(etest-deftest ess-rdired-test ()
838838
:inf-cleanup
839839
(progn
840840
(kill-buffer ess-rdired-buffer)
@@ -895,4 +895,9 @@ https://github.com/emacs-ess/ESS/issues/725#issuecomment-431781558"
895895

896896
(provide 'ess-test-r)
897897

898+
899+
;; Local Variables:
900+
;; etest-local-config: etest-r-config
901+
;; End:
902+
898903
;;; ess-test-r.el ends here

test/etest/etest.el

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,18 @@
2929
Use the `:inf-result' to flush this buffer and test its
3030
contents.")
3131

32+
(defvar-local etest-local-config nil
33+
"Local configuration for `etest-deftest'.
34+
List of etest keywords and commands, e.g. an `:init' spec to set
35+
up a particular mode.")
36+
3237
(cl-defmacro etest-deftest (name args &body body)
3338
(declare (doc-string 3)
3439
(indent 2))
3540
(let ((etest--docstring (when (stringp (car body))
3641
(list (pop body)))))
42+
;; Record this at compile time because ert doesn't run tests locally
43+
(etest--push-local-config body)
3744
`(ert-deftest ,name ,args
3845
,@etest--docstring
3946
(etest--run-test (quote ,body)
@@ -47,6 +54,17 @@ contents.")
4754
(setq local (append local (pop ,place))))
4855
local))
4956

57+
;; Evaluate symbols to make it easier to set local variables
58+
(defmacro etest--push-local-config (place)
59+
`(let ((etest--config (cond ((not etest-local-config)
60+
nil)
61+
((symbolp etest-local-config)
62+
(eval etest-local-config))
63+
(t
64+
etest-local-config))))
65+
(when etest--config
66+
(setq ,place (append etest--config ,place)))))
67+
5068
(defmacro etest--with-test-buffer (init &rest body)
5169
(declare (indent 1)
5270
(debug (&rest form)))
@@ -189,6 +207,7 @@ keywords."
189207
(pop body))
190208
(when (stringp (car body))
191209
(pop body))
210+
(etest--push-local-config body)
192211
(let ((results (etest--read-results body)))
193212
(goto-char beg)
194213
(forward-char 1)

test/etest/test-etest.el

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
;; -*- lexical-binding: t -*-
12

23
(require 'ert)
34
(require 'etest)
@@ -234,3 +235,18 @@ bar"
234235
:result "f¶oo×"
235236
:eval "<right>"
236237
:result "fo¶o×")
238+
239+
;; `let' doesn't seem to work here, perhaps an interaction between
240+
;; scoping in macros and file-local variables
241+
(setq etest-local-config '(:init ((mode . text))))
242+
243+
(etest-deftest etest-local-config-test ()
244+
"Local configuration is picked up"
245+
:eval (should (eq major-mode 'text-mode)))
246+
247+
(setq etest-local-config nil)
248+
249+
(etest-deftest etest-default-mode ()
250+
"Default mode is fundamental.
251+
Also tests local config test is cleaned up properly."
252+
:eval (should (eq major-mode 'fundamental-mode)))

0 commit comments

Comments
 (0)