Description: basic tests for the completion scripts
 There is probably too few tests of the completion scripts, but that's
 future work.
Forwarded: https://savannah.nongnu.org/patch/index.php?8448

---
 Makefile.in                   |    5 ++++-
 test/colon-in-patch-name.test |    9 +++++++++
 test/completion.test          |   33 +++++++++++++++++++++++++++++++++
 test/run-test-completion.in   |   42 ++++++++++++++++++++++++++++++++++++++++++
 test/space-in-filenames.test  |    4 ++++
 5 files changed, 92 insertions(+), 1 deletion(-)

Index: b/test/completion.test
===================================================================
--- /dev/null
+++ b/test/completion.test
@@ -0,0 +1,33 @@
+# Some very basic tests concerning the bash completions
+# when possible, the tests should be placed with the completed command, not here
+
+$ ../run-test-completion add quilt ad
+>~ PASS:.*
+
+$ ../run-test-completion "add annotate applied" quilt a
+>~ PASS:.*
+
+$ ../run-test-completion "" quilt toppp
+>~ PASS:.*
+
+$ mkdir patches
+$ quilt new "patch:name:with:column.diff"
+> Patch patches/patch:name:with:column.diff is now on top
+
+$ quilt add "file with space"
+> File file with space added to patch patches/patch:name:with:column.diff
+
+$ echo "some content" > "file with space"
+
+$ quilt refresh
+> Refreshed patch patches/patch:name:with:column.diff
+
+$ quilt files
+> file with space
+
+$ ls
+> file with space
+> patches
+
+$ ../run-test-completion "patch:name:with:column.diff" quilt pop patch
+>~ PASS:.*
\ No newline at end of file
Index: b/Makefile.in
===================================================================
--- a/Makefile.in
+++ b/Makefile.in
@@ -79,6 +79,8 @@
 SRC +=		$(QUILT_SRC:%=quilt/%)
 DIRT +=		$(QUILT_IN:%=quilt/%)
 
+SRC +=		test/run-test-completion.in
+DIRT +=		test/run-test-completion
 SCRIPTS_IN :=	patchfns inspect dependency-graph edmail	\
 		remove-trailing-ws backup-files
 
@@ -150,7 +152,8 @@
 
 scripts : $(BIN:%=bin/%) $(QUILT:%=quilt/%)				\
 	  $(SCRIPTS:%=quilt/scripts/%)					\
-	  $(if $(PATCH_WRAPPER),bin/patch-wrapper)
+	  $(if $(PATCH_WRAPPER),bin/patch-wrapper)			\
+	  test/run-test-completion
 
 dist : clean $(PACKAGE)-$(VERSION).tar.gz
 
Index: b/test/run-test-completion.in
===================================================================
--- /dev/null
+++ b/test/run-test-completion.in
@@ -0,0 +1,42 @@
+#! @BASH@
+
+# Little test runner for the bash completion
+
+# Usage:   run-test-completion "expected output" the command line to complete
+#
+# $ run-test-completion "add" quilt ad
+# PASS: quilt ad -> add
+# $ run-test-completion "add" quilt a
+# FAIL: quilt a -> add annotate applied  !=  add
+# $ run-test-completion "" quilt toppp
+# PASS: quilt toppp -> 
+
+
+#  This script is free software; you can redistribute it and/or modify
+#  it under the terms of the GNU General Public License version 2 as
+#  published by the Free Software Foundation.
+#
+#  See the COPYING and AUTHORS files for more details.
+
+
+set -e
+source ../../bash_completion
+
+expected_output=$1
+shift
+
+declare -a COMP_WORDS=()
+for arg in "$@" ; do
+  COMP_WORDS[${#COMP_WORDS[@]}]=$arg
+done
+COMP_CWORD=${#COMP_WORDS[@]}-1
+
+set +e # _quilt_completion fails when completing something with no existing completion, such as "quilt topppp"
+_quilt_completion -o filenames quilt
+observed_output="${COMPREPLY[*]}"
+
+if [ "$expected_output" = "$observed_output" ] ; then
+  echo "PASS: $@ -> $expected_output"
+else
+  echo "FAIL: $@ -> $observed_output  !=  $expected_output"
+fi
Index: b/test/colon-in-patch-name.test
===================================================================
--- a/test/colon-in-patch-name.test
+++ b/test/colon-in-patch-name.test
@@ -6,6 +6,9 @@
 $ quilt new "patch_with:strange[name]"
 > Patch patches/patch_with:strange[name] is now on top
 
+$ ../run-test-completion "patch_with:strange[name]" quilt pop p
+>~ PASS:.*
+
 $ echo foo > foo
 $ quilt add foo
 > File foo added to patch patches/patch_with:strange[name]
@@ -49,6 +52,12 @@
 $ quilt new "{%'}.patch"
 > Patch patches/{%'}.patch is now on top
 
+$ ../run-test-completion "another:strange(name)" quilt pop a
+>~ PASS:.*
+
+$ ../run-test-completion "{%}.patch" quilt pop '{'
+>~ PASS:.*
+
 $ quilt add foo
 > File foo added to patch patches/{%'}.patch
 
Index: b/test/space-in-filenames.test
===================================================================
--- a/test/space-in-filenames.test
+++ b/test/space-in-filenames.test
@@ -14,6 +14,10 @@
 $ quilt patches "foo bar"
 
 $ echo foo > "foo bar"
+
+$ ../run-test-completion "foo bar foo" quilt add f
+>~ PASS:.*
+
 $ quilt add "foo bar"
 > File foo bar added to patch patches/test.diff
 
