Add snapshot test for option parsing library

This commit is contained in:
Ethan P 2019-09-08 19:38:13 -07:00
parent 8b5d2384b2
commit 0967ca9ab3
No known key found for this signature in database
GPG Key ID: 1F8DF8091CD46FBC
3 changed files with 33 additions and 0 deletions

View File

@ -23,6 +23,10 @@ run_test() {
local test_name="$1" local test_name="$1"
local test_action="$2" local test_action="$2"
export DIR_SRC="${HERE}/../src"
export DIR_BIN="${HERE}/../bin"
export DIR_LIB="${HERE}/../lib"
bash "$HERE/util/test-exec.sh" "$test_action" "$test_name" bash "$HERE/util/test-exec.sh" "$test_action" "$test_name"
return $? return $?
} }

22
test/tests/lib.opt.sh Normal file
View File

@ -0,0 +1,22 @@
set -e
source "${DIR_LIB}/opt.sh"
setargs pos1 \
--val1 for_val1 \
--val2=for_val2 \
pos2 \
--flag1 \
-v4 for_val4 \
--flag2 \
# Run a standard option parsing loop.
while shiftopt; do
case "$OPT" in
--val*) shiftval; printf "LONG_OPTION: \"%s\" with value \"%s\"\n" "${OPT}" "${OPT_VAL}" ;;
--*) printf "LONG_FLAG: \"%s\"\n" "${OPT}" ;;
-v*) shiftval; printf "SHORT_OPTION: \"%s\" with value \"%s\"\n" "${OPT}" "${OPT_VAL}" ;;
-*) printf "SHORT_FLAG: \"%s\"\n" "${OPT}" ;;
*) printf "ARGUMENT: \"%s\"\n" "${OPT}" ;;
esac
done

View File

@ -0,0 +1,7 @@
ARGUMENT: "pos1"
LONG_OPTION: "--val1" with value "for_val1"
LONG_OPTION: "--val2" with value "for_val2"
ARGUMENT: "pos2"
LONG_FLAG: "--flag1"
SHORT_OPTION: "-v4" with value "for_val4"
LONG_FLAG: "--flag2"