From 9e719d8d9c8cfe483c7842932017bfd575de798b Mon Sep 17 00:00:00 2001 From: Bob Killen Date: Sun, 17 Feb 2019 18:22:50 -0500 Subject: [PATCH] Fix shellcheck lint errors in third_party/forked/shell2junit/sh2ju.sh --- hack/.shellcheck_failures | 1 - third_party/forked/shell2junit/sh2ju.sh | 50 ++++++++++++------------- 2 files changed, 25 insertions(+), 26 deletions(-) diff --git a/hack/.shellcheck_failures b/hack/.shellcheck_failures index 842679db1d1..2c69c2c0331 100644 --- a/hack/.shellcheck_failures +++ b/hack/.shellcheck_failures @@ -96,7 +96,6 @@ ./test/images/volume/gluster/run_gluster.sh ./test/images/volume/iscsi/create_block.sh ./test/images/volume/nfs/run_nfs.sh -./third_party/forked/shell2junit/sh2ju.sh ./third_party/intemp/intemp.sh ./third_party/multiarch/qemu-user-static/register/qemu-binfmt-conf.sh ./third_party/multiarch/qemu-user-static/register/register.sh diff --git a/third_party/forked/shell2junit/sh2ju.sh b/third_party/forked/shell2junit/sh2ju.sh index f0891455c82..5a136a99603 100755 --- a/third_party/forked/shell2junit/sh2ju.sh +++ b/third_party/forked/shell2junit/sh2ju.sh @@ -24,10 +24,10 @@ ### asserts=00; errors=0; total=0; content="" -date=`which gdate 2>/dev/null || which date` +date="$(which gdate 2>/dev/null || which date)" # default output folder -juDIR=`pwd`/results +juDIR="$(pwd)/results" # The name of the suite is calculated based in your script name suite="" @@ -59,18 +59,18 @@ function juLogClean() { function juLog() { suite=""; errfile=/tmp/evErr.$$.log - date=`which gdate 2>/dev/null || which date` + date="$(which gdate 2>/dev/null || which date)" asserts=00; errors=0; total=0; content="" # parse arguments ya=""; icase="" while [[ -z "$ya" ]]; do case "$1" in - -name=*) name=`echo "$1" | ${SED} -e 's/-name=//'`; shift;; - -class=*) class=`echo "$1" | ${SED} -e 's/-class=//'`; shift;; - -ierror=*) ereg=`echo "$1" | ${SED} -e 's/-ierror=//'`; icase="-i"; shift;; - -error=*) ereg=`echo "$1" | ${SED} -e 's/-error=//'`; shift;; - -output=*) juDIR=`echo "$1" | ${SED} -e 's/-output=//'`; shift;; + -name=*) name="$(echo "$1" | ${SED} -e 's/-name=//')"; shift;; + -class=*) class="$(echo "$1" | ${SED} -e 's/-class=//')"; shift;; + -ierror=*) ereg="$(echo "$1" | ${SED} -e 's/-ierror=//')"; icase="-i"; shift;; + -error=*) ereg="$(echo "$1" | ${SED} -e 's/-error=//')"; shift;; + -output=*) juDIR="$(echo "$1" | ${SED} -e 's/-output=//')"; shift;; *) ya=1;; esac done @@ -101,37 +101,37 @@ function juLog() { # eval the command sending output to a file outf=/var/tmp/ju$$.txt errf=/var/tmp/ju$$-err.txt - >${outf} + :>${outf} echo "" | tee -a ${outf} echo "+++ Running case: ${class}.${name} " | tee -a ${outf} - echo "+++ working dir: "`pwd` | tee -a ${outf} + echo "+++ working dir: $(pwd)" | tee -a ${outf} echo "+++ command: ${cmd}" | tee -a ${outf} - ini=`${date} +%s.%N` + ini="$(${date} +%s.%N)" # execute the command, temporarily swapping stderr and stdout so they can be tee'd to separate files, # then swapping them back again so that the streams are written correctly for the invoking process ( (eVal "${cmd}" | tee -a ${outf}) 3>&1 1>&2 2>&3 | tee ${errf}) 3>&1 1>&2 2>&3 - evErr=`cat ${errfile}` + evErr="$(cat ${errfile})" rm -f ${errfile} - end=`${date} +%s.%N` + end="$(${date} +%s.%N)" echo "+++ exit code: ${evErr}" | tee -a ${outf} # set the appropriate error, based in the exit code and the regex [[ ${evErr} != 0 ]] && err=1 || err=0 - out=`cat $outf | ${SED} -e 's/^\([^+]\)/| \1/g'` - if [ ${err} = 0 -a -n "${ereg:-}" ]; then - H=`echo "${out}" | egrep ${icase} "${ereg}"` + out="$(${SED} -e 's/^\([^+]\)/| \1/g' "$outf")" + if [ ${err} = 0 ] && [ -n "${ereg:-}" ]; then + H=$(echo "${out}" | grep -E ${icase} "${ereg}") [[ -n "${H}" ]] && err=1 fi [[ ${err} != 0 ]] && echo "+++ error: ${err}" | tee -a ${outf} rm -f ${outf} - errMsg=`cat ${errf}` + errMsg=$(cat ${errf}) rm -f ${errf} # calculate vars - asserts=$(($asserts+1)) - errors=$(($errors+$err)) - time=`echo "${end} ${ini}" | awk '{print $1 - $2}'` - total=`echo "${total} ${time}" | awk '{print $1 + $2}'` + asserts=$((asserts+1)) + errors=$((errors+err)) + time=$(echo "${end} ${ini}" | awk '{print $1 - $2}') + total=$(echo "${total} ${time}" | awk '{print $1 + $2}') # write the junit xml report ## failure tag @@ -149,14 +149,14 @@ function juLog() { if [[ -e "${juDIR}/junit_${suite}.xml" ]]; then # file exists. first update the failures count - failCount=`${SED} -n "s/.*testsuite.*failures=\"\([0-9]*\)\".*/\1/p" "${juDIR}/junit_${suite}.xml"` - errors=$(($failCount+$errors)) + failCount=$(${SED} -n "s/.*testsuite.*failures=\"\([0-9]*\)\".*/\1/p" "${juDIR}/junit_${suite}.xml") + errors=$((failCount+errors)) ${SED} -i "0,/failures=\"${failCount}\"/ s/failures=\"${failCount}\"/failures=\"${errors}\"/" "${juDIR}/junit_${suite}.xml" ${SED} -i "0,/errors=\"${failCount}\"/ s/errors=\"${failCount}\"/errors=\"${errors}\"/" "${juDIR}/junit_${suite}.xml" # file exists. Need to append to it. If we remove the testsuite end tag, we can just add it in after. - ${SED} -i "s^^^g" ${juDIR}/junit_${suite}.xml ## remove testSuite so we can add it later - ${SED} -i "s^^^g" ${juDIR}/junit_${suite}.xml + ${SED} -i "s^^^g" "${juDIR}/junit_${suite}.xml" ## remove testSuite so we can add it later + ${SED} -i "s^^^g" "${juDIR}/junit_${suite}.xml" cat <> "$juDIR/junit_$suite.xml" ${content:-}