From 9dfecf8c4701ebf78142deadc228e76ee145449f Mon Sep 17 00:00:00 2001 From: David Pritchard Date: Sun, 18 Oct 2020 10:39:23 -0400 Subject: [PATCH 01/21] Add a mock TRAMP method --- test/ess-test-r-utils.el | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/test/ess-test-r-utils.el b/test/ess-test-r-utils.el index b6229389a..097aea808 100644 --- a/test/ess-test-r-utils.el +++ b/test/ess-test-r-utils.el @@ -304,6 +304,38 @@ representative to the common interactive use with tracebug on." (eval . (ess-test-r-set-local-process))) ,@body))) +;; Define a mock TRAMP method to use for testing. This code is taken from +;; `tramp-tests.el'. +(defconst tramp-test-temporary-file-directory + (cond + ((getenv "REMOTE_TEMPORARY_FILE_DIRECTORY")) + ((eq system-type 'windows-nt) null-device) + (t (add-to-list + 'tramp-methods + '("mock" + (tramp-login-program "sh") + (tramp-login-args (("-i"))) + (tramp-direct-async-args (("-c"))) + (tramp-remote-shell "/bin/sh") + (tramp-remote-shell-args ("-c")) + (tramp-connection-timeout 10))) + (add-to-list + 'tramp-default-host-alist + `("\\`mock\\'" nil ,(system-name))) + ;; Emacs's Makefile sets $HOME to a nonexistent value. Needed + ;; in batch mode only, therefore. + (unless (and (null noninteractive) (file-directory-p "~/")) + (setenv "HOME" temporary-file-directory)) + (format "/mock::%s" temporary-file-directory))) + "Temporary directory for Tramp tests.") + +(defun ess-test-make-remote-path (path) + "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." + (let ((full-path (abbreviate-file-name (expand-file-name path)))) + (concat "/mock::" full-path))) + (provide 'ess-test-r-utils) ;;; ess-test-r-utils.el ends here From 075b1f2d9b28f87e92d24f5104e32045e8dc4709 Mon Sep 17 00:00:00 2001 From: David Pritchard Date: Fri, 16 Oct 2020 18:12:14 -0400 Subject: [PATCH 02/21] Add `ess-path-get-local-portion` --- lisp/ess-inf.el | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lisp/ess-inf.el b/lisp/ess-inf.el index abf6ea80a..7c8632a32 100644 --- a/lisp/ess-inf.el +++ b/lisp/ess-inf.el @@ -2920,6 +2920,14 @@ path, and can be a remote path" (concat (file-remote-p old) (or (file-remote-p new 'localname) new))) +(defun ess-path-get-local-portion (path) + "Obtain the local portion of a (possibly remote) path. +If the string PATH is determined to be a remote path, then the +value of PATH is returned unchanged. Otherwise, the portion of +the string in PATH that represents the local portion of the path +is returned." + (or (file-remote-p path 'localname) path)) + ;; search path (defun ess--mark-search-list-as-changed () "Internal. Mark all the search-list related variables as changed." From 518b5bb11057e117f6377f5ced1b908dd5952d66 Mon Sep 17 00:00:00 2001 From: David Pritchard Date: Sat, 17 Oct 2020 14:27:48 -0400 Subject: [PATCH 03/21] Update `ess-r-package-info` to return remote path --- lisp/ess-r-package.el | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/lisp/ess-r-package.el b/lisp/ess-r-package.el index 397ce14e6..76df7710c 100644 --- a/lisp/ess-r-package.el +++ b/lisp/ess-r-package.el @@ -126,12 +126,9 @@ efficiency reasons." (let* ((path (ess-r-package--find-package-path (or dir default-directory))) (name (when path (ess-r-package--find-package-name path))) - (local (if (and path (file-remote-p path)) - (tramp-file-name-localname (tramp-dissect-file-name path)) - path)) (info (if name (list :name name - :root local) + :root path) '(nil)))) ;; If DIR was supplied we cannot cache in the current buffer. (if dir From e15b5d6f23b3190b102f5c9b8fda126658fd7eac Mon Sep 17 00:00:00 2001 From: David Pritchard Date: Sun, 18 Oct 2020 10:46:06 -0400 Subject: [PATCH 04/21] Add a test for `ess-r-package-info` on a remote --- test/ess-test-r-package.el | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/ess-test-r-package.el b/test/ess-test-r-package.el index 604c207a2..6b7390ecf 100644 --- a/test/ess-test-r-package.el +++ b/test/ess-test-r-package.el @@ -102,6 +102,11 @@ (should (string= (plist-get pkg-info :name) "foo")) (should (string-match-p "dummy-pkg$" (plist-get pkg-info :root))) (kill-buffer))) + (with-ess-test-r-file (ess-test-make-remote-path "dummy-pkg/R/test.R") + (let ((pkg-info (ess-r-package-info))) + (should (string= (plist-get pkg-info :name) "foo")) + (should (string-match-p "^/mock:.*dummy-pkg$" (plist-get pkg-info :root))) + (kill-buffer))) (with-ess-test-c-file "dummy-pkg/src/test.c" (let ((pkg-info (ess-r-package-info))) (should (string= (plist-get pkg-info :name) "foo")) From 683ba9213677d18a3578106629871d4cec38f8e7 Mon Sep 17 00:00:00 2001 From: David Pritchard Date: Sat, 17 Oct 2020 14:29:08 -0400 Subject: [PATCH 05/21] Update callers of `ess-r-package-info` Updates `ess-r-package-use-dir` and `ess-r-package-eval-linewise`. --- lisp/ess-r-package.el | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lisp/ess-r-package.el b/lisp/ess-r-package.el index 76df7710c..8588caf3a 100644 --- a/lisp/ess-r-package.el +++ b/lisp/ess-r-package.el @@ -216,9 +216,11 @@ DIR defaults to the current buffer's file name (if non-nil) or "Set process directory to current package directory." (interactive) (let ((pkg-root (plist-get (ess-r-package-info) :root))) - (if pkg-root - (ess-set-working-directory (abbreviate-file-name pkg-root)) - (user-error "Not in a project")))) + (unless pkg-root + (user-error "Not in a project")) + (let* ((lpath (ess-path-get-local-portion pkg-root)) + (lpath-abbreviated (abbreviate-file-name lpath))) + (ess-set-working-directory lpath-abbreviated)))) ;;;*;;; Evaluation @@ -259,7 +261,8 @@ arguments, or expressions which return R arguments." (ess-project-save-buffers) (message msg (plist-get pkg-info :name)) (display-buffer (ess-get-process-buffer)) - (let ((pkg-path (concat "'" (abbreviate-file-name (plist-get pkg-info :root)) "'"))) + (let* ((lpath (ess-path-get-local-portion (plist-get pkg-info :root))) + (pkg-path (concat "'" (abbreviate-file-name lpath) "'"))) (ess-eval-linewise (format command (concat pkg-path args)))))) (defun ess-r-command--build-args (ix &optional actions) From 059114290e2e1d141d67e3d3779aadd36a1e047d Mon Sep 17 00:00:00 2001 From: David Pritchard Date: Sun, 17 Jan 2021 14:42:41 -0500 Subject: [PATCH 06/21] Update `ess--derive-connection-path` to use helper --- lisp/ess-inf.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lisp/ess-inf.el b/lisp/ess-inf.el index 7c8632a32..d09a484e4 100644 --- a/lisp/ess-inf.el +++ b/lisp/ess-inf.el @@ -2918,7 +2918,7 @@ path), in such a way that the host and connection information (if any) in OLD is retained in the NEW path. NEW must be an absolute path, and can be a remote path" (concat (file-remote-p old) - (or (file-remote-p new 'localname) new))) + (ess-path-get-local-portion new))) (defun ess-path-get-local-portion (path) "Obtain the local portion of a (possibly remote) path. From 265cdf4827576e2261ca9fd21e9a6c1a9935584b Mon Sep 17 00:00:00 2001 From: David Pritchard Date: Tue, 19 Jan 2021 12:15:49 -0500 Subject: [PATCH 07/21] Add test for `ess-r-package-use-dir` --- test/ess-test-r-package.el | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/test/ess-test-r-package.el b/test/ess-test-r-package.el index 6b7390ecf..fc27fe38d 100644 --- a/test/ess-test-r-package.el +++ b/test/ess-test-r-package.el @@ -113,6 +113,25 @@ (should (string-match-p "dummy-pkg$" (plist-get pkg-info :root))) (kill-buffer))))) +(ert-deftest ess-r-package-use-dir-test () + (with-ess-test-r-file "dummy-pkg/R/test.R" + (ess-set-working-directory "/") + (ess-wait-for-process) + (should (string= (ess-get-working-directory) "/")) + (ess-r-package-use-dir) + (ess-wait-for-process) + (should (string-match-p "dummy-pkg$" (ess-get-working-directory))) + (kill-buffer)) + (with-ess-test-r-file (ess-test-make-remote-path "dummy-pkg/R/test.R") + (should (string-match-p "/mock:.*/dummy-pkg/R/test.R" buffer-file-name)) + (ess-set-working-directory "/") + (ess-wait-for-process) + (should (string= (ess-get-working-directory) "/")) + (ess-r-package-use-dir) + (ess-wait-for-process) + (should (string-match-p "dummy-pkg$" (ess-get-working-directory))) + (kill-buffer))) + (provide 'ess-test-r-package) ;;; ess-test-r-package.el ends here From 7864cc4cd4edd4ba028da55f2aef21eb0be66bb1 Mon Sep 17 00:00:00 2001 From: David Pritchard Date: Wed, 20 Jan 2021 18:03:48 -0500 Subject: [PATCH 08/21] Fix `ess-path-get-local-portion` docstring --- lisp/ess-inf.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lisp/ess-inf.el b/lisp/ess-inf.el index d09a484e4..5887c2adc 100644 --- a/lisp/ess-inf.el +++ b/lisp/ess-inf.el @@ -2922,7 +2922,7 @@ path, and can be a remote path" (defun ess-path-get-local-portion (path) "Obtain the local portion of a (possibly remote) path. -If the string PATH is determined to be a remote path, then the +If the string PATH is determined to be a local path, then the value of PATH is returned unchanged. Otherwise, the portion of the string in PATH that represents the local portion of the path is returned." From 937317287e44f9ab458dbca8a87103f6107ad7f1 Mon Sep 17 00:00:00 2001 From: David Pritchard Date: Wed, 20 Jan 2021 18:08:49 -0500 Subject: [PATCH 09/21] Add test for `ess--path-get-local-portion-test` --- test/ess-test-inf.el | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/test/ess-test-inf.el b/test/ess-test-inf.el index 7c0763c6e..b5f922470 100644 --- a/test/ess-test-inf.el +++ b/test/ess-test-inf.el @@ -394,7 +394,7 @@ some. text (should (cl-every #'string= (ess-get-words-from-vector "c('aaa','bbb\"ccc', 'dddd')\n") '("aaa" "bbb\\\"ccc" "dddd"))))) -(ert-deftest ess--derive-connection-path () +(ert-deftest ess--derive-connection-path-test () (let* ((old-localname "/path/to/file") (new-localname "/home/username/projects") (connection-basic "/ssh:melancholia.danann.net:") @@ -424,6 +424,10 @@ some. text (should (funcall check-new-remotepath "")) (should (funcall check-new-remotepath connection-basic)))) +(ert-deftest ess-path-get-local-portion-test () + (should (string= "/path/to/file" (ess-path-get-local-portion "/path/to/file"))) + (should (string= "/some/file" (ess-path-get-local-portion "/ssh:melancholia.danann.net:/some/file")))) + ;; Test runners ;; Note that we add R-3.2.1 to continuous integration via a symlink to From 028d0f1a73a7ec9203f590112a184180475f9423 Mon Sep 17 00:00:00 2001 From: David Pritchard Date: Wed, 20 Jan 2021 21:15:00 -0500 Subject: [PATCH 10/21] Make `ess-r-package-info` internal --- lisp/ess-inf.el | 4 ++-- lisp/ess-r-package.el | 4 ++-- test/ess-test-inf.el | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lisp/ess-inf.el b/lisp/ess-inf.el index 5887c2adc..de8be961a 100644 --- a/lisp/ess-inf.el +++ b/lisp/ess-inf.el @@ -2918,9 +2918,9 @@ path), in such a way that the host and connection information (if any) in OLD is retained in the NEW path. NEW must be an absolute path, and can be a remote path" (concat (file-remote-p old) - (ess-path-get-local-portion new))) + (ess--path-get-local-portion new))) -(defun ess-path-get-local-portion (path) +(defun ess--path-get-local-portion (path) "Obtain the local portion of a (possibly remote) path. If the string PATH is determined to be a local path, then the value of PATH is returned unchanged. Otherwise, the portion of diff --git a/lisp/ess-r-package.el b/lisp/ess-r-package.el index 8588caf3a..8ae3e3be0 100644 --- a/lisp/ess-r-package.el +++ b/lisp/ess-r-package.el @@ -218,7 +218,7 @@ DIR defaults to the current buffer's file name (if non-nil) or (let ((pkg-root (plist-get (ess-r-package-info) :root))) (unless pkg-root (user-error "Not in a project")) - (let* ((lpath (ess-path-get-local-portion pkg-root)) + (let* ((lpath (ess--path-get-local-portion pkg-root)) (lpath-abbreviated (abbreviate-file-name lpath))) (ess-set-working-directory lpath-abbreviated)))) @@ -261,7 +261,7 @@ arguments, or expressions which return R arguments." (ess-project-save-buffers) (message msg (plist-get pkg-info :name)) (display-buffer (ess-get-process-buffer)) - (let* ((lpath (ess-path-get-local-portion (plist-get pkg-info :root))) + (let* ((lpath (ess--path-get-local-portion (plist-get pkg-info :root))) (pkg-path (concat "'" (abbreviate-file-name lpath) "'"))) (ess-eval-linewise (format command (concat pkg-path args)))))) diff --git a/test/ess-test-inf.el b/test/ess-test-inf.el index b5f922470..62d173079 100644 --- a/test/ess-test-inf.el +++ b/test/ess-test-inf.el @@ -424,9 +424,9 @@ some. text (should (funcall check-new-remotepath "")) (should (funcall check-new-remotepath connection-basic)))) -(ert-deftest ess-path-get-local-portion-test () - (should (string= "/path/to/file" (ess-path-get-local-portion "/path/to/file"))) - (should (string= "/some/file" (ess-path-get-local-portion "/ssh:melancholia.danann.net:/some/file")))) +(ert-deftest ess--path-get-local-portion-test () + (should (string= "/path/to/file" (ess--path-get-local-portion "/path/to/file"))) + (should (string= "/some/file" (ess--path-get-local-portion "/ssh:melancholia.danann.net:/some/file")))) ;; Test runners From bf811d0802c6b22e8fc643319b9ceb599a729f57 Mon Sep 17 00:00:00 2001 From: David Pritchard Date: Wed, 20 Jan 2021 23:30:39 -0500 Subject: [PATCH 11/21] Add test for `inferior-ess-r--adjust-startup-directory` --- test/ess-test-r-package.el | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/test/ess-test-r-package.el b/test/ess-test-r-package.el index fc27fe38d..c3f9b626a 100644 --- a/test/ess-test-r-package.el +++ b/test/ess-test-r-package.el @@ -132,6 +132,21 @@ (should (string-match-p "dummy-pkg$" (ess-get-working-directory))) (kill-buffer))) +;; Return DIR unless both (i) DIR is the path of package root directory and (ii) +;; the buffer file name is in the tests/ package directory. When both (i) and +;; (ii) hold then return the path corresponding to tests/. +(ert-deftest inferior-ess-r--adjust-startup-directory-test () + (with-ess-test-r-file (ess-test-make-remote-path "dummy-pkg/tests/example.R") + (let* ((pkg-dir (plist-get (ess-r-package-info) :root)) + (inst-dir (expand-file-name "inst" pkg-dir))) ;; arbitrary non-package root directory choice + (should (string-match-p "^/mock:.*/dummy-pkg/tests/$" default-directory)) + (should (string-match-p "^/mock:.*/dummy-pkg$" pkg-dir)) + (should (string= inst-dir + (inferior-ess-r--adjust-startup-directory inst-dir "R"))) + (should (string= default-directory + (inferior-ess-r--adjust-startup-directory pkg-dir "R")))) + (kill-buffer))) + (provide 'ess-test-r-package) ;;; ess-test-r-package.el ends here From a7b689e3c923171f59e43ab8e48d2e53e2a5b605 Mon Sep 17 00:00:00 2001 From: David Pritchard Date: Sun, 24 Jan 2021 18:18:38 -0500 Subject: [PATCH 12/21] Add test for `ess-r-package-eval-linewise` --- test/ess-test-r-package.el | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/test/ess-test-r-package.el b/test/ess-test-r-package.el index c3f9b626a..2b54d648e 100644 --- a/test/ess-test-r-package.el +++ b/test/ess-test-r-package.el @@ -147,6 +147,23 @@ (inferior-ess-r--adjust-startup-directory pkg-dir "R")))) (kill-buffer))) +(ert-deftest ess-r-package-eval-linewise-test () + (let ((output-regex "^# '.*/dummy-pkg'$")) + ;; Test with an R package on a local filesystem + (with-ess-test-r-file "dummy-pkg/R/test.R" + (with-r-running (current-buffer) + (let ((actual (output (ess-r-package-eval-linewise "# %s")))) + (should (string-match-p output-regex actual)))) + (kill-buffer)) + ;; Test with an R package on a remote filesystem. The remote prefix portion + ;; of the package location should be stripped from the command. + (with-ess-test-r-file (ess-test-make-remote-path "dummy-pkg/R/test.R") + (with-r-running (current-buffer) + (should (string-match-p "^/mock:.*/dummy-pkg/R/test.R$" buffer-file-name)) + (let ((actual (output (ess-r-package-eval-linewise "# %s")))) + (should (string-match-p output-regex actual)) + (should (not (string-match-p "/mock:" actual))))) + (kill-buffer)))) (provide 'ess-test-r-package) ;;; ess-test-r-package.el ends here From d02b6f057c54b30ed10582cbe40a1ebb0f35f4dd Mon Sep 17 00:00:00 2001 From: David Pritchard Date: Sun, 24 Jan 2021 18:19:48 -0500 Subject: [PATCH 13/21] Add test for `ert-deftest ess-r--flymake-parse-output` --- test/ess-test-r-package.el | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/test/ess-test-r-package.el b/test/ess-test-r-package.el index 2b54d648e..461702d45 100644 --- a/test/ess-test-r-package.el +++ b/test/ess-test-r-package.el @@ -164,6 +164,26 @@ (should (string-match-p output-regex actual)) (should (not (string-match-p "/mock:" actual))))) (kill-buffer)))) + +(ert-deftest ess-r--flymake-parse-output-test () + (with-ess-test-r-file (ess-test-make-remote-path "dummy-pkg/R/test.R") + (let ((ess-proj-file (expand-file-name "../.lintr")) + (cur-dir-file (expand-file-name ".lintr"))) + ;; no .lintr file + (should (null (ess-r--find-lintr-file))) + ;; .lintr file in the package directory + (write-region "" nil ess-proj-file) + (let ((actual (ess-r--find-lintr-file))) + (should (string-match-p "^/mock:.*/dummy-pkg/\\.lintr$" actual))) + ;; .lintr file in the current directory takes precedence over any other + ;; locations + (write-region "" nil cur-dir-file) + (let ((actual (ess-r--find-lintr-file))) + (should (string-match-p "^/mock:.*/dummy-pkg/R/\\.lintr$" actual))) + ;; clean up created files + (delete-file ess-proj-file) + (delete-file cur-dir-file)))) + (provide 'ess-test-r-package) ;;; ess-test-r-package.el ends here From ce7eee8a939359d42b1f013b485f1f6a3b3783dc Mon Sep 17 00:00:00 2001 From: David Pritchard Date: Sun, 24 Jan 2021 21:47:16 -0500 Subject: [PATCH 14/21] Add test for `ess-r-package-project` --- test/ess-test-r-package.el | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/ess-test-r-package.el b/test/ess-test-r-package.el index 461702d45..c84298f8f 100644 --- a/test/ess-test-r-package.el +++ b/test/ess-test-r-package.el @@ -113,6 +113,18 @@ (should (string-match-p "dummy-pkg$" (plist-get pkg-info :root))) (kill-buffer))))) +(ert-deftest ess-r-package-project-test () + (with-ess-test-r-file "dummy-pkg/R/test.R" + (let ((project-info (ess-r-package-project))) + (should (equal 'ess-r-package (car project-info))) + (should (string-match-p "dummy-pkg$" (cdr project-info))) + (kill-buffer))) + (with-ess-test-r-file (ess-test-make-remote-path "dummy-pkg/R/test.R") + (let ((project-info (ess-r-package-project))) + (should (equal 'ess-r-package (car project-info))) + (should (string-match-p "^/mock:.*dummy-pkg$" (cdr project-info))) + (kill-buffer)))) + (ert-deftest ess-r-package-use-dir-test () (with-ess-test-r-file "dummy-pkg/R/test.R" (ess-set-working-directory "/") From 13e6965a1b832d7ada41ec864747ac31acd284a3 Mon Sep 17 00:00:00 2001 From: David Pritchard Date: Sun, 24 Jan 2021 23:04:39 -0500 Subject: [PATCH 15/21] Add test for `ess-r-package-source-dirs` --- test/ess-test-r-package.el | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/test/ess-test-r-package.el b/test/ess-test-r-package.el index c84298f8f..150492008 100644 --- a/test/ess-test-r-package.el +++ b/test/ess-test-r-package.el @@ -159,6 +159,20 @@ (inferior-ess-r--adjust-startup-directory pkg-dir "R")))) (kill-buffer))) +(ert-deftest ess-r-package-source-dirs-test () + (with-ess-test-r-file "dummy-pkg/R/test.R" + (let ((source-dirs (ess-r-package-source-dirs))) + (should (string-match-p ".*/dummy-pkg/R$" (car source-dirs))) + (should (string-match-p ".*/dummy-pkg/src$" (car (cdr source-dirs)))) + (should (null (cdr (cdr source-dirs)))) + (kill-buffer))) + (with-ess-test-r-file (ess-test-make-remote-path "dummy-pkg/R/test.R") + (let ((source-dirs (ess-r-package-source-dirs))) + (should (string-match-p "^/mock:.*/dummy-pkg/R$" (car source-dirs))) + (should (string-match-p "^/mock:.*/dummy-pkg/src$" (car (cdr source-dirs)))) + (should (null (cdr (cdr source-dirs)))) + (kill-buffer)))) + (ert-deftest ess-r-package-eval-linewise-test () (let ((output-regex "^# '.*/dummy-pkg'$")) ;; Test with an R package on a local filesystem From 1bdad4ce14a70696fd85477139133165d3355fda Mon Sep 17 00:00:00 2001 From: David Pritchard Date: Sun, 24 Jan 2021 23:06:06 -0500 Subject: [PATCH 16/21] Change the name of 'ess-test-make-remote-path' The new name is `ess-test-create-remote-path`. --- test/ess-test-r-package.el | 14 +++++++------- test/ess-test-r-utils.el | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/test/ess-test-r-package.el b/test/ess-test-r-package.el index 150492008..104fc4e8c 100644 --- a/test/ess-test-r-package.el +++ b/test/ess-test-r-package.el @@ -102,7 +102,7 @@ (should (string= (plist-get pkg-info :name) "foo")) (should (string-match-p "dummy-pkg$" (plist-get pkg-info :root))) (kill-buffer))) - (with-ess-test-r-file (ess-test-make-remote-path "dummy-pkg/R/test.R") + (with-ess-test-r-file (ess-test-create-remote-path "dummy-pkg/R/test.R") (let ((pkg-info (ess-r-package-info))) (should (string= (plist-get pkg-info :name) "foo")) (should (string-match-p "^/mock:.*dummy-pkg$" (plist-get pkg-info :root))) @@ -119,7 +119,7 @@ (should (equal 'ess-r-package (car project-info))) (should (string-match-p "dummy-pkg$" (cdr project-info))) (kill-buffer))) - (with-ess-test-r-file (ess-test-make-remote-path "dummy-pkg/R/test.R") + (with-ess-test-r-file (ess-test-create-remote-path "dummy-pkg/R/test.R") (let ((project-info (ess-r-package-project))) (should (equal 'ess-r-package (car project-info))) (should (string-match-p "^/mock:.*dummy-pkg$" (cdr project-info))) @@ -134,7 +134,7 @@ (ess-wait-for-process) (should (string-match-p "dummy-pkg$" (ess-get-working-directory))) (kill-buffer)) - (with-ess-test-r-file (ess-test-make-remote-path "dummy-pkg/R/test.R") + (with-ess-test-r-file (ess-test-create-remote-path "dummy-pkg/R/test.R") (should (string-match-p "/mock:.*/dummy-pkg/R/test.R" buffer-file-name)) (ess-set-working-directory "/") (ess-wait-for-process) @@ -148,7 +148,7 @@ ;; the buffer file name is in the tests/ package directory. When both (i) and ;; (ii) hold then return the path corresponding to tests/. (ert-deftest inferior-ess-r--adjust-startup-directory-test () - (with-ess-test-r-file (ess-test-make-remote-path "dummy-pkg/tests/example.R") + (with-ess-test-r-file (ess-test-create-remote-path "dummy-pkg/tests/example.R") (let* ((pkg-dir (plist-get (ess-r-package-info) :root)) (inst-dir (expand-file-name "inst" pkg-dir))) ;; arbitrary non-package root directory choice (should (string-match-p "^/mock:.*/dummy-pkg/tests/$" default-directory)) @@ -166,7 +166,7 @@ (should (string-match-p ".*/dummy-pkg/src$" (car (cdr source-dirs)))) (should (null (cdr (cdr source-dirs)))) (kill-buffer))) - (with-ess-test-r-file (ess-test-make-remote-path "dummy-pkg/R/test.R") + (with-ess-test-r-file (ess-test-create-remote-path "dummy-pkg/R/test.R") (let ((source-dirs (ess-r-package-source-dirs))) (should (string-match-p "^/mock:.*/dummy-pkg/R$" (car source-dirs))) (should (string-match-p "^/mock:.*/dummy-pkg/src$" (car (cdr source-dirs)))) @@ -183,7 +183,7 @@ (kill-buffer)) ;; Test with an R package on a remote filesystem. The remote prefix portion ;; of the package location should be stripped from the command. - (with-ess-test-r-file (ess-test-make-remote-path "dummy-pkg/R/test.R") + (with-ess-test-r-file (ess-test-create-remote-path "dummy-pkg/R/test.R") (with-r-running (current-buffer) (should (string-match-p "^/mock:.*/dummy-pkg/R/test.R$" buffer-file-name)) (let ((actual (output (ess-r-package-eval-linewise "# %s")))) @@ -192,7 +192,7 @@ (kill-buffer)))) (ert-deftest ess-r--flymake-parse-output-test () - (with-ess-test-r-file (ess-test-make-remote-path "dummy-pkg/R/test.R") + (with-ess-test-r-file (ess-test-create-remote-path "dummy-pkg/R/test.R") (let ((ess-proj-file (expand-file-name "../.lintr")) (cur-dir-file (expand-file-name ".lintr"))) ;; no .lintr file diff --git a/test/ess-test-r-utils.el b/test/ess-test-r-utils.el index 097aea808..7012228d5 100644 --- a/test/ess-test-r-utils.el +++ b/test/ess-test-r-utils.el @@ -329,7 +329,7 @@ representative to the common interactive use with tracebug on." (format "/mock::%s" temporary-file-directory))) "Temporary directory for Tramp tests.") -(defun ess-test-make-remote-path (path) +(defun ess-test-create-remote-path (path) "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." From 8590573c886a09e1da619537a19c12a05d606e78 Mon Sep 17 00:00:00 2001 From: David Pritchard Date: Sun, 24 Jan 2021 23:55:50 -0500 Subject: [PATCH 17/21] Add test for `ert-deftest ess-r-package-save-buffers` --- test/ess-test-r-package.el | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/test/ess-test-r-package.el b/test/ess-test-r-package.el index 104fc4e8c..50a21e4a1 100644 --- a/test/ess-test-r-package.el +++ b/test/ess-test-r-package.el @@ -173,6 +173,40 @@ (should (null (cdr (cdr source-dirs)))) (kill-buffer)))) +(ert-deftest ess-r-package-save-buffers-test () + ;; modify a file within an R package and try to save it + (with-ess-test-r-file "dummy-pkg/R/test.R" + (let ((new-path (expand-file-name "tmp.R"))) + (write-region "" nil new-path) + (find-file new-path) + (should (string-match-p ".*/dummy-pkg/R/tmp.R$" buffer-file-name)) + (should (not (buffer-modified-p))) + (insert "# buffer update") + (should (buffer-modified-p)) + (let ((ess-save-silently t)) + (ess-project-save-buffers) + (should (string-match-p ".*/dummy-pkg/R/tmp.R$" buffer-file-name)) + (should (not (buffer-modified-p)))) + (kill-buffer "test.R") + (kill-buffer "tmp.R") + (delete-file new-path))) + ;; modify a file within an R package with a remote path and try to save it + (with-ess-test-r-file (ess-test-create-remote-path "dummy-pkg/R/test.R") + (let ((new-path (expand-file-name "tmp.R"))) + (write-region "" nil new-path) + (find-file new-path) + (should (string-match-p "^/mock:.*/dummy-pkg/R/tmp.R$" buffer-file-name)) + (should (not (buffer-modified-p))) + (insert "# buffer update") + (should (buffer-modified-p)) + (let ((ess-save-silently t)) + (ess-project-save-buffers) + (should (string-match-p "^/mock:.*/dummy-pkg/R/tmp.R$" buffer-file-name)) + (should (not (buffer-modified-p)))) + (kill-buffer "test.R") + (kill-buffer "tmp.R") + (delete-file new-path)))) + (ert-deftest ess-r-package-eval-linewise-test () (let ((output-regex "^# '.*/dummy-pkg'$")) ;; Test with an R package on a local filesystem From c487146d2d4c0b5391ab54c6cd2c426306509e0c Mon Sep 17 00:00:00 2001 From: David Pritchard Date: Mon, 25 Jan 2021 00:16:47 -0500 Subject: [PATCH 18/21] Require tramp in ess-test-r-utils.el This is because we are appending an element to a Tramp variable in the file. --- test/ess-test-r-utils.el | 1 + 1 file changed, 1 insertion(+) diff --git a/test/ess-test-r-utils.el b/test/ess-test-r-utils.el index 7012228d5..f88f572ea 100644 --- a/test/ess-test-r-utils.el +++ b/test/ess-test-r-utils.el @@ -20,6 +20,7 @@ (require 'ert) (require 'etest) (require 'ess-r-mode) +(require 'tramp) (defvar ess-test-fixtures-directory (expand-file-name "fixtures" From 58cea5a1fe63af640ac365d0172bbaaf7bb23f18 Mon Sep 17 00:00:00 2001 From: David Pritchard Date: Sun, 31 Jan 2021 17:02:42 -0500 Subject: [PATCH 19/21] Remove unnecessary Tramp mock code --- test/ess-test-r-utils.el | 31 +++++++++---------------------- 1 file changed, 9 insertions(+), 22 deletions(-) diff --git a/test/ess-test-r-utils.el b/test/ess-test-r-utils.el index f88f572ea..48177faa4 100644 --- a/test/ess-test-r-utils.el +++ b/test/ess-test-r-utils.el @@ -307,28 +307,15 @@ representative to the common interactive use with tracebug on." ;; Define a mock TRAMP method to use for testing. This code is taken from ;; `tramp-tests.el'. -(defconst tramp-test-temporary-file-directory - (cond - ((getenv "REMOTE_TEMPORARY_FILE_DIRECTORY")) - ((eq system-type 'windows-nt) null-device) - (t (add-to-list - 'tramp-methods - '("mock" - (tramp-login-program "sh") - (tramp-login-args (("-i"))) - (tramp-direct-async-args (("-c"))) - (tramp-remote-shell "/bin/sh") - (tramp-remote-shell-args ("-c")) - (tramp-connection-timeout 10))) - (add-to-list - 'tramp-default-host-alist - `("\\`mock\\'" nil ,(system-name))) - ;; Emacs's Makefile sets $HOME to a nonexistent value. Needed - ;; in batch mode only, therefore. - (unless (and (null noninteractive) (file-directory-p "~/")) - (setenv "HOME" temporary-file-directory)) - (format "/mock::%s" temporary-file-directory))) - "Temporary directory for Tramp tests.") +(add-to-list + 'tramp-methods + '("mock" + (tramp-login-program "sh") + (tramp-login-args (("-i"))) + (tramp-direct-async-args (("-c"))) + (tramp-remote-shell "/bin/sh") + (tramp-remote-shell-args ("-c")) + (tramp-connection-timeout 10))) (defun ess-test-create-remote-path (path) "Construct a remote path using the 'mock' TRAMP method. From 218b692e20a4fad3da7d9e9f36ed91751331c083 Mon Sep 17 00:00:00 2001 From: David Pritchard Date: Sun, 31 Jan 2021 18:06:36 -0500 Subject: [PATCH 20/21] Use `with-r-running` in `ess-r-package-use-dir-test` --- test/ess-test-r-package.el | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/test/ess-test-r-package.el b/test/ess-test-r-package.el index 50a21e4a1..eeaeee571 100644 --- a/test/ess-test-r-package.el +++ b/test/ess-test-r-package.el @@ -127,22 +127,24 @@ (ert-deftest ess-r-package-use-dir-test () (with-ess-test-r-file "dummy-pkg/R/test.R" - (ess-set-working-directory "/") - (ess-wait-for-process) - (should (string= (ess-get-working-directory) "/")) - (ess-r-package-use-dir) - (ess-wait-for-process) - (should (string-match-p "dummy-pkg$" (ess-get-working-directory))) + (with-r-running (current-buffer) + (ess-set-working-directory "/") + (ess-wait-for-process) + (should (string= (ess-get-working-directory) "/")) + (ess-r-package-use-dir) + (ess-wait-for-process) + (should (string-match-p "dummy-pkg$" (ess-get-working-directory)))) (kill-buffer)) (with-ess-test-r-file (ess-test-create-remote-path "dummy-pkg/R/test.R") - (should (string-match-p "/mock:.*/dummy-pkg/R/test.R" buffer-file-name)) - (ess-set-working-directory "/") - (ess-wait-for-process) - (should (string= (ess-get-working-directory) "/")) - (ess-r-package-use-dir) - (ess-wait-for-process) - (should (string-match-p "dummy-pkg$" (ess-get-working-directory))) - (kill-buffer))) + (with-r-running (current-buffer) + (should (string-match-p "/mock:.*/dummy-pkg/R/test.R" buffer-file-name)) + (ess-set-working-directory "/") + (ess-wait-for-process) + (should (string= (ess-get-working-directory) "/")) + (ess-r-package-use-dir) + (ess-wait-for-process) + (should (string-match-p "dummy-pkg$" (ess-get-working-directory))) + (kill-buffer)))) ;; Return DIR unless both (i) DIR is the path of package root directory and (ii) ;; the buffer file name is in the tests/ package directory. When both (i) and From 8fc7fddcc5664497ed1e6a0026011307f5efee0c Mon Sep 17 00:00:00 2001 From: David Pritchard Date: Sun, 31 Jan 2021 22:13:10 -0500 Subject: [PATCH 21/21] Load ess-r-flymake in R package tests --- test/ess-test-r-package.el | 1 + 1 file changed, 1 insertion(+) diff --git a/test/ess-test-r-package.el b/test/ess-test-r-package.el index eeaeee571..77ca75c2c 100644 --- a/test/ess-test-r-package.el +++ b/test/ess-test-r-package.el @@ -19,6 +19,7 @@ (require 'ert) (require 'ess-r-mode) (require 'ess-r-package) +(require 'ess-r-flymake) (require 'ess-test-r-utils) ;;; Code: