1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200
|
#! /bin/sh
# Unit tests for funclib.sh
# This is free software. There is NO warranty; not even for
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
# Copyright (C) 2015-2019, 2021, 2023-2024 Bootstrap Authors
#
# This file is dual licensed under the terms of the MIT license
# <https://opensource.org/licenses/MIT>, and GPL version 2 or later
# <https://www.gnu.org/licenses/gpl-2.0.html>. You must apply one of
# these licenses when using or redistributing this software or any of
# the files within it. See the URLs above, or the file `LICENSE`
# included in the Bootstrap distribution for the full license texts.
# Please report bugs or propose patches to:
# <https://github.com/gnulib-modules/bootstrap/issues>
. "$abs_aux_dir"/funclib.sh || exit 1
. "$abs_aux_dir"/options-parser || exit 1
set -e
scriptversion='test-version'
func_help ()
{
$ECHO "HELP"
exit 0
}
# Make sure that setting <func_name>_result has no effect if we return non-zero
# return value.
test_prep_do_nothing ()
{
:
}
func_add_hook func_options_prep test_prep_do_nothing
test_prep_shortcuts ()
{
debug_on=
test x--debug = "x$1" && debug_on=--debug && shift
case $1 in
short|shortc|shortcu|shortcut)
shift
func_quote eval --test SHORTCUT $debug_on ${1+"$@"}
test_prep_shortcuts_result=$func_quote_result
;;
*)
;;
esac
}
func_add_hook func_options_prep test_prep_shortcuts
test_parse_split_short ()
{
while test $# -gt 0
do
_G_opt=$1 ; shift
case $_G_opt in
-t?*)
func_split_short_opt "$_G_opt"
set dummy "$func_split_short_opt_name" \
"$func_split_short_opt_arg" ${1+"$@"}
shift
;;
*)
set dummy "$_G_opt" ${1+"$@"} ; shift
;;
esac
break
done
func_quote eval ${1+"$@"}
test_parse_split_short_result=$func_quote_result
}
func_add_hook func_parse_options test_parse_split_short
test_parse_subst_equal_signs ()
{
_G_opt=$1 ; shift
case $_G_opt in
--*=*)
func_split_equals "$_G_opt"
set dummy "$func_split_equals_lhs" \
"$func_split_equals_rhs" ${1+"$@"}
shift
func_quote eval ${1+"$@"}
test_parse_subst_equal_signs_result=$func_quote_result
;;
*)
;;
esac
}
func_add_hook func_parse_options test_parse_subst_equal_signs
test_parse_do_nothing ()
{
:
}
func_add_hook func_parse_options test_parse_do_nothing
test_parse_eat_test ()
{
_t_parse_match=false
_G_opt=$1 ; shift
case $_G_opt in
--test|-t)
_t_parse_match=:
if test $# = 0; then
func_missing_arg $_G_opt
else
opt_test=$1
shift
fi
;;
esac
if $_t_parse_match; then
func_quote eval ${1+"$@"}
test_parse_eat_test_result=$func_quote_result
fi
}
func_add_hook func_parse_options test_parse_eat_test
test_validate_do_nothing ()
{
:
}
func_add_hook func_validate_options test_validate_do_nothing
test_validate_eat_sth ()
{
if test validate_out = "$1"; then
shift
func_quote eval ${1+"$@"}
test_validate_eat_sth_result=$func_quote_result
fi
}
func_add_hook func_validate_options test_validate_eat_sth
unset_test_opt ()
{
case $# in
0)
$ECHO UNSET_TEST
;;
1)
$ECHO "ONE_ARG $*"
;;
2)
case $1 in
eval)
eval "$2"
exit $?
;;
esac
;;
3)
$ECHO THREE_ARGS
;;
*)
$ECHO MORE_ARGS
;;
esac
}
func_options ${1+"$@"}
eval set dummy "$func_options_result"; shift
case ${opt_test-unset} in
'')
$ECHO "EMPTY_TEST"
;;
unset)
unset_test_opt ${1+"$@"}
;;
false)
$ECHO "FALSE_TEST"
exit 1
;;
*)
$ECHO $opt_test
;;
esac
:
|