Skip to content

Commit 4c216c4

Browse files
committed
Add an integration test to cover multiple completion results.
1 parent c6decb1 commit 4c216c4

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

test/bash-completion-integration-test.el

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,11 +142,16 @@
142142
(or end (point-max))))
143143

144144
(defun bash-completion_test-candidates (complete-me)
145-
"Complete COMPLETE-ME and returns the candidates."
145+
"Complete COMPLETE-ME and returns the candidates.
146+
147+
The result is sorted to avoid hardcoding arbitrary order in the test."
146148
(goto-char (point-max))
147149
(delete-region (line-beginning-position) (line-end-position))
148150
(insert complete-me)
149-
(nth 2 (bash-completion-dynamic-complete-nocomint)))
151+
(sort
152+
(nth 2 (bash-completion-dynamic-complete-nocomint
153+
(line-beginning-position) (point) nil))
154+
'string<))
150155

151156
(defun bash-completion_test-setup-env (bashrc)
152157
"Sets up a directory that contains a bashrc file other files
@@ -224,6 +229,23 @@ for testing completion."
224229
(bash-completion_test-complete
225230
"export SOMEPATH=some/directory:some/oth")))))
226231

232+
(ert-deftest bash-completion-integration-multiple-completions-test ()
233+
(bash-completion_test-multiple-completions-test ""))
234+
235+
(ert-deftest bash-completion-integration-multiple-completions-prog-test ()
236+
(bash-completion_test-multiple-completions-test
237+
(concat "source " bash-completion_test-setup-completion "\n")))
238+
239+
(defun bash-completion_test-multiple-completions-test (bashrc)
240+
(bash-completion_test-with-shell-harness
241+
bashrc
242+
nil ; use-separate-process
243+
(should (equal '("some/directory/" "some/other/")
244+
(sort (bash-completion_test-candidates "ls some/") 'string<)))
245+
(should (equal '("some/directory/") (bash-completion_test-candidates "ls some/d")))
246+
(should (equal '("some/directory/") (bash-completion_test-candidates "ls some/di")))
247+
(should (equal '() (bash-completion_test-candidates "ls some/do")))))
248+
227249
(ert-deftest bash-completion-integration-nocomint-test ()
228250
(bash-completion_test-harness
229251
"function somefunction { echo ok; }\n"

0 commit comments

Comments
 (0)