Skip to content

Commit

Permalink
Merge pull request #74180 from mrbobbytables/fix-third-party-shellcheck
Browse files Browse the repository at this point in the history
Fix shellcheck lint errors in third_party/* scripts
  • Loading branch information
k8s-ci-robot committed Apr 12, 2019
2 parents cbaaa67 + 9e719d8 commit 5b434ee
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 26 deletions.
1 change: 0 additions & 1 deletion hack/.shellcheck_failures
Expand Up @@ -94,7 +94,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
50 changes: 25 additions & 25 deletions third_party/forked/shell2junit/sh2ju.sh
Expand Up @@ -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=""
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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^</testsuite>^^g" ${juDIR}/junit_${suite}.xml ## remove testSuite so we can add it later
${SED} -i "s^</testsuites>^^g" ${juDIR}/junit_${suite}.xml
${SED} -i "s^</testsuite>^^g" "${juDIR}/junit_${suite}.xml" ## remove testSuite so we can add it later
${SED} -i "s^</testsuites>^^g" "${juDIR}/junit_${suite}.xml"
cat <<EOF >> "$juDIR/junit_$suite.xml"
${content:-}
</testsuite>
Expand Down

0 comments on commit 5b434ee

Please sign in to comment.