#!/usr/bin/env bash
conf=${0##*/}.conf

expect -c -s "'# ${conf} '*'
mybool1 = false
mybool2 = true
mybool3 = true
mystr = new'" optauto args --mystr=new --no-mybool1 --mybool2 -bIi ignore --dumpconfig <<-EOO
	B|!mybool1=bool:true
	mybool2=bool:false
	b|mybool3=bool:false
	mystr=str:default
	I|ignored-without-argument=ignore
	i|ignored-with-argument=ignore:
EOO

testopt() {
	optauto args 1 2 3 </dev/null &&
		echo "${args[*]}"
}
expect -c "1 2 3" testopt

testopt() {
	usage <<<"test" &&
		optauto args -h </dev/null
}
expect -c "test" testopt

expect -c "${0##*/} ${VERSION}" optauto args --version </dev/null

cat > ${conf} <<-EOF
	mystr = new
EOF
expect -c -s "'# ${conf} '*'
mystr = new'" optauto args --confdir=. --dumpconfig <<<"mystr=str:text"

unset EPREFIX EROOT ROOT
optauto args --root=/root --eprefix=/eprefix/ </dev/null
[[ ${ROOT} == /root ]] || fail "ROOT='${ROOT}' is not '/root'"
[[ ${EPREFIX} == /eprefix ]] || fail "EPREFIX='${EPREFIX}' is not '/eprefix'"
[[ ${EROOT} == /root/eprefix ]] || fail "EROOT='${EROOT}' is not '/root/eprefix'"
