[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/urgrep f50f31d37d 3/6: Add tests for Eshell integration
From: |
ELPA Syncer |
Subject: |
[elpa] externals/urgrep f50f31d37d 3/6: Add tests for Eshell integration |
Date: |
Wed, 7 Jun 2023 16:00:32 -0400 (EDT) |
branch: externals/urgrep
commit f50f31d37d7a9e6cb09cb4caf8cebc7651763187
Author: Jim Porter <jporterbugs@gmail.com>
Commit: Jim Porter <jporterbugs@gmail.com>
Add tests for Eshell integration
---
urgrep-tests.el | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 58 insertions(+), 1 deletion(-)
diff --git a/urgrep-tests.el b/urgrep-tests.el
index 867575baa0..e3dfe8c777 100644
--- a/urgrep-tests.el
+++ b/urgrep-tests.el
@@ -29,14 +29,17 @@
(require 'compat)
(require 'ert)
+(require 'eshell)
+(require 'esh-mode)
(require 'tramp)
(require 'urgrep)
+;; Work around Emacs bug#58265.
(let ((orig-home (getenv "HOME")))
(require 'ert-x)
- ;; Work around Emacs bug#58265.
(when (< emacs-major-version 29)
(setenv "HOME" orig-home)))
+(eval-when-compile (require 'ert-x))
(defun urgrep-tests/remote-accessible-p ()
"Return whether a test involving remote files can proceed."
@@ -70,6 +73,47 @@ joined to compare against COMMAND."
(should (equal (compilation--loc->col loc)
(- match-start text-start)))))
+;; Eshell utilities:
+
+;; These are adapted from test/lisp/eshell/eshell-tests-helpers.el in Emacs.
+
+(defvar eshell-history-file-name)
+(defvar eshell-last-dir-ring-file-name)
+
+(defmacro with-temp-eshell (&rest body)
+ "Evaluate BODY in a temporary Eshell buffer."
+ `(save-current-buffer
+ (ert-with-temp-directory eshell-directory-name
+ (let* (;; We want no history file, so prevent Eshell from falling
+ ;; back on $HISTFILE.
+ (process-environment (cons "HISTFILE" process-environment))
+ (eshell-history-file-name nil)
+ (eshell-last-dir-ring-file-name nil)
+ (eshell-buffer (eshell t)))
+ (unwind-protect
+ (with-current-buffer eshell-buffer
+ ,@body)
+ (let (kill-buffer-query-functions)
+ (kill-buffer eshell-buffer)))))))
+
+(defun eshell-match-command-output (command regexp)
+ "Insert a COMMAND at the end of the buffer and match the output with REGEXP."
+ ;; Execute COMMAND.
+ (goto-char eshell-last-output-end)
+ (insert-and-inherit command)
+ (eshell-send-input)
+ ;; Wait until the command has completed.
+ (let ((start (current-time)))
+ (while (eshell-interactive-process)
+ (when (> (float-time (time-since start)) 5)
+ (error "timeout"))
+ (accept-process-output)))
+ ;; Check the result.
+ (should (string-match-p regexp
+ (buffer-substring-no-properties
+ (eshell-beginning-of-output)
+ (eshell-end-of-output)))))
+
;;; Tests:
(ert-deftest urgrep-tests/common-prefix ()
@@ -610,4 +654,17 @@ joined to compare against COMMAND."
(beginning-of-line 2)
(urgrep-tests/check-match-at-point))
+(ert-deftest urgrep-tests/eshell/urgrep-buffer ()
+ (with-temp-eshell
+ (eshell-match-command-output "urgrep universal" "\\`#<buffer .*>\n")
+ (with-current-buffer eshell-last-command-result
+ (while (get-buffer-process (current-buffer))
+ (accept-process-output))
+ (should (eq major-mode #'urgrep-mode)))))
+
+(ert-deftest urgrep-tests/eshell/inline ()
+ (skip-unless (executable-find "cat"))
+ (with-temp-eshell
+ (eshell-match-command-output "urgrep universal | cat" "^README.md\n")))
+
;;; urgrep-tests.el ends here
- [elpa] externals/urgrep updated (243501d797 -> 48e02f2e41), ELPA Syncer, 2023/06/07
- [elpa] externals/urgrep f50f31d37d 3/6: Add tests for Eshell integration,
ELPA Syncer <=
- [elpa] externals/urgrep 5284789367 4/6: Update NEWS, ELPA Syncer, 2023/06/07
- [elpa] externals/urgrep 48e02f2e41 6/6: Update version to 0.1.2-git, ELPA Syncer, 2023/06/07
- [elpa] externals/urgrep c63f893250 1/6: Allow running tests without compiling, ELPA Syncer, 2023/06/07
- [elpa] externals/urgrep 1924e175a5 5/6: Update version to v0.1.1, ELPA Syncer, 2023/06/07
- [elpa] externals/urgrep e33a953b72 2/6: Use `accept-process-output` instead of `sit-for`, ELPA Syncer, 2023/06/07