Skip to content

Commit

Permalink
v4.1.3: fixes for the test suite only to avoid bugs in bash versions …
Browse files Browse the repository at this point in the history
…< 4.4. The cgibashopts actual code is unchanged, no need to upgrade unless for passing the test suite on legacy systems.
  • Loading branch information
ColasNahaboo committed Jan 11, 2023
1 parent 8809750 commit e701e24
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 32 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ Feel welcome to copy and enhance this project, as well as providing bug reports,
- Or just email me: [email protected]

## History of changes
- 2023-01-08 v4.1.2: bug fix: only semico0lons were understood as separators in the `Content-Type` and `Content-Disposition` HTTP headers. Fixed to also use commas. Bug reported by "florin-ctu", issues #8 and #9.
- 2023-01-11 v4.1.3: fixes for the test suite only to avoid bugs in bash versions < 4.4. The cgibashopts actual code is unchanged, no need to upgrade unless for passing the test suite on legacy systems.
- 2023-01-08 v4.1.2: bug fix: only semicolons were understood as separators in the `Content-Type` and `Content-Disposition` HTTP headers. Fixed to also use commas. Bug reported by "florin-ctu", issues #8 and #9.
- 2022-11-24 v4.1.1: bug fix: form fields after a file upload field were ignored. Please upgrade!
Bug report by "pipoprods", issue #7.
- 2021-12-23 v4.1.0:
Expand Down
2 changes: 1 addition & 1 deletion cgibashopts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# See https://github.com/ColasNahaboo/cgibashopts
# Uses the CGI env variables REQUEST_METHOD CONTENT_TYPE QUERY_STRING

export CGIBASHOPTS_RELEASE=4.1.2
export CGIBASHOPTS_RELEASE=4.1.3
export CGIBASHOPTS_VERSION="${CGIBASHOPTS_RELEASE%%.*}"
cr=$'\r'
nl=$'\n'
Expand Down
2 changes: 1 addition & 1 deletion tests/filefield-runaway.test
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ TEST "file field then text field"
{
binparse
cat
} <<<$in >$tmp.out
} <<<"$in" >$tmp.out
echo "$expected" >$tmp.exp
cmp -s $tmp.exp $tmp.out || TERR "rest of params gobbled: $(diff $tmp.exp $tmp.out)"
TEND
17 changes: 15 additions & 2 deletions tests/form-files.test
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@
# We "replay" all the saved CGI invocation data in form-files, so we do not
# need a web server, different browsers, and manual steps for the tests

# Note: we exclude testing file5 in old bash versions < 4.4, as this is a
# teratological case, for testing purposes only, that will not happen in real
# operation and that bashes prior to 4.4 could not handle

dofile5=5
if [[ $BASH_VERSION =~ ^([[:digit:]]+)[.]([[:digit:]]+) ]]; then
((${BASH_REMATCH[1]} * 100 + ${BASH_REMATCH[2]} < 404)) && dofile5=
fi

for path in form-files/*.data; do
B="${path%.data}"; B="${B##*/}"

