~svn/ubuntu/raring/subversion/ppa

« back to all changes in this revision

Viewing changes to tools/client-side/bash_completion_test

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-12-05 01:26:14 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20051205012614-qom4xfypgtsqc2xq
Tags: 1.2.3dfsg1-3ubuntu1
Merge with the final Debian release of 1.2.3dfsg1-3, bringing in
fixes to the clean target, better documentation of the libdb4.3
upgrade and build fixes to work with swig1.3_1.3.27.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/bash
 
2
# Checks that the "_svn" function defined in the specified "bash_completion"
 
3
# script produces appropriate lists of completions for various incomplete svn
 
4
# command lines.
 
5
 
 
6
if [ ! -f "$1" ] || [ "$2" ]; then
 
7
  echo "Usage: bash_completion_test BASH_COMPLETION_PATHNAME"
 
8
  echo "Tests the specified \"bash_completion\" script,"
 
9
  echo "including checking it against the \"svn\" program found in the current PATH."
 
10
  exit 1
 
11
fi
 
12
 
 
13
set -e  # Exit on error
 
14
shopt -s extglob
 
15
 
 
16
# Execute the script which is to be tested.
 
17
. "$1"
 
18
 
 
19
# From the given incomplete svn command, print a space-separated list of
 
20
# possible completions of the last argument (or of an empty first argument
 
21
# if no subcommand is given).
 
22
# Usage: get_svn_completions [SVN-SUBCOMMAND [SVN-OPTION...]]
 
23
get_svn_completions() {
 
24
  COMP_WORDS=(svn "$@")
 
25
  if [ $# == 0 ]; then
 
26
    COMP_CWORD=1
 
27
  else
 
28
    COMP_CWORD=$#
 
29
  fi
 
30
  _svn
 
31
  echo -n "${COMPREPLY[*]}"
 
32
}
 
33
 
 
34
# Print a failure message, record the failure, and return "false".
 
35
# Usage: fail MESSAGE
 
36
fail() {
 
37
  PREFIX="FAIL: "
 
38
  for LINE in "$@"; do
 
39
    echo "$PREFIX$LINE"
 
40
    PREFIX="      "
 
41
  done
 
42
  TESTS_FAILED=1
 
43
  false
 
44
}
 
45
 
 
46
# Check that EXPECTED-WORD is among the completions of the last word in
 
47
# SVN-COMMAND.  SVN-COMMAND is a single argument to this function, split
 
48
# into multiple arguments when passed to "get_svn_completions()".
 
49
# Usage: includes SVN-COMMAND EXPECTED-WORD
 
50
includes() {
 
51
  COMPLETIONS=`get_svn_completions $1`
 
52
  if [[ "$2" != @(${COMPLETIONS// /|}) ]]; then
 
53
    fail "completions of \"svn $1\" should include \"$2\"" \
 
54
      "(completions: $COMPLETIONS)"
 
55
  fi
 
56
}
 
57
 
 
58
excludes() {
 
59
  COMPLETIONS=`get_svn_completions $1`
 
60
  if [[ "$2" == @(${COMPLETIONS// /|}) ]]; then
 
61
    fail "completions of \"svn $1\" should exclude \"$2\"" \
 
62
      "(completions: $COMPLETIONS)"
 
63
  fi
 
64
}
 
65
 
 
66
# Print the valid subcommands for "svn", one per line, sorted.
 
67
# Exclude any synonym that is just a truncation of its full name.
 
68
# Usage: get_svn_subcommands
 
69
get_svn_subcommands() {
 
70
  svn help |
 
71
    # Find the relevant lines.
 
72
    sed -n -e '1,/^Available subcommands:$/d;/^$/q;p' |
 
73
    # Remove brackets and commas
 
74
    tr -d ' )' | tr '(,' ' ' |
 
75
    # Remove simple abbreviations
 
76
    ( while read SYNONYMS; do
 
77
        for CMD in $SYNONYMS; do
 
78
          for SYNONYM in $SYNONYMS; do
 
79
            if [ $CMD != "?" ]; then
 
80
              case $SYNONYM in
 
81
              $CMD) ;;
 
82
              $CMD*) CMD= ; break ;;
 
83
              esac
 
84
            fi
 
85
          done
 
86
          if [ $CMD ]; then
 
87
            echo $CMD
 
88
          fi
 
89
        done
 
90
      done
 
91
    ) |
 
92
    sort
 
93
}
 
94
 
 
95
# Print the valid option switches for "svn SUBCMD", one per line, sorted.
 
96
# Usage: get_svn_options SUBCMD
 
97
get_svn_options() {
 
98
  { svn help "$1" |
 
99
      # Find the relevant lines; remove "arg" and description.
 
100
      sed -n -e '1,/^Valid options:$/d;/^  -/!d' \
 
101
             -e 's/\( arg\)* * : .*//;p' |
 
102
      # Remove brackets; put each word on its own line.
 
103
      tr -d '] ' | tr '[' '\n'
 
104
    # The following options are always accepted but not listed in the help
 
105
    echo "-h"
 
106
    echo "--help"
 
107
  } | sort
 
108
  
 
109
}
 
110
 
 
111
 
 
112
# The tests.
 
113
set +e  # Do not exit on error
 
114
TESTS_FAILED=
 
115
 
 
116
echo "Checking general completion"
 
117
includes "he" "help"
 
118
includes "" "?"
 
119
includes "" "h"
 
120
includes "" "help"
 
121
includes "" "--version"
 
122
 
 
123
echo "Checking list of subcommands"
 
124
HELP_SUBCMDS=`get_svn_subcommands | tr "\n" " "`
 
125
COMPLETION_SUBCMDS=`get_svn_completions | tr " " "\n" | grep -v "^-" | sort | tr "\n" " "`
 
126
if [ "$HELP_SUBCMDS" != "$COMPLETION_SUBCMDS" ]; then
 
127
  fail "non-option completions for \"svn \" != subcommands accepted" \
 
128
       "    (non-o. cmpl.: $COMPLETION_SUBCMDS)" \
 
129
       "    (svn accepts:  $HELP_SUBCMDS)"
 
130
fi
 
131
 
 
132
echo "Checking list of options for each subcommand"
 
133
for SUBCMD in $HELP_SUBCMDS; do
 
134
  HELP_OPTIONS=`get_svn_options $SUBCMD | tr "\n" " "`
 
135
  COMPLETION_OPTIONS=`get_svn_completions $SUBCMD - | tr " " "\n" | sort | tr "\n" " "`
 
136
  if [ "$HELP_OPTIONS" != "$COMPLETION_OPTIONS" ]; then
 
137
    fail "completions for \"svn $SUBCMD -\" != options accepted" \
 
138
         "    (completions: $COMPLETION_OPTIONS)" \
 
139
         "    (svn accepts: $HELP_OPTIONS)"
 
140
  fi
 
141
done
 
142
 
 
143
echo "Checking rejection of synonyms"
 
144
excludes "diff -x -u -" "-x"
 
145
excludes "diff -x -u --e" "--extensions"
 
146
excludes "diff --extensions -u -" "--extensions"
 
147
excludes "diff --extensions -u -" "-x"
 
148
excludes "diff --extensions=-u -" "-x"
 
149
 
 
150
if [ $TESTS_FAILED ]; then
 
151
  echo "FAILURE: at least one bash_completion test failed."
 
152
else
 
153
  echo "All bash_completion tests passed."
 
154
fi