From: Sami Kerola Date: Fri, 5 Dec 2014 22:49:48 +0000 (+0000) Subject: tests: add more getopt tests X-Git-Tag: v2.26-rc1~140^2~9 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d458000dea7ff96c63532b317fce631847768877;p=thirdparty%2Futil-linux.git tests: add more getopt tests After importing Frodo's tests I ran coverage to see if something had remained unchecked, and there were couple tests that could be done. CC: Frodo Looijaard Signed-off-by: Sami Kerola --- diff --git a/tests/expected/misc/getopt3 b/tests/expected/misc/getopt3 new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/expected/misc/getopt3-compatible b/tests/expected/misc/getopt3-compatible new file mode 100644 index 0000000000..585de608ac --- /dev/null +++ b/tests/expected/misc/getopt3-compatible @@ -0,0 +1,5 @@ +getopt: missing optstring argument +Try `getopt --help' for more information. +exit value: 2 + -- +exit value: 0 diff --git a/tests/expected/misc/getopt3-csh b/tests/expected/misc/getopt3-csh new file mode 100644 index 0000000000..86e48f4fed --- /dev/null +++ b/tests/expected/misc/getopt3-csh @@ -0,0 +1,2 @@ + -a -b '1' -c '2' --a-long --b-long '3' --c-long '' -- 'foo' 'bar' +exit value: 0 diff --git a/tests/expected/misc/getopt3-no-arguments b/tests/expected/misc/getopt3-no-arguments new file mode 100644 index 0000000000..08b3ed5cff --- /dev/null +++ b/tests/expected/misc/getopt3-no-arguments @@ -0,0 +1,3 @@ +getopt: missing optstring argument +Try `getopt --help' for more information. +exit value: 2 diff --git a/tests/expected/misc/getopt3-non-option b/tests/expected/misc/getopt3-non-option new file mode 100644 index 0000000000..73f0b659ce --- /dev/null +++ b/tests/expected/misc/getopt3-non-option @@ -0,0 +1,4 @@ + -a 'x' -- 'y' '-b' 'z' 'w' + -a 'x' -b 'z' -- 'y' 'w' + -a 'x' 'y' -b 'z' 'w' -- +exit value: 0 diff --git a/tests/expected/misc/getopt3-posix_correctly b/tests/expected/misc/getopt3-posix_correctly new file mode 100644 index 0000000000..5b2bc33fca --- /dev/null +++ b/tests/expected/misc/getopt3-posix_correctly @@ -0,0 +1,4 @@ + -a -b '1' -c '2' --a-long --b-long '3' --c-long '' -- 'foo' 'bar' 'xyxxy' '--a-long' +exit value: 0 + -a -b '1' -c '2' --a-long --b-long '3' --c-long '' -- 'foo' 'bar' 'xyxxy' '--a-long' +exit value: 0 diff --git a/tests/expected/misc/getopt3-sh b/tests/expected/misc/getopt3-sh new file mode 100644 index 0000000000..86e48f4fed --- /dev/null +++ b/tests/expected/misc/getopt3-sh @@ -0,0 +1,2 @@ + -a -b '1' -c '2' --a-long --b-long '3' --c-long '' -- 'foo' 'bar' +exit value: 0 diff --git a/tests/ts/misc/getopt3 b/tests/ts/misc/getopt3 new file mode 100755 index 0000000000..68dc0698fc --- /dev/null +++ b/tests/ts/misc/getopt3 @@ -0,0 +1,63 @@ +#!/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="getopt3" + +. $TS_TOPDIR/functions.sh + +ts_init "$*" +ts_check_test_command "$TS_CMD_GETOPT" + +export LANG=C + +ts_init_subtest compatible +$TS_CMD_GETOPT >> $TS_OUTPUT 2>&1 +echo "exit value: $?" >> $TS_OUTPUT +GETOPT_COMPATIBLE='' $TS_CMD_GETOPT >> $TS_OUTPUT 2>&1 +echo "exit value: $?" >> $TS_OUTPUT +sed -i '1,1s/.*\///' $TS_OUTPUT +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>&1 +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>&1 +echo "exit value: $?" >> $TS_OUTPUT +ts_finalize_subtest + +ts_init_subtest no-arguments +$TS_CMD_GETOPT >> $TS_OUTPUT 2>&1 +echo "exit value: $?" >> $TS_OUTPUT +sed -i '1,1s/.*\///' $TS_OUTPUT +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>&1 +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>&1 +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>&1 +$TS_CMD_GETOPT -o a:b: -- -a x y -b z w >> $TS_OUTPUT 2>&1 +$TS_CMD_GETOPT -o -a:b: -- -a x y -b z w >> $TS_OUTPUT 2>&1 +echo "exit value: $?" >> $TS_OUTPUT +ts_finalize_subtest + +ts_finalize