[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/bash-completion b4ae893243 268/313: Test prompt and histor
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/bash-completion b4ae893243 268/313: Test prompt and history manipulation, fix $? in prompt. |
Date: |
Sat, 3 Dec 2022 10:59:36 -0500 (EST) |
branch: elpa/bash-completion
commit b4ae893243a907849e926b7d9f5555fe635b9644
Author: Stephane Zermatten <stephane@boomer.lan>
Commit: Stephane Zermatten <stephane@boomer.lan>
Test prompt and history manipulation, fix $? in prompt.
This change adds tests to cover:
- PROMPT_COMMAND
- PS1
- history content
in single-process mode.
It also fixes a bug that these tests uncovered, where the value of $?
valid at the time PROMPT_COMMAND was evaluated was incorrect.
---
bash-completion.el | 3 +-
test/bash-completion-integration-test.el | 90 +++++++++++++++++++++++++++++---
2 files changed, 84 insertions(+), 9 deletions(-)
diff --git a/bash-completion.el b/bash-completion.el
index 6f558ed14b..f6aee9e22c 100644
--- a/bash-completion.el
+++ b/bash-completion.el
@@ -1263,11 +1263,12 @@ function __emacs_complete_prompt {
PROMPT_COMMAND=__emacs_complete_recover_prompt
}; \
function __emacs_complete_recover_prompt {
+ local r=$?
PS1=\"${__emacs_complete_ps1}\"
PROMPT_COMMAND=\"${__emacs_complete_pc}\"
unset __emacs_complete_ps1 __emacs_complete_pc
if [[ -n \"$PROMPT_COMMAND\" ]]; then
- eval \"$PROMPT_COMMAND\"
+ (exit $r); eval \"$PROMPT_COMMAND\"
fi
}" process)
(bash-completion--setup-bash-common process))
diff --git a/test/bash-completion-integration-test.el
b/test/bash-completion-integration-test.el
index 6ed2dc1c6f..1056bb73bf 100644
--- a/test/bash-completion-integration-test.el
+++ b/test/bash-completion-integration-test.el
@@ -92,8 +92,7 @@
(setq shell-buffer (shell (generate-new-buffer-name
"*bash-completion_test-with-shell*")))
(with-current-buffer shell-buffer
- (bash-completion--wait-for-regexp
- (get-buffer-process shell-buffer) comint-prompt-regexp 3.0)
+ (bash-completion_test-wait-for-prompt)
(let ((comint-dynamic-complete-functions
'(bash-completion-dynamic-complete))
(completion-at-point-functions '(comint-completion-at-point
t)))
(progn ,@body))))
@@ -116,14 +115,24 @@
(buffer-substring-no-properties
(line-beginning-position) (point)))
-(defun bash-completion_test-send (command)
+(defun bash-completion_test-send (command &optional complete)
"Execute COMMAND in a shell buffer."
(goto-char (point-max))
- (delete-region (line-beginning-position) (line-end-position))
- (insert command)
- (comint-send-input)
+ (let ((command-start (point)))
+ (delete-region (line-beginning-position) (line-end-position))
+ (insert command)
+ (when complete (completion-at-point))
+ (comint-send-input)
+ (bash-completion_test-wait-for-prompt command-start)))
+
+(defun bash-completion_test-wait-for-prompt (&optional limit)
(bash-completion--wait-for-regexp
- (get-buffer-process (current-buffer)) comint-prompt-regexp 3.0))
+ (get-buffer-process shell-buffer) comint-prompt-regexp 3.0 limit))
+
+(defun bash-completion_test-buffer-string (&optional start end)
+ (delete-trailing-whitespace (point-min) (point-max))
+ (untabify (point-min) (point-max))
+ (buffer-substring-no-properties (or start (point-min)) (or end (point-max))))
(defun bash-completion_test-candidates (complete-me)
"Complete COMPLETE-ME and returns the candidates."
@@ -143,8 +152,12 @@ for testing completion."
(prog1
test-env-dir
(with-temp-file (expand-file-name "bashrc" test-env-dir)
+ (insert "export PATH=/bin\n")
(insert (format "cd '%s'\n" test-env-dir))
- (insert bashrc))
+ (insert bashrc)
+ (insert "\n")
+ (insert "HISTFILE=/dev/null\n")
+ (insert "history -c\n"))
(let ((default-directory test-env-dir))
(make-directory "some/directory" 'parents)
(make-directory "some/other/directory" 'parents)))))
@@ -454,4 +467,65 @@ for testing completion."
(should (equal "ls \"~/some/" (bash-completion_test-complete "ls \"~/so")))
(should (equal "ls '~/some/" (bash-completion_test-complete "ls '~/so")))))
+(ert-deftest bash-completion-integration-prompt-command ()
+ "Tests PROMPT_COMMAND storage and recovery in single-process mode."
+ (bash-completion_test-with-shell-harness
+ "prompt_count=0
+function _prompt {
+ PS1=\"[$prompt_count]:$? $ \"
+ prompt_count=$(( $prompt_count + 1 ))
+}
+PROMPT_COMMAND=_prompt
+"
+ nil ; use-separate-process
+ (bash-completion_test-send "ls -1 so" 'complete)
+ (bash-completion_test-send "tru" 'complete)
+ (bash-completion_test-send "fals" 'complete)
+ (should (equal
+ (bash-completion_test-buffer-string)
+ "[0]:0 $ ls -1 some/
+directory
+other
+[1]:0 $ true
+[2]:0 $ false
+[3]:1 $ "))))
+
+(ert-deftest bash-completion-integration-ps1 ()
+ "Tests PS1 storage and recovery in single-process mode."
+ (bash-completion_test-with-shell-harness
+ "PS1='$? $ '"
+ nil ; use-separate-process
+ (bash-completion_test-send "ls -1 so" 'complete)
+ (bash-completion_test-send "tru" 'complete)
+ (bash-completion_test-send "fals" 'complete)
+ (should (equal
+ (bash-completion_test-buffer-string)
+ "0 $ ls -1 some/
+directory
+other
+0 $ true
+0 $ false
+1 $ "))))
+
+(ert-deftest bash-completion-integration-prompt-history ()
+ "Tests that history is not polluted by completion."
+ (bash-completion_test-with-shell-harness
+ "PS1='$ '"
+ nil ; use-separate-process
+ (bash-completion_test-send "ls -1 so" 'complete)
+ (bash-completion_test-send "tru" 'complete)
+ (bash-completion_test-send "fals" 'complete)
+ (let ((history-start (line-beginning-position)))
+ (bash-completion_test-send "history")
+ (untabify (point-min) (point-max))
+ (delete-trailing-whitespace (point-min) (point-max))
+ (should (equal
+ (bash-completion_test-buffer-string history-start)
+ "history
+ 1 ls -1 some/
+ 2 true
+ 3 false
+ 4 history
+$ ")))))
+
;;; bash-completion-integration-test.el ends here
- [nongnu] elpa/bash-completion 31a01859b2 227/313: Do not run tests under Emacs 24.1., (continued)
- [nongnu] elpa/bash-completion 31a01859b2 227/313: Do not run tests under Emacs 24.1., ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 21471cc542 228/313: Report result of running the test workflow on README.md., ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 98a2a21be7 234/313: Provide a way of refreshing the completion table., ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 4fcddf83c9 242/313: Make /etc/bash_completion scripts work with escaped spaces., ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 2dbc7e61f6 248/313: Extend bash-completion-refresh to refresh everything, test it., ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 04393bca0f 250/313: Apply filename post-processing even when prefix doesn't match., ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 2a937b3763 255/313: Don't let Emacs post-filter completions built by bash., ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion e95867c993 256/313: completion-table-with-cache captures and restore buffer and variables., ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 747920fdbf 265/313: Avoid having to set BASH_COMPLETION., ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion f15176ee59 267/313: Fix to properly evaluate PROMPT_COMMAND after restoring it., ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion b4ae893243 268/313: Test prompt and history manipulation, fix $? in prompt.,
ELPA Syncer <=
- [nongnu] elpa/bash-completion 20feaf909d 258/313: Fix markdown markup., ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 8713edbb92 269/313: Mention that completion works with bash 5, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 4b80c75c43 272/313: Take current directory from shell when in single-process mode., ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion ea5cc15b99 273/313: Let status code of compgen through when in single-process mode., ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 12da4f0e91 289/313: Better handle slow completion functions., ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 7186a18cad 012/313: Integrated into comm, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion e81c478032 020/313: bash-complete -> bash-completion, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 8270e09294 023/313: pass words as command-line arguments to the function, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 482383dcd7 021/313: handle slash for directory, usable completion, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion cd2ec103d1 026/313: Expand directory names with quotes and spaces, but no further, ELPA Syncer, 2022/12/03