diff options
Diffstat (limited to 'test')
| -rw-r--r-- | test/ess-test-inf.el | 35 | ||||
| -rw-r--r-- | test/ess-test-literate.el | 13 | ||||
| -rw-r--r-- | test/ess-test-org.el | 2 | ||||
| -rw-r--r-- | test/ess-test-r-eval.el | 2 | ||||
| -rw-r--r-- | test/ess-test-r-mode.el | 2 | ||||
| -rw-r--r-- | test/ess-test-r-syntax.el | 2 | ||||
| -rw-r--r-- | test/ess-test-r-utils.el | 140 | ||||
| -rw-r--r-- | test/ess-test-r.el | 13 | ||||
| -rw-r--r-- | test/ess-test-rd.el | 2 | ||||
| -rw-r--r-- | test/etest/test-etest.el | 2 | ||||
| -rw-r--r-- | test/literate/fontification.el | 5 | ||||
| -rw-r--r-- | test/literate/roxy.el | 15 | ||||
| -rw-r--r-- | test/literate/tokens.el | 1 |
13 files changed, 126 insertions, 108 deletions
diff --git a/test/ess-test-inf.el b/test/ess-test-inf.el index 980c8d4..15fa065 100644 --- a/test/ess-test-inf.el +++ b/test/ess-test-inf.el @@ -17,7 +17,7 @@ ;; Tests for inferior processes. (require 'ert) -(require 'etest) +(require 'etest "test/etest/etest") (require 'cl-lib) ;; As we use the R inferior for the generic tests @@ -47,7 +47,7 @@ (ert-deftest ess-test-inferior-live-process-error () (let* ((ess-gen-proc-buffer-name-function ;; Generate same inferior name each time - (lambda (&rest args) "" "foo")) + (lambda (&rest _) "" "foo")) (error-msg "Can't start a new session in buffer `foo` because one already exists") (inf-buf (run-ess-test-r-vanilla))) (ess-test-unwind-protect inf-buf @@ -56,7 +56,8 @@ (ert-deftest ess-test-inferior-local-start-args () (with-r-running nil - (let ((inf-data (buffer-local-value 'inferior-ess--local-data *inf-buf*))) + (let ((inf-data (buffer-local-value 'inferior-ess--local-data + (process-buffer *proc*)))) (should (equal (car inf-data) "R")) (should (equal (cdr inf-data) "--no-readline --no-init-file --no-site-file"))))) @@ -97,7 +98,7 @@ (ess-async-command "{cat(1:5);Sys.sleep(0.5);cat(2:6, '\n')}\n" (get-buffer-create " *ess-async-text-command-output*") inf-proc - (lambda (&rest args) (setq semaphore t))) + (lambda (&rest _) (setq semaphore t))) (should (process-get inf-proc 'callbacks)) (cl-loop repeat 3 until (and semaphore (null (process-get inf-proc 'callbacks))) @@ -106,7 +107,7 @@ (ert-deftest ess-run-presend-hooks-test () (with-r-running nil - (let ((ess-presend-filter-functions (list (lambda (string) "\"bar\"")))) + (let ((ess-presend-filter-functions (list (lambda (_string) "\"bar\"")))) (should (output= (ess-send-string (ess-get-process) "\"foo\"") "[1] \"bar\""))))) @@ -476,9 +477,10 @@ cleaned-prompts > } ") (output "> ") - (output-nowait "> fn <- function() { -+ } -> ")) + ;; (output-nowait "> fn <- function() { +;; + } +;; > ") + ) (let ((inferior-ess-replace-long+ t)) (let ((ess-eval-visibly nil)) (should (string= output @@ -500,14 +502,15 @@ head(cars, 2) 1 4 2 2 4 10 > ") - (output-nowait "cat(\"some. text\\n\") -+ head(cars, 2) -some. text -> - speed dist -1 4 2 -2 4 10 -> ")) + ;; (output-nowait "cat(\"some. text\\n\") +;; + head(cars, 2) +;; some. text +;; > +;; speed dist +;; 1 4 2 +;; 2 4 10 +;; > ") + ) (let ((inferior-ess-replace-long+ t)) (let ((ess-eval-visibly nil)) (should (string= output diff --git a/test/ess-test-literate.el b/test/ess-test-literate.el index fd49c38..01872f5 100644 --- a/test/ess-test-literate.el +++ b/test/ess-test-literate.el @@ -10,12 +10,11 @@ (require 'ess-r-mode) (eval-when-compile (require 'cl-lib)) -(require 'etest) +(require 'etest "test/etest/etest") (defvar elt-section-pattern) (defvar elt-chunk-pattern) (defvar elt-code-pattern) -(defvar chunk-end) (defvar elt-code-cont-pattern) (defvar test-case) (defvar test-case-state) @@ -70,7 +69,7 @@ (with-temp-buffer (insert src-string) ;; Don't check safety of local variables declared in test files - (cl-letf (((symbol-function 'safe-local-variable-p) (lambda (sym val) t))) + (cl-letf (((symbol-function 'safe-local-variable-p) (lambda (_sym _val) t))) (let ((enable-dir-local-variables nil)) (hack-local-variables))) (let ((elt-chunk-pattern elt-ess-r-chunk-pattern) @@ -148,7 +147,7 @@ (condition-case cnd (let* ((test-case (progn (skip-chars-forward " \t\n") - (elt-process-case))) + (elt-process-case chunk-end))) (test-case-state test-case)) (while (looking-at elt-code-pattern) (elt-process-next-subchunk chunk-end)) @@ -166,7 +165,7 @@ (defun elt-process-next-subchunk (chunk-end) (let* ((continuation (looking-at elt-code-cont-pattern)) - (test-code (elt-process-code)) + (test-code (elt-process-code chunk-end)) (test-result (elt-run-chunk test-code elt-mode-init continuation)) @@ -178,7 +177,7 @@ (delete-region (point) subchunk-end) (insert (concat "\n" test-result "\n\n")))) -(defun elt-process-case () +(defun elt-process-case (chunk-end) (let ((case-start (progn (skip-chars-forward " \t\n") (goto-char (line-beginning-position)) @@ -194,7 +193,7 @@ (insert "\n") (buffer-substring-no-properties case-start case-end))) -(defun elt-process-code () +(defun elt-process-code (chunk-end) (let* ((test-start (point)) (test-end (if (re-search-forward "^$" chunk-end t) (1- (match-beginning 0)) diff --git a/test/ess-test-org.el b/test/ess-test-org.el index e79b738..7303d83 100644 --- a/test/ess-test-org.el +++ b/test/ess-test-org.el @@ -30,7 +30,7 @@ (defun test-org-R-ouput (expect input) (declare (indent 1)) (let* ((inf-buf (run-ess-test-r-vanilla)) - (inf-proc (get-buffer-process inf-buf))) + ) ;; (inf-proc (get-buffer-process inf-buf)) (setq input (format input (buffer-name inf-buf))) (ess-test-unwind-protect inf-buf (with-current-buffer (get-buffer-create "*ess-org-test*") diff --git a/test/ess-test-r-eval.el b/test/ess-test-r-eval.el index 538d4bb..a019c69 100644 --- a/test/ess-test-r-eval.el +++ b/test/ess-test-r-eval.el @@ -17,7 +17,7 @@ ;; (require 'ert) -(require 'etest) +(require 'etest "test/etest/etest") (require 'ess-r-mode) (require 'ess-test-r-utils) diff --git a/test/ess-test-r-mode.el b/test/ess-test-r-mode.el index 2173e43..232c683 100644 --- a/test/ess-test-r-mode.el +++ b/test/ess-test-r-mode.el @@ -20,7 +20,7 @@ "Backticked symbols are not fontified as strings." :case "¶`f¶oo¶`" (setq-local font-lock-syntactic-face-function - 'inferior-ess-r-font-lock-syntactic-face-function) + #'inferior-ess-r-font-lock-syntactic-face-function) (font-lock-ensure) (should (not (face-at-point)))) diff --git a/test/ess-test-r-syntax.el b/test/ess-test-r-syntax.el index 199e329..497cb41 100644 --- a/test/ess-test-r-syntax.el +++ b/test/ess-test-r-syntax.el @@ -17,7 +17,7 @@ ;; (require 'ert) -(require 'etest) +(require 'etest "test/etest/etest") (require 'ess-r-mode) (require 'ess-test-r-utils) diff --git a/test/ess-test-r-utils.el b/test/ess-test-r-utils.el index 2288500..c7b528e 100644 --- a/test/ess-test-r-utils.el +++ b/test/ess-test-r-utils.el @@ -18,7 +18,7 @@ ;;; Code: (require 'ert) -(require 'etest) +(require 'etest "test/etest/etest") (require 'ess-r-mode) (require 'tramp) (require 'seq) @@ -39,7 +39,7 @@ (declare (indent 1) (debug (&rest body))) `(let ((inhibit-message ess-inhibit-message-in-tests) (*file* ,file)) - (save-window-excursion + (save-window-excursion ;; FIXME: Why not `save-current-buffer'? (set-buffer (if *file* (find-file-noselect *file*) (generate-new-buffer " *with-r-file-temp*"))) @@ -98,6 +98,32 @@ inserted text." (goto-char (point-min)))) ,@body))) +(defmacro ess-test-sleep-while (test seconds timeout &optional msg) + (declare (debug t)) + `(ess--test-sleep-while-1 (lambda () ,test) ,seconds ,timeout ,msg)) + +(defun ess--test-sleep-while-1 (test-fun seconds timeout msg) + (let ((time-start (current-time))) + (while (funcall test-fun) + (when (time-less-p timeout (time-subtract (current-time) time-start)) + (error (or msg "Exceeded timeout"))) + (sleep-for seconds)) + t)) + +(defmacro ess-test-unwind-protect (inf-buf &rest body) + (declare (indent 1) (debug t)) + `(ess--test-unwind-protect-1 ,inf-buf (lambda () ,@body))) + +(defun ess--test-unwind-protect-1 (inf-buf body-fun) + (unwind-protect (funcall body-fun) + (let* ((inf-proc (get-buffer-process inf-buf))) + (when (and inf-proc (process-live-p inf-proc)) + (set-process-query-on-exit-flag inf-proc nil) + (kill-process inf-proc) + (ess-test-sleep-while (process-live-p inf-proc) 0.001 1 + "Expected dead process")) + (kill-buffer inf-buf)))) + (defun run-ess-test-r-vanilla () "Start vanilla R process and return the process object." (save-window-excursion @@ -135,14 +161,14 @@ inserted text." (defun ess-send-input-to-R (input &optional type) "Eval INPUT and return the entire content of the REPL buffer. -TYPE can be one of 'string, 'region 'c-c or 'repl. If nil or -'string, use `ess-send-string' (lowest level primitive); if -'region use `ess-eval-region' if 'c-c use +TYPE can be one of `string', `region', `c-c' or `repl'. If nil or +`string', use `ess-send-string' (lowest level primitive); if +`region' use `ess-eval-region' if `c-c' use `ess-eval-region-or-function-or-paragraph' which is by default -bound to C-c C-c; if 'repl, eval interactively at the REPL. All -prompts in the output are replaced with '> '. There is no full +bound to `C-c C-c'; if `repl', eval interactively at the REPL. +All prompts in the output are replaced with \"> \". There is no fool proof way to test for prompts given that process output could be -split arbitrary." +split arbitrarily." (let* ((prompt-regexp "^\\([+.>] \\)\\{2,\\}") (inf-buf (run-ess-test-r-vanilla)) (inf-proc (get-buffer-process inf-buf)) @@ -197,36 +223,44 @@ split arbitrary." ;; !!! NB: proc functionality from now on uses inferior-ess-ordinary-filter and ;; !!! *proc* dynamic var -(defmacro with-r-running (buffer-or-file &rest body) +(defmacro with-r-running (buffer-or-file &rest body) ;; FIXME: "ess-" prefix! "Run BODY within BUFFER-OR-FILE with attached R process. -If BUFFER-OR-FILE is a file, the file is visited first. The R +If BUFFER-OR-FILE is a file, the file is visited first. The R process is run with `inferior-ess-ordinary-filter' which is not -representative to the common interactive use with tracebug on." +representative to the common interactive use with tracebug on. +BODY can refer to the process via the variable `*proc*'." (declare (indent 1) (debug (form body))) - `(let* ((inhibit-message ess-inhibit-message-in-tests) - (buffer-or-file ,buffer-or-file) - (r-file-buffer (cond ((bufferp buffer-or-file) - buffer-or-file) - ((stringp buffer-or-file) - (find-file-noselect buffer-or-file)) - (t - (generate-new-buffer " *with-r-file-temp*"))))) - (save-window-excursion - (switch-to-buffer r-file-buffer) - (R-mode) - (let* ((*proc* (get-buffer-process (run-ess-test-r-vanilla))) - (ess-local-process-name (process-name *proc*)) - (*inf-buf* (process-buffer *proc*))) - (unwind-protect - (ess-test-unwind-protect *inf-buf* - (setq ess-r-tests-current-output-buffer *inf-buf*) - (let ((inhibit-read-only t)) - (with-current-buffer ess-r-tests-current-output-buffer - (erase-buffer))) - (set-process-filter *proc* 'inferior-ess-output-filter) - (prog1 (progn ,@body) - (ess-wait-for-process *proc*))) - (setq ess-r-tests-current-output-buffer nil)))))) + `(ess--with-r-running-1 ,buffer-or-file + (lambda (*proc*) (ignore *proc*) ,@body))) + +(defun ess--with-r-running-1 (buffer-or-file body-fun) + (let* ((inhibit-message ess-inhibit-message-in-tests) + (r-file-buffer (cond ((bufferp buffer-or-file) + buffer-or-file) + ((stringp buffer-or-file) + (find-file-noselect buffer-or-file)) + (t + (generate-new-buffer " *with-r-file-temp*"))))) + ;; FIXME: If you don't want to display `r-file-buffer', then why not + ;; use `with-current-buffer' rather than using `switch-to-buffer' + ;; and then having to try and undo its damage with `save-window-excursion' + ;; (which can't work when `switch-to-buffer' created a new frame)? + (save-window-excursion + (switch-to-buffer r-file-buffer) + (R-mode) + (let* ((*proc* (get-buffer-process (run-ess-test-r-vanilla))) + (ess-local-process-name (process-name *proc*)) + (*inf-buf* (process-buffer *proc*))) + (unwind-protect + (ess-test-unwind-protect *inf-buf* + (setq ess-r-tests-current-output-buffer *inf-buf*) + (let ((inhibit-read-only t)) + (with-current-buffer ess-r-tests-current-output-buffer + (erase-buffer))) + (set-process-filter *proc* #'inferior-ess-output-filter) + (prog1 (funcall body-fun *proc*) + (ess-wait-for-process *proc*))) + (setq ess-r-tests-current-output-buffer nil)))))) (defvar ess-r-tests-current-output-buffer nil) @@ -238,7 +272,7 @@ representative to the common interactive use with tracebug on." ;; to perform ulterior tests with a fresh R to avoid contaminating ;; them. -(defmacro output (&rest body) +(defmacro output (&rest body) ;; FIXME: `ess-' prefix? (declare (indent 1) (debug (&rest body))) `(progn (ess-wait-for-process *proc*) @@ -249,18 +283,18 @@ representative to the common interactive use with tracebug on." (prog1 (buffer-substring-no-properties (point-min) (point-max)) (erase-buffer))))) -(defmacro output= (body expected) +(defmacro output= (body expected) ;; FIXME: `ess-' prefix? (declare (indent 0) (debug (sexp sexp))) `(progn (let ((output (output ,body)) - (expected (eval ,expected))) + (expected ,expected)) (if (string= output expected) output ;; Probably a better way but this gets the job done (signal 'ert-test-failed (list (concat "Expected: \n" expected) (concat "Result: \n" output))))))) -(defun face-at (point) +(defun face-at (point) ;; FIXME: `ess-' prefix? (save-excursion (if (>= point 0) (goto-char point) @@ -271,30 +305,8 @@ representative to the common interactive use with tracebug on." (apply #'insert args) (font-lock-default-fontify-buffer)) -(defmacro ess-test-sleep-while (test seconds timeout &optional msg) - `(let ((_seconds ,seconds) - (_timeout ,timeout) - (_time-start (current-time))) - (while ,test - (when (time-less-p _timeout (time-subtract (current-time) _time-start)) - (error (or ,msg "Exceeded timeout"))) - (sleep-for _seconds)) - t)) - ;; It is safer to kill the buffer synchronously, otherwise it might be ;; reused in another test -(defmacro ess-test-unwind-protect (inf-buf &rest body) - (declare (indent 1)) - `(unwind-protect (progn ,@body) - (let* ((inf-buf ,inf-buf) - (inf-proc (get-buffer-process inf-buf))) - (when (and inf-proc (process-live-p inf-proc)) - (set-process-query-on-exit-flag inf-proc nil) - (kill-process inf-proc) - (ess-test-sleep-while (process-live-p inf-proc) 0.001 1 - "Expected dead process")) - (kill-buffer inf-buf)))) - (defun ess-test-r-set-local-process (&optional type) (let* ((proc-buf (ess-r-test-proc-buf (or type 'tracebug))) (proc (get-buffer-process proc-buf))) @@ -319,9 +331,9 @@ representative to the common interactive use with tracebug on." (tramp-connection-timeout 10))) (defun ess-test-create-remote-path (path) - "Construct a remote path using the 'mock' TRAMP method. + "Construct a remote path using the `mock' TRAMP method. Take a string PATH representing a local path, and construct a -remote path that uses the 'mock' TRAMP method." +remote path that uses the `mock' TRAMP method." (let ((full-path (abbreviate-file-name (expand-file-name path)))) (concat "/mock::" full-path))) @@ -377,7 +389,7 @@ Throws an error if unsuccesful." (should (ess--essr-check-if-in-essrenv))) (kill-buffer))) -(defun token= (type &optional value) +(defun token= (type &optional value) ;; FIXME: `ess-' prefix? "Check that the next token conforms to TYPE and VALUE. This checks it back and forth and moves the point after the token." diff --git a/test/ess-test-r.el b/test/ess-test-r.el index 6f59e4b..9c885d8 100644 --- a/test/ess-test-r.el +++ b/test/ess-test-r.el @@ -17,24 +17,25 @@ ;; (require 'ert) -(require 'etest) +(require 'etest "test/etest/etest") (require 'ess-r-mode) (require 'ess-test-r-utils) (require 'cc-mode) (require 'imenu) (with-no-warnings (when (< emacs-major-version 26) - (require 'cl))) + (require 'cl))) ;; FIXME: For? ;;; R ;;; Code: (ert-deftest ess-r-inherits-prog-mode-test () - (let ((prog-mode-hook (lambda () (setq ess-test-prog-hook t)))) + (let* ((pmh-was-run nil) + (prog-mode-hook (lambda () (setq pmh-was-run t)))) (with-ess-test-r-file nil (should (derived-mode-p 'prog-mode)) - (should ess-test-prog-hook) + (should pmh-was-run) (should ;; Test that prog-mode-map is a keymap-parent (let ((map (current-local-map)) @@ -156,7 +157,7 @@ (ert-deftest ess-r-run-presend-hooks-test () (with-r-running nil - (let ((ess-presend-filter-functions (list (lambda (string) "\"bar\""))) + (let ((ess-presend-filter-functions (list (lambda (_string) "\"bar\""))) (ess-r-evaluation-env "base") ess-eval-visibly) (insert "\"foo\"\n") @@ -204,7 +205,7 @@ (defun ess-test-init-insert-assign () (let ((map (make-sparse-keymap))) - (define-key map "_" 'ess-insert-assign) + (define-key map "_" #'ess-insert-assign) (use-local-map map))) (etest-deftest ess-insert-assign-test () diff --git a/test/ess-test-rd.el b/test/ess-test-rd.el index bb519fa..e06060a 100644 --- a/test/ess-test-rd.el +++ b/test/ess-test-rd.el @@ -17,7 +17,7 @@ ;; (require 'ert) -(require 'etest) +(require 'etest "test/etest/etest") (require 'ess-r-mode) (require 'ess-test-r-utils) (require 'ess-rd) diff --git a/test/etest/test-etest.el b/test/etest/test-etest.el index 896920b..25f0b81 100644 --- a/test/etest/test-etest.el +++ b/test/etest/test-etest.el @@ -1,7 +1,7 @@ ;; -*- lexical-binding: t -*- (require 'ert) -(require 'etest) +(require 'etest "test/etest/etest") (etest-deftest etest-local-vars-test () "`:init' keyword specifies local variables." diff --git a/test/literate/fontification.el b/test/literate/fontification.el index 41bed7c..f3e6827 100644 --- a/test/literate/fontification.el +++ b/test/literate/fontification.el @@ -1,5 +1,6 @@ -(defun face-at-point () - (get-char-property (point) 'face)) +;; -*- lexical-binding: t; -*- +;; (defun face-at-point () +;; (get-char-property (point) 'face)) (defmacro with-ess-toggled-font-lock-keyword (enable keywords &rest body) (declare (indent 2) diff --git a/test/literate/roxy.el b/test/literate/roxy.el index 1d0de69..d11f5da 100644 --- a/test/literate/roxy.el +++ b/test/literate/roxy.el @@ -1,9 +1,10 @@ +;; -*- lexical-binding: t; -*- -(defun face-at-point () - (get-char-property (point) 'face)) +;; (defun face-at-point () +;; (get-char-property (point) 'face)) -(defun faces-at-point () - (let ((face (get-char-property (point) 'face))) - (if (listp face) - face - (list face)))) +;; (defun faces-at-point () +;; (let ((face (get-char-property (point) 'face))) +;; (if (listp face) +;; face +;; (list face)))) diff --git a/test/literate/tokens.el b/test/literate/tokens.el index 3351dcf..0329869 100644 --- a/test/literate/tokens.el +++ b/test/literate/tokens.el @@ -1,3 +1,4 @@ +;; -*- lexical-binding: t; -*- (defun token= (type &optional value) "Check that the next token conforms to TYPE and VALUE. |
