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 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231
|
#!/bin/bash
# This file is part of util-linux.
#
# This file is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This file is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
TS_TOPDIR="${0%/*}/../.."
TS_DESC="options"
. "$TS_TOPDIR"/functions.sh
ts_init "$*"
ts_check_test_command "$TS_CMD_GETOPT"
export LANG=C
function gnu_getopt_clean() {
sed --in-place \
-e "s/: \(.*\) -- \(.\)$/: \1 -- '\2'/" \
-e "s/ ['\`]\(--[a-zA-Z0-9]\{1,\}\)'/ '\1'/g" \
-e "s/unrecognized option: \(.\)$/invalid option -- '\1'/" \
-e "s/option requires an argument: \(.\)$/option requires an argument -- '\1'/" \
-e "s/unrecognized option: \([^'-].\{1,\}\)$/unrecognized option '--\1'/" \
$TS_OUTPUT $TS_ERRLOG
}
ts_init_subtest alternative_option_clash
$TS_CMD_GETOPT -a -o abcde -l abcde -- -a -ab -abc -ac >> $TS_OUTPUT 2>> $TS_ERRLOG
echo "exit value: $?" >> $TS_OUTPUT
gnu_getopt_clean
ts_finalize_subtest
ts_init_subtest alternative_option_long
$TS_CMD_GETOPT --alternative -o a -l one,two:,three::,four:: -- -a -one -two=MANDATORY -three=OPTIONAL >> $TS_OUTPUT 2>> $TS_ERRLOG
echo "exit value: $?" >> $TS_OUTPUT
gnu_getopt_clean
ts_finalize_subtest
ts_init_subtest alternative_option_short
$TS_CMD_GETOPT -a -o a -l one,two:,three::,four:: -- -a -one -two=MANDATORY -three=OPTIONAL >> $TS_OUTPUT 2>> $TS_ERRLOG
echo "exit value: $?" >> $TS_OUTPUT
gnu_getopt_clean
ts_finalize_subtest
ts_init_subtest invalid_getopt_option
$TS_CMD_GETOPT -b >> $TS_OUTPUT 2>> $TS_ERRLOG
echo "exit value: $?" >> $TS_OUTPUT
sed -i '1,1s/.*\///' $TS_OUTPUT $TS_ERRLOG
gnu_getopt_clean
ts_finalize_subtest
ts_init_subtest invocation_model_one
$TS_CMD_GETOPT abc:d::e::f::g: ARG0 -b ARG1 -d -eOPTIONAL1 -f NOT_OPTIONAL ARG2 -a -c -ISREQUIRED ARG3 -g "BECOMES THREE ARGUMENTS" >> $TS_OUTPUT 2>> $TS_ERRLOG
echo "exit value: $?" >> $TS_OUTPUT
gnu_getopt_clean
ts_finalize_subtest
ts_init_subtest invocation_model_three_as_one
$TS_CMD_GETOPT -o abc:d::e::f::g: -- ARG0 -b ARG1 -d -eOPTIONAL1 -f NOT_OPTIONAL ARG2 -a -c -ISREQUIRED ARG3 -g "BECOMES THREE ARGUMENTS" >> $TS_OUTPUT 2>> $TS_ERRLOG
echo "exit value: $?" >> $TS_OUTPUT
gnu_getopt_clean
ts_finalize_subtest
ts_init_subtest invocation_model_two_as_one
$TS_CMD_GETOPT -- abc:d::e::f::g: ARG0 -b ARG1 -d -eOPTIONAL1 -f NOT_OPTIONAL ARG2 -a -c -ISREQUIRED ARG3 -g "BECOMES THREE ARGUMENTS" >> $TS_OUTPUT 2>> $TS_ERRLOG
echo "exit value: $?" >> $TS_OUTPUT
gnu_getopt_clean
ts_finalize_subtest
ts_init_subtest invocation_without_parameters
$TS_CMD_GETOPT >> $TS_OUTPUT 2>> $TS_ERRLOG
echo "exit value: $?" >> $TS_OUTPUT
gnu_getopt_clean
ts_finalize_subtest
ts_init_subtest long_option_ambiguous_1
$TS_CMD_GETOPT -o a -l long1,long2 -- --long >> $TS_OUTPUT 2>> $TS_ERRLOG
echo "exit value: $?" >> $TS_OUTPUT
sed -i -e '1,1s/.*\///' -e "1s/ambiguous$/ambiguous; possibilities: '--long1' '--long2'/" $TS_OUTPUT $TS_ERRLOG
sed -i -e "1s/is ambiguous: long$/'--long' is ambiguous; possibilities: '--long1' '--long2'/" $TS_OUTPUT $TS_ERRLOG
gnu_getopt_clean
ts_finalize_subtest
ts_init_subtest longopts
$TS_CMD_GETOPT -o a -l long1,secondlong:,thirdlong::,abbreviation: -- --long1 EXTRA1 --thirdlong=ARGUMENT --secondlong=ARG --abbr ABBRARG -a >> $TS_OUTPUT 2>> $TS_ERRLOG
echo "exit value: $?" >> $TS_OUTPUT
gnu_getopt_clean
ts_finalize_subtest
ts_init_subtest name_option_long
$TS_CMD_GETOPT -n THIS_PROGRAM -o a -l long -- -b --long --whatever -a >> $TS_OUTPUT 2>> $TS_ERRLOG
echo "exit value: $?" >> $TS_OUTPUT
gnu_getopt_clean
ts_finalize_subtest
ts_init_subtest name_option_short
$TS_CMD_GETOPT --name THIS_PROGRAM -o a -l long -- -b --long --whatever -a >> $TS_OUTPUT 2>> $TS_ERRLOG
echo "exit value: $?" >> $TS_OUTPUT
gnu_getopt_clean
ts_finalize_subtest
ts_init_subtest quiet_option_long
$TS_CMD_GETOPT --quiet -o a,b: -l long1,long2 -- -c --unknown --long -b >> $TS_OUTPUT 2>> $TS_ERRLOG
echo "exit value: $?" >> $TS_OUTPUT
gnu_getopt_clean
ts_finalize_subtest
ts_init_subtest quiet_option_short
$TS_CMD_GETOPT -q -o a,b: -l long1,long2 -- -c --unknown --long -b >> $TS_OUTPUT 2>> $TS_ERRLOG
echo "exit value: $?" >> $TS_OUTPUT
gnu_getopt_clean
ts_finalize_subtest
ts_init_subtest quiet_output_option_long
$TS_CMD_GETOPT --quiet-output -o a,b: -l long1,long2 -- -c --unknown --long -b >> $TS_OUTPUT 2>> $TS_ERRLOG
echo "exit value: $?" >> $TS_OUTPUT
sed -i -e '1,4s/.*\///' -e "3s/ambiguous$/ambiguous; possibilities: '--long1' '--long2'/" $TS_OUTPUT $TS_ERRLOG
sed -i -e "3s/is ambiguous: long$/'--long' is ambiguous; possibilities: '--long1' '--long2'/" $TS_OUTPUT $TS_ERRLOG
gnu_getopt_clean
ts_finalize_subtest
ts_init_subtest quiet_output_option_short
$TS_CMD_GETOPT -Q -o a,b: -l long1,long2 -- -c --unknown --long -b >> $TS_OUTPUT 2>> $TS_ERRLOG
echo "exit value: $?" >> $TS_OUTPUT
sed -i -e '1,4s/.*\///' -e "3s/ambiguous$/ambiguous; possibilities: '--long1' '--long2'/" $TS_OUTPUT $TS_ERRLOG
sed -i "3s/is ambiguous: long$/'--long' is ambiguous; possibilities: '--long1' '--long2'/" $TS_OUTPUT $TS_ERRLOG
gnu_getopt_clean
ts_finalize_subtest
ts_init_subtest same_long_short_options
$TS_CMD_GETOPT -o a -l a -- -a --a >> $TS_OUTPUT 2>> $TS_ERRLOG
echo "exit value: $?" >> $TS_OUTPUT
gnu_getopt_clean
ts_finalize_subtest
ts_init_subtest test_for_enhanced_getopt
$TS_CMD_GETOPT -T >> $TS_OUTPUT 2>> $TS_ERRLOG
echo "exit value: $?" >> $TS_OUTPUT
gnu_getopt_clean
ts_finalize_subtest
ts_init_subtest unknown_options
$TS_CMD_GETOPT -o a -l long -- -b --long --whatever -a >> $TS_OUTPUT 2>> $TS_ERRLOG
echo "exit value: $?" >> $TS_OUTPUT
sed -i '1,2s/.*\///' $TS_OUTPUT $TS_ERRLOG
gnu_getopt_clean
ts_finalize_subtest
ts_init_subtest unquoted_option_bash
$TS_CMD_GETOPT -s bash -u -o a: -l long1: -- -a '$?!* ' --long \"\\\' 'More
than
one
line' >> $TS_OUTPUT 2>> $TS_ERRLOG
echo "exit value: $?" >> $TS_OUTPUT
gnu_getopt_clean
ts_finalize_subtest
ts_init_subtest unquoted_option_tcsh
$TS_CMD_GETOPT -s tcsh --unquoted -o a: -l long1: -- -a '$?!* ' --long \"\\\' 'More
than
one
line' >> $TS_OUTPUT 2>> $TS_ERRLOG
echo "exit value: $?" >> $TS_OUTPUT
gnu_getopt_clean
ts_finalize_subtest
ts_init_subtest weird_quoting_bash
$TS_CMD_GETOPT -s bash -o a: -l long1: -- -a '$?!* ' --long \"\\\' 'More
than
one
line' >> $TS_OUTPUT 2>> $TS_ERRLOG
echo "exit value: $?" >> $TS_OUTPUT
gnu_getopt_clean
ts_finalize_subtest
ts_init_subtest weird_quoting_tcsh
$TS_CMD_GETOPT --shell tcsh -o a: -l long1: -- -a '$?!* ' --long \"\\\' 'More
than
one
line' >> $TS_OUTPUT 2>> $TS_ERRLOG
echo "exit value: $?" >> $TS_OUTPUT
gnu_getopt_clean
ts_finalize_subtest
ts_init_subtest compatible
$TS_CMD_GETOPT >> $TS_OUTPUT 2>> $TS_ERRLOG
echo "exit value: $?" >> $TS_OUTPUT
GETOPT_COMPATIBLE='' $TS_CMD_GETOPT >> $TS_OUTPUT 2>> $TS_ERRLOG
echo "exit value: $?" >> $TS_OUTPUT
sed -i '1,1s/.*\///' $TS_OUTPUT $TS_ERRLOG
ts_finalize_subtest
ts_init_subtest sh
$TS_CMD_GETOPT --shell=sh -o ab:c:: --long a-long,b-long:,c-long:: -n 'example.sh' -- -a -b 1 -c2 --a-long --b-long 3 --c-long foo bar >> $TS_OUTPUT 2>> $TS_ERRLOG
echo "exit value: $?" >> $TS_OUTPUT
ts_finalize_subtest
ts_init_subtest csh
$TS_CMD_GETOPT --shell=csh -o ab:c:: --long a-long,b-long:,c-long:: -n 'example.csh' -- -a -b 1 -c2 --a-long --b-long 3 --c-long foo bar >> $TS_OUTPUT 2>> $TS_ERRLOG
echo "exit value: $?" >> $TS_OUTPUT
ts_finalize_subtest
ts_init_subtest no-arguments
$TS_CMD_GETOPT >> $TS_OUTPUT 2>> $TS_ERRLOG
echo "exit value: $?" >> $TS_OUTPUT
sed -i '1,1s/.*\///' $TS_OUTPUT $TS_ERRLOG
ts_finalize_subtest
ts_init_subtest posix_correctly
$TS_CMD_GETOPT -o +ab:c:: --long a-long,b-long:,c-long:: -n 'example' -- -a -b 1 -c2 --a-long --b-long 3 --c-long foo bar xyxxy --a-long >> $TS_OUTPUT 2>> $TS_ERRLOG
echo "exit value: $?" >> $TS_OUTPUT
POSIXLY_CORRECT='' $TS_CMD_GETOPT -o ab:c:: --long a-long,b-long:,c-long:: -n 'example' -- -a -b 1 -c2 --a-long --b-long 3 --c-long foo bar xyxxy --a-long >> $TS_OUTPUT 2>> $TS_ERRLOG
echo "exit value: $?" >> $TS_OUTPUT
ts_finalize_subtest
ts_init_subtest non-option
$TS_CMD_GETOPT -o +a:b: -- -a x y -b z w >> $TS_OUTPUT 2>> $TS_ERRLOG
$TS_CMD_GETOPT -o a:b: -- -a x y -b z w >> $TS_OUTPUT 2>> $TS_ERRLOG
$TS_CMD_GETOPT -o -a:b: -- -a x y -b z w >> $TS_OUTPUT 2>> $TS_ERRLOG
echo "exit value: $?" >> $TS_OUTPUT
ts_finalize_subtest
ts_finalize
|