Expand All @@ -25,7 +34,7 @@ for path in form-files/*.data; do
done
. ../cgibashopts <form-files/"$B.data" # fakes a cgi call, creates 5 files

for i in 1 2 3 4 5; do
for i in 1 2 3 4 $dofile5; do
# check if this file is expected to have DOS lines (CR-terminated)
# dos2 is a variant for the weird file5 case with embedded CRs
if egrep -qs "(^| )${i}.2( |\$)" form-files/"$B.dos"; then os=dos2
Expand All @@ -34,7 +43,11 @@ for path in form-files/*.data; do
fi
if ! cmp -s $CGIBASHOPTS_DIR/file$i files-$os/file$i; then
cp $CGIBASHOPTS_DIR/file$i /tmp/$B-file-$i
TERR "file $file$i differ for browser $B. See difference from expected to result by: diff $PWD/files-$os/file$i /tmp/$B-file$i"
TERR "file $file$i differ for browser $B.
# Expected:
$(hexdump -c $PWD/files-$os/file$i 2>/dev/null)
# Got:
$(hexdump -c /tmp/$B-file$i 2>/dev/null)"
fi
[ "$(param file$i)" = file$i ] || TERR filename of file$1 is: "\"$(param file$i)\""
done
Expand Down
70 changes: 43 additions & 27 deletions tests/tewiba
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
export TEWIBA=1.5.0
export TEWIBA=1.5.4
USAGE="USAGE: tewiba [options] [tests...]
Tewiba: TEst WIth BAsh: a simple test suite, in the spirit of shell scripting
Version $TEWIBA - More info: https://github.com/ColasNahaboo/tewiba
Expand Down Expand Up @@ -52,6 +52,9 @@ if [ -n "$_TCLASS_RE_STRING" ]; then
done
fi

# Ensure . is in the path for convenience
[[ $PATH =~ (^|:)[.]: ]] || PATH=".:$PATH"

############################################ Tewiba API: usable funcs & vars
# These can be used in your tests script files.

Expand Down Expand Up @@ -139,38 +142,51 @@ TECHO(){
}

# Usage: DOTEST [options] command-to-test its-options...
# local vars prefixed with _DT_ to avoid conflicts when testing functions
DOTEST(){
local opt label o to e te s ts f c result status r=0
OPTIND=1; while getopts 'o:O:e:E:s:S:l:f:c:' opt; do case "$opt" in
l) label="$OPTARG ";;
o) o="$OPTARG"; to=f;; O) o="$OPTARG"; to=r;;
e) e="$OPTARG"; te=f;; E) e="$OPTARG"; te=r;;
local _DT_opt _DT_label _DT_result _DT_status _DT_r=0 _DT_lset=0
local _DT_o _DT_to _DT_e _DT_te _DT_s _DT_ts _DT_f _DT_c _DT_vv _DT_vf
OPTIND=1; while getopts 'o:O:e:E:s:S:l:f:c:v:V:' _DT_opt; do case "$_DT_opt" in
l) _DT_label="$OPTARG"; _DT_lset=1;;
o) _DT_o="$OPTARG"; _DT_to=f;; O) _DT_o="$OPTARG"; _DT_to=r;;
e) _DT_e="$OPTARG"; _DT_te=f;; E) _DT_e="$OPTARG"; _DT_te=r;;
s) [[ "$OPTARG" =~ ^-?[[:digit:]]+$ ]] && \
s="status != $OPTARG" || s="status != 0" ; ts=r;;
S) s="$OPTARG"; ts=r;;
f) f="$OPTARG";; c) c="$OPTARG";;
_DT_s="_DT_status != $OPTARG" || _DT_s="_DT_status != 0"
_DT_ts=r;;
S) _DT_s="$OPTARG"; _DT_ts=r;;
f) _DT_f="$OPTARG";; c) _DT_c="$OPTARG";;
v) _DT_vv="$OPTARG";; V) _DT_vf="$OPTARG";;
*) :;;
esac; done; shift $((OPTIND-1))

"$@" >$tmp.dotest.out 2>$tmp.dotest.err; status=$?

[ -n "$to" ] && result=$(cat $tmp.dotest.out) && \
[[ ( $to = f && "$result" != "$o" ) ||
( $to = e && ! $result =~ $o ) ]] && ((++r)) &&\
TERR "${label}stdout${nl}Expect: \"$o\"${nl}Got>>>: \"$result\""
[ -n "$te" ] && result=$(cat $tmp.dotest.err) && \
[[ ( $te = f && "$result" != "$e" ) ||
( $te = e && ! $result =~ $e ) ]] && ((++r)) &&\
TERR "${label}stderr${nl}Expect: \"$e\"${nl}Got>>>: \"$result\""
[ -n "$ts" ] && (("$s")) && ((++r)) && \
TERR "${label}status expected: \"$s\", got $status"
[ -n "$f" ] && ! cmp -s $tmp.dotest.out "$f" && ((++r)) && \
if [ -n "$c" ]; then cp $tmp.dotest.out "$c"
TERR "${label}output differ, compare expected to result:
diff ${f@Q} ${F@Q}"
else TERR "${label}output differ"
((_DT_lset)) || _DT_label="$*"
"$@" >$tmp.dotest.out 2>$tmp.dotest.err; _DT_status=$?

[ -n "$_DT_to" ] && _DT_result=$(cat $tmp.dotest.out) && \
[[ ( $_DT_to = f && "$_DT_result" != "$_DT_o" ) ||
( $_DT_to = e && ! $_DT_result =~ $_DT_o ) ]] && ((++_DT_r)) &&\
TERR "${_DT_label}${nl}Exp: \"$_DT_o\"${nl}Got: \"$_DT_result\""
[ -n "$_DT_te" ] && _DT_result=$(cat $tmp.dotest.err) && \
[[ ( $_DT_te = f && "$_DT_result" != "$_DT_e" ) ||
( $_DT_te = e && ! $_DT_result =~ $_DT_e ) ]] && ((++_DT_r)) &&\
TERR "${_DT_label}${_DT_label:+, }(stderr)${nl}Exp: \"$_DT_e\"${nl}Got: \"$_DT_result\""
[ -n "$_DT_ts" ] && (("$_DT_s")) && ((++_DT_r)) && \
TERR "${_DT_label}${_DT_label:+, }(status)${nl}Exp: \"$_DT_s\", Got: $_DT_status"
[ -n "$_DT_f" ] && ! cmp -s $tmp.dotest.out "$_DT_f" && ((++_DT_r)) && \
if [ -n "$_DT_c" ]; then cp $tmp.dotest.out "$_DT_c"
TERR "${_DT_label} output differ, compare expected to result:
diff '${_DT_f}' '${_DT_F}'"
else TERR "${_DT_label} output differ"
fi
return "$r"
[ -n "$_DT_vv" ] && {
eval "$_DT_vv" >/dev/null 2>&1 </dev/null ||
TERR "$_DT_vv failed (status $?)"
}
[ -n "$_DT_vf" ] && {
DOTEST_EVAL "$_DT_vf" "$@" >/dev/null 2>&1 </dev/null ||
TERR "DOTEST_EVAL $_DT_vf $*: failed (status $?)"
}
return "$_DT_r"
}

# in __INIT__, declare regexes to ignore file names
Expand Down

0 comments on commit e701e24

Please sign in to comment.