Permalink
Browse files

Spec tests for the getopts builtin.

Alpine Linux uses this a lot.
  • Loading branch information...
Andy Chu
Andy Chu committed Sep 26, 2017
1 parent bd2a916 commit 232d7226ce834c92f6f993aceda9c416965f527d
Showing with 24 additions and 0 deletions.
  1. +19 −0 spec/builtin-getopts.test.sh
  2. +5 −0 test/spec.sh
@@ -0,0 +1,19 @@
#!/bin/bash
#
# Bash implements type -t.
#
# NOTE: Aliases don't work in batch mode! Interactive only.
### Basic getopts invocation
set -- -h -c foo x y z
FLAG_h=0
FLAG_c=''
while getopts "hc:" opt; do
case $opt in
h) FLAG_h=1 ;;
c) FLAG_c="$OPTARG" ;;
esac
done
shift $(( OPTIND - 1 ))
echo h=$FLAG_h c=$FLAG_c optind=$OPTIND argv=$@
# stdout: h=1 c=foo optind=4 argv=x y z
View
@@ -257,6 +257,11 @@ builtin-vars() {
${REF_SHELLS[@]} $OSH "$@"
}
builtin-getopts() {
sh-spec spec/builtin-getopts.test.sh --osh-failures-allowed 1 \
${REF_SHELLS[@]} $OSH "$@"
}
builtin-test() {
sh-spec spec/builtin-test.test.sh --osh-failures-allowed 1 \
${REF_SHELLS[@]} $OSH "$@"

0 comments on commit 232d722

Please sign in to comment.