[Note: this is a repost with corrections to message #74549 ]
Log:
* NEW FILES:
/svn/trunk/tools/client-side/bash_completion_test_svn
/svn/trunk/tools/client-side/bash_completion_test_svnadmin
Fixed issues with 'bash_completion' config and new 'svnadmin' tester
o Also see previous posting on updates to 'bash_completion' file.
o Fixed svn & svnadmin parameters for trunk programs.
o File now passes all 'svn' and 'svnadmin' tests sucessfully.
o (I don't know if a bug/issue was ever reported, but I fixed it. :)
o I discovered that the 'bash_completion_test' script did not correctly
check 'svnadmin' commands. (it was broke!)
o I copied 'bash_completion_test' to 'bash_completion_test_svnadmin',
for checking 'svnadmin' commands specifically.
o The difference between two versions is about 30 lines, but it was
faster for me to make a new version than trying to code one script
'generically'. :)
o If someone writes a 'generic' version, then this script could be
extended for other 'subversion' commands.
o Both files are included below.....
------------------------------------------------------------------
FILE: bash_compeltion_test_svn
------------------------------------------------------------------
#!/bin/bash
# Checks that the "_svn" function defined in the specified "bash_completion"
# script produces appropriate lists of completions for various incomplete svn
# command lines.
if [ ! -f "$1" ] || [ "$2" ]; then
echo "Usage: bash_completion_test_svn BASH_COMPLETION_PATHNAME"
echo "Tests the specified \"bash_completion\" script,"
echo "including checking it against the \"svn\" program found in the
current PATH."
exit 1
fi
set -e # Exit on error
shopt -s extglob
# Execute the script which is to be tested.
.. "$1"
# From the given incomplete svn command, print a space-separated list of
# possible completions of the last argument (or of an empty first argument
# if no subcommand is given).
# Usage: get_svn_completions [SVN-SUBCOMMAND [SVN-OPTION...]]
get_svn_completions() {
COMP_WORDS=(svn "$@")
if [ $# == 0 ]; then
COMP_CWORD=1
else
COMP_CWORD=$#
fi
_svn
echo -n "${COMPREPLY[*]}"
}
# Print a failure message, record the failure, and return "false".
# Usage: fail MESSAGE
fail() {
PREFIX="FAIL: "
for LINE in "$@"; do
echo "$PREFIX$LINE"
PREFIX=" "
done
TESTS_FAILED=1
false
}
# Check that EXPECTED-WORD is among the completions of the last word in
# SVN-COMMAND. SVN-COMMAND is a single argument to this function, split
# into multiple arguments when passed to "get_svn_completions()".
# Usage: includes SVN-COMMAND EXPECTED-WORD
includes() {
COMPLETIONS=`get_svn_completions $1`
if [[ "$2" != @(${COMPLETIONS// /|}) ]]; then
fail "completions of \"svn $1\" should include \"$2\"" \
"(completions: $COMPLETIONS)"
fi
}
excludes() {
COMPLETIONS=`get_svn_completions $1`
if [[ "$2" == @(${COMPLETIONS// /|}) ]]; then
fail "completions of \"svn $1\" should exclude \"$2\"" \
"(completions: $COMPLETIONS)"
fi
}
# Print the valid subcommands for "svn", one per line, sorted.
# Exclude any synonym that is just a truncation of its full name.
# Usage: get_svn_subcommands
get_svn_subcommands() {
svn help |
# Find the relevant lines.
sed -n -e '1,/^Available subcommands:$/d;/^$/q;p' |
# Remove brackets and commas
tr -d ' )' | tr '(,' ' ' |
# Remove simple abbreviations
( while read SYNONYMS; do
for CMD in $SYNONYMS; do
for SYNONYM in $SYNONYMS; do
if [ $CMD != "?" ]; then
case $SYNONYM in
$CMD) ;;
$CMD*) CMD= ; break ;;
esac
fi
done
if [ $CMD ]; then
echo $CMD
fi
done
done
) |
sort
}
# Print the valid option switches for "svn SUBCMD", one per line, sorted.
# Usage: get_svn_options SUBCMD
get_svn_options() {
{ svn help "$1" |
# Find the relevant lines; remove "arg" and description.
sed -n -e '1,/^Valid options:$/d;/^ -/!d' \
-e 's/\( arg\)* * : .*//;p' |
# Remove brackets; put each word on its own line.
tr -d '] ' | tr '[' '\n'
# The following options are always accepted but not listed in the help
echo "-h"
echo "--help"
} | sort
}
# The tests.
set +e # Do not exit on error
TESTS_FAILED=
echo "Checking general completion"
includes "he" "help"
includes "" "?"
includes "" "h"
includes "" "help"
includes "" "--version"
echo "Checking list of subcommands"
HELP_SUBCMDS=`get_svn_subcommands | tr "\n" " "`
COMPLETION_SUBCMDS=`get_svn_completions | tr " " "\n" | grep -v "^-" |
sort | tr "\n" " "`
if [ "$HELP_SUBCMDS" != "$COMPLETION_SUBCMDS" ]; then
fail "non-option completions for \"svn \" != subcommands accepted" \
" (non-o. cmpl.: $COMPLETION_SUBCMDS)" \
" (svn accepts: $HELP_SUBCMDS)"
fi
echo "Checking list of options for each subcommand"
for SUBCMD in $HELP_SUBCMDS; do
HELP_OPTIONS=`get_svn_options $SUBCMD | tr "\n" " "`
COMPLETION_OPTIONS=`get_svn_completions $SUBCMD - | tr " " "\n" |
sort | tr "\n" " "`
if [ "$HELP_OPTIONS" != "$COMPLETION_OPTIONS" ]; then
fail "completions for \"svn $SUBCMD -\" != options accepted" \
" (completions: $COMPLETION_OPTIONS)" \
" (svn accepts: $HELP_OPTIONS)"
fi
done
echo "Checking rejection of synonyms"
excludes "diff -x -u -" "-x"
excludes "diff -x -u --e" "--extensions"
excludes "diff --extensions -u -" "--extensions"
excludes "diff --extensions -u -" "-x"
excludes "diff --extensions=-u -" "-x"
if [ $TESTS_FAILED ]; then
echo "FAILURE: at least one bash_completion test failed."
else
echo "All bash_completion tests passed."
fi
------------------------------------------------------------------
FILE: bash_compeltion_test_svnadmin
------------------------------------------------------------------
#!/bin/bash
# Checks that the "_svnadmin" function defined in the specified
"bash_completion"
# script produces appropriate lists of completions for various incomplete svn
# command lines.
if [ ! -f "$1" ] || [ "$2" ]; then
echo "Usage: bash_completion_test_svnadmin BASH_COMPLETION_PATHNAME"
echo "Tests the specified \"bash_completion\" script,"
echo "including checking it against the \"svnadmin\" program found
in the current PATH."
exit 1
fi
set -e # Exit on error
shopt -s extglob
# Execute the script which is to be tested.
.. "$1"
# From the given incomplete svnadmin command, print a space-separated list of
# possible completions of the last argument (or of an empty first argument
# if no subcommand is given).
# Usage: get_svnadmin_completions [SVN-SUBCOMMAND [SVN-OPTION...]]
get_svnadmin_completions() {
COMP_WORDS=(svnadmin "$@")
if [ $# == 0 ]; then
COMP_CWORD=1
else
COMP_CWORD=$#
fi
_svnadmin
echo -n "${COMPREPLY[*]}"
}
# Print a failure message, record the failure, and return "false".
# Usage: fail MESSAGE
fail() {
PREFIX="FAIL: "
for LINE in "$@"; do
echo "$PREFIX$LINE"
PREFIX=" "
done
TESTS_FAILED=1
false
}
# Check that EXPECTED-WORD is among the completions of the last word in
# SVN-COMMAND. SVN-COMMAND is a single argument to this function, split
# into multiple arguments when passed to "get_svnadmin_completions()".
# Usage: includes SVN-COMMAND EXPECTED-WORD
includes() {
COMPLETIONS=`get_svnadmin_completions $1`
if [[ "$2" != @(${COMPLETIONS// /|}) ]]; then
fail "completions of \"svnadmin $1\" should include \"$2\"" \
"(completions: $COMPLETIONS)"
fi
}
excludes() {
COMPLETIONS=`get_svnadmin_completions $1`
if [[ "$2" == @(${COMPLETIONS// /|}) ]]; then
fail "completions of \"svnadmin $1\" should exclude \"$2\"" \
"(completions: $COMPLETIONS)"
fi
}
# Print the valid subcommands for "svn", one per line, sorted.
# Exclude any synonym that is just a truncation of its full name.
# Usage: get_svnadmin_subcommands
get_svnadmin_subcommands() {
svnadmin help |
# Find the relevant lines.
sed -n -e '1,/^Available subcommands:$/d;/^$/q;p' |
# Remove brackets and commas
tr -d ' )' | tr '(,' ' ' |
# Remove simple abbreviations
( while read SYNONYMS; do
for CMD in $SYNONYMS; do
for SYNONYM in $SYNONYMS; do
if [ $CMD != "?" ]; then
case $SYNONYM in
$CMD) ;;
$CMD*) CMD= ; break ;;
esac
fi
done
if [ $CMD ]; then
echo $CMD
fi
done
done
) |
sort
}
# Print the valid option switches for "svnadmin SUBCMD", one per line, sorted.
# Usage: get_svnadmin_options SUBCMD
get_svnadmin_options() {
{ svnadmin help "$1" |
# Find the relevant lines; remove "arg" and description.
sed -n -e '1,/^Valid options:$/d;/^ -/!d' \
-e 's/\( arg\)* * : .*//;p' |
# Remove brackets; put each word on its own line.
tr -d '] ' | tr '[' '\n'
# The following options are always accepted but not listed in the help
echo "-h"
echo "--help"
} | sort
}
# The tests.
set +e # Do not exit on error
TESTS_FAILED=
echo "Checking general completion"
includes "he" "help"
includes "" "?"
includes "" "h"
includes "" "help"
includes "" "--version"
echo "Checking list of subcommands"
HELP_SUBCMDS=`get_svnadmin_subcommands | tr "\n" " "`
COMPLETION_SUBCMDS=`get_svnadmin_completions | tr " " "\n" | grep -v
"^-" | sort | tr "\n" " "`
if [ "$HELP_SUBCMDS" != "$COMPLETION_SUBCMDS" ]; then
fail "non-option completions for \"svnadmin \" != subcommands accepted" \
" (non-o. cmpl.: $COMPLETION_SUBCMDS)" \
" (svnadmin accepts: $HELP_SUBCMDS)"
fi
echo "Checking list of options for each subcommand"
for SUBCMD in $HELP_SUBCMDS; do
HELP_OPTIONS=`get_svnadmin_options $SUBCMD | tr "\n" " "`
COMPLETION_OPTIONS=`get_svnadmin_completions $SUBCMD - | tr " " "\n"
| sort | tr "\n" " "`
if [ "$HELP_OPTIONS" != "$COMPLETION_OPTIONS" ]; then
fail "completions for \"svnadmin $SUBCMD -\" != options accepted" \
" (completions: $COMPLETION_OPTIONS)" \
" (svnadmin accepts: $HELP_OPTIONS)"
fi
done
echo "Checking rejection of synonyms"
excludes "diff -x -u -" "-x"
excludes "diff -x -u --e" "--extensions"
excludes "diff --extensions -u -" "--extensions"
excludes "diff --extensions -u -" "-x"
excludes "diff --extensions=-u -" "-x"
if [ $TESTS_FAILED ]; then
echo "FAILURE: at least one bash_completion test failed."
else
echo "All bash_completion tests passed."
fi
-------------------------------------------------------------
-------------------------------------------------------------
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Thu Aug 19 07:12:14 2004