tests: add initial bash completion tests
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Felipe Contreras committed
Apr 12, 2012 at 00:57 UTC
5c293a6be48d2e2ab4516aa113bb340b5cf0a12a
1 file changed
+120
t/t9902-completion.sh
new
+120
@@ -0,0 +1,120 @@
1
+#!/bin/sh
2
+#
3
+# Copyright (c) 2012 Felipe Contreras
4
+#
5
+
6
+if test -n "$BASH" && test -z "$POSIXLY_CORRECT"; then
7
+ # we are in full-on bash mode
8
+ true
9
+elif type bash >/dev/null 2>&1; then
10
+ # execute in full-on bash mode
11
+ unset POSIXLY_CORRECT
12
+ exec bash "$0" "$@"
13
+else
14
+ echo '1..0 #SKIP skipping bash completion tests; bash not available'
15
+ exit 0
16
+fi
17
+
18
+test_description='test bash completion'
19
+
20
+. ./test-lib.sh
21
+
22
+complete ()
23
+{
24
+ # do nothing
25
+ return 0
26
+}
27
+
28
+. "$GIT_BUILD_DIR/contrib/completion/git-completion.bash"
29
+
30
+# We don't need this function to actually join words or do anything special.
31
+# Also, it's cleaner to avoid touching bash's internal completion variables.
32
+# So let's override it with a minimal version for testing purposes.
33
+_get_comp_words_by_ref ()
34
+{
35
+ while [ $# -gt 0 ]; do
36
+ case "$1" in
37
+ cur)
38
+ cur=${_words[_cword]}
39
+ ;;
40
+ prev)
41
+ prev=${_words[_cword-1]}
42
+ ;;
43
+ words)
44
+ words=("${_words[@]}")
45
+ ;;
46
+ cword)
47
+ cword=$_cword
48
+ ;;
49
+ esac
50
+ shift
51
+ done
52
+}
53
+
54
+print_comp ()
55
+{
56
+ local IFS=$'\n'
57
+ echo "${COMPREPLY[*]}" > out
58
+}
59
+
60
+run_completion ()
61
+{
62
+ local -a COMPREPLY _words
63
+ local _cword
64
+ _words=( $1 )
65
+ (( _cword = ${#_words[@]} - 1 ))
66
+ _git && print_comp
67
+}
68
+
69
+test_completion ()
70
+{
71
+ test $# -gt 1 && echo "$2" > expected
72
+ run_completion "$@" &&
73
+ test_cmp expected out
74
+}
75
+
76
+test_expect_success 'basic' '
77
+ run_completion "git \"\"" &&
78
+ # built-in
79
+ grep -q "^add \$" out &&
80
+ # script
81
+ grep -q "^filter-branch \$" out &&
82
+ # plumbing
83
+ ! grep -q "^ls-files \$" out &&
84
+
85
+ run_completion "git f" &&
86
+ ! grep -q -v "^f" out
87
+'
88
+
89
+test_expect_success 'double dash "git" itself' '
90
+ sed -e "s/Z$//" >expected <<-\EOF &&
91
+ --paginate Z
92
+ --no-pager Z
93
+ --git-dir=
94
+ --bare Z
95
+ --version Z
96
+ --exec-path Z
97
+ --html-path Z
98
+ --work-tree=
99
+ --namespace=
100
+ --help Z
101
+ EOF
102
+ test_completion "git --"
103
+'
104
+
105
+test_expect_success 'double dash "git checkout"' '
106
+ sed -e "s/Z$//" >expected <<-\EOF &&
107
+ --quiet Z
108
+ --ours Z
109
+ --theirs Z
110
+ --track Z
111
+ --no-track Z
112
+ --merge Z
113
+ --conflict=
114
+ --orphan Z
115
+ --patch Z
116
+ EOF
117
+ test_completion "git checkout --"
118
+'
119
+
120
+test_done