mirror of
https://github.com/eth-p/bat-extras.git
synced 2025-06-20 19:57:46 +02:00
Add snapshot test for option parsing library
This commit is contained in:
parent
8b5d2384b2
commit
0967ca9ab3
@ -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
22
test/tests/lib.opt.sh
Normal 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
|
||||||
|
|
7
test/tests/lib.opt.snapshot
Normal file
7
test/tests/lib.opt.snapshot
Normal 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"
|
Loading…
x
Reference in New Issue
Block a user