From e701e2436c8497f628cd69597d2920c1f6d9d4b9 Mon Sep 17 00:00:00 2001 From: Colas Nahaboo Date: Wed, 11 Jan 2023 07:37:43 +0100 Subject: [PATCH] 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. --- README.md | 3 +- cgibashopts | 2 +- tests/filefield-runaway.test | 2 +- tests/form-files.test | 17 +++++++-- tests/tewiba | 70 ++++++++++++++++++++++-------------- 5 files changed, 62 insertions(+), 32 deletions(-) diff --git a/README.md b/README.md index 337a42d..2c7eb8d 100644 --- a/README.md +++ b/README.md @@ -72,7 +72,8 @@ Feel welcome to copy and enhance this project, as well as providing bug reports, - Or just email me: colas@nahaboo.net ## 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: diff --git a/cgibashopts b/cgibashopts index 482d789..826ea2e 100755 --- a/cgibashopts +++ b/cgibashopts @@ -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' diff --git a/tests/filefield-runaway.test b/tests/filefield-runaway.test index 1c87855..193c820 100755 --- a/tests/filefield-runaway.test +++ b/tests/filefield-runaway.test @@ -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 diff --git a/tests/form-files.test b/tests/form-files.test index 70bd08c..c5a802f 100755 --- a/tests/form-files.test +++ b/tests/form-files.test @@ -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##*/}" @@ -25,7 +34,7 @@ for path in form-files/*.data; do done . ../cgibashopts /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 diff --git a/tests/tewiba b/tests/tewiba index 9d66494..41ddff3 100755 --- a/tests/tewiba +++ b/tests/tewiba @@ -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 @@ -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. @@ -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 2>&1