Skip to content
Permalink
Browse files

Fix shellcheck errors

  • Loading branch information
krader1961 committed Dec 16, 2019
1 parent 02525a3 commit 5efb243e87c63e8352776ef5f3fb28c3360813c4
@@ -1,11 +1,13 @@
#!/bin/sh -x
# Run shellcheck on scripts under bin and scripts directories
# shellcheck disable=SC2046,SC2038
typeset -a dirs=(.copr bin scripts \
src/cmd/ksh93/functions \
src/cmd/ksh93/tests/util \
src/lib/libast/tests)
shellcheck -s ksh $(find "${dirs[@]}" -type f |
xargs file |
#
# Run shellcheck on all scripts that are not unit test scripts. The latter
# should not have a `#!/bin/sh` like shebang line. That will cause the `file`
# command to not classify them as shell scripts. All other scripts, even those
# meant to be `source`d or equivalent should have a shebang line that
# identifies them as a shell script.
#
# shellcheck disable=SC2046
shellcheck -s ksh $(find ./* -type f -print0 |
xargs -0 file |
grep -E '(shell|ksh) script' |
cut -d':' -f1)
@@ -33,7 +33,7 @@ typeset -a c_files=()
typeset -a files=()

function semver {
echo $1 | awk '{ split($1, v, "."); printf "%d%03d%03d\n", v[1], v[2], v[3] }'
print -- "$1" | awk '{ split($1, v, "."); printf "%d%03d%03d\n", v[1], v[2], v[3] }'
}

# Deal with any CLI flags.
@@ -60,14 +60,14 @@ fi
if command -v clang-format > /dev/null
then
cformat_ver=$(clang-format --version | awk '{ print $3 }')
if [[ $(semver $cformat_ver) -lt $(semver $MIN_CFORMAT_VER) ]]
if [[ $(semver "$cformat_ver") -lt $(semver "$MIN_CFORMAT_VER") ]]
then
echo
echo "ERROR: clang-format version $cformat_ver less than min required $MIN_CFORMAT_VER"
echo
exit 1
fi
if [[ $(semver $cformat_ver) -gt $(semver $MAX_CFORMAT_VER) ]]
if [[ $(semver "$cformat_ver") -gt $(semver "$MAX_CFORMAT_VER") ]]
then
echo
echo "ERROR: clang-format version $cformat_ver greater than max allowed $MAX_CFORMAT_VER"
@@ -88,7 +88,7 @@ then
echo >&2
echo 'You have uncommitted changes. Cowardly refusing to restyle the entire code base.' >&2
echo 'We do not want to include style cleanups unrelated to your work in progress.' >&2
echo 'It should be sufficient to simply run `bin/style` to fix issues with your wip.' >&2
echo 'It should be sufficient to simply run bin/style to fix issues with your wip.' >&2
echo >&2
exit
fi
@@ -6,11 +6,13 @@ do
then
for s in "*.*" "*[!a]*"
do
# shellcheck disable=SC2043
# Notice the `break 3` in the body of the loop.
for b in libc
do
for i in $d/$b.$s
do
if test -f $i
if test -f "$i"
then
lib=$i
fi
@@ -25,33 +27,34 @@ done

case $lib in
*.[0-9]*.[0-9]*)
i=`echo $lib | sed 's,\([^0-9]*[0-9]*\).*,\1,'`
if test -f $i
then
lib=$i
fi
;;
# shellcheck disable=SC2001
i=$(echo "$lib" | sed 's,\([^0-9]*[0-9]*\).*,\1,')
if test -f "$i"
then
lib=$i
fi
;;
esac

# Some run time linkers barf with /lib/xxx if /usr/lib/xxx is there.
case $lib in
/usr*) ;;
*) if test -f /usr$lib
/usr*) ;;
*) if test -f "/usr$lib"
then
lib=/usr$lib
fi
;;
lib=/usr$lib
fi
;;
esac

case $lib in
"")
lib=/lib/libc.so.1
;;
"")
lib=/lib/libc.so.1
;;
esac

case $lib in
/usr/lib/*)
case `package 2>/dev/null` in
/usr/lib/*)
case $(package 2>/dev/null) in
sgi.mips3)
abi=/lib32
;;
@@ -66,11 +69,12 @@ case $lib in
?*)
if test -d $abi
then
lib=`echo $lib | sed 's,/usr/lib/,,'`
# shellcheck disable=SC2001
lib=$(echo "$lib" | sed 's,/usr/lib/,,')
lib=$abi/$lib
fi
;;
esac
;;
esac
echo $lib
echo "$lib"
@@ -31,12 +31,14 @@ for i in \
do case $i in
-*) op=$i; continue ;;
esac
if test $op $i
if test "$op" "$i"
then ok=1
break
fi
set x $i.[0-9]*
if test $op $2
# shellcheck disable=SC2121
# We're deliberately setting the "argv" strings.
set x "$i".[0-9]*
if test "$op" "$2"
then ok=1
break
fi
@@ -7,6 +7,7 @@
#
function _ksh_print_help {
local cmd=$1
# shellcheck disable=SC2154
local man_dir="${.sh.install_prefix}/share/ksh/man"
local fname="$man_dir/man1/${cmd}.1"

@@ -12,6 +12,7 @@ function man {
[[ -n $manpath_cmd ]] && manpath="$($manpath_cmd)"
fi
local -x MANPATH="$manpath"
# shellcheck disable=SC2154
local ksh_manpath="${.sh.install_prefix}/share/ksh/man"
if [[ -d "$ksh_manpath" && -n "$MANPATH" ]]
then
@@ -4,9 +4,11 @@
# doesn't overflow what can safely be represented in the exit status.
#
empty_fifos
if (( $error_count != 0 ))
# shellcheck disable=SC2154
if (( error_count != 0 ))
then
'log_warning' $((start_of_test_lineno - 1)) "error_count = $error_count"
# shellcheck disable=SC2154
'log_warning' $(( start_of_test_lineno - 1 )) "error_count = $error_count"
exit $(( error_count < 50 ? error_count : 50 ))
fi
exit 0
@@ -1,4 +1,7 @@
#!/usr/bin/env ksh
# shellcheck disable=SC2034
# This module defines a bunch of vars that are not used by this module but are, potentially, used
# when this module is combined with specific unit tests.
#
# Setup the environment for the unit test.
#
@@ -26,7 +29,8 @@ bin_true=$(whence -p true)
bin_uname=$(whence -p uname)

# We have tests that should only run if the `nc` (netcat) command is available.
whence -q nc && readonly nc_available=yes || readonly nc_available=no
whence -q nc && nc_available=yes || nc_available=no
readonly nc_available

# There are at least two tests that are broken if all builtins are enabled by munging PATH.
# So make it easy for a unit test to not enable all builtins by default. See issue #960.
@@ -54,19 +58,19 @@ integer error_count=0
integer start_of_test_lineno=0 # redefined later to be read-only

function log_info {
typeset lineno=$(( $1 < 0 ? $1 : $1 - $start_of_test_lineno ))
print -r "<I> ${test_name}[$lineno]: ${@:2}"
typeset lineno=$(( $1 < 0 ? $1 : $1 - start_of_test_lineno ))
print -r "<I> ${test_name}[$lineno]: ${*:2}"
}
alias log_info='log_info $LINENO'

function log_warning {
typeset lineno=$(( $1 < 0 ? $1 : $1 - $start_of_test_lineno ))
print -u2 -r "<W> ${test_name}[$lineno]: ${@:2}"
typeset lineno=$(( $1 < 0 ? $1 : $1 - start_of_test_lineno ))
print -u2 -r "<W> ${test_name}[$lineno]: ${*:2}"
}
alias log_warning='log_warning $LINENO'

function log_error {
typeset lineno=$(( $1 < 0 ? $1 : $1 - $start_of_test_lineno ))
typeset lineno=$(( $1 < 0 ? $1 : $1 - start_of_test_lineno ))
typeset msg="$2"
print -u2 -r "<E> ${test_name}[$lineno]: $msg"
if (( $# > 2 ))
@@ -97,17 +101,17 @@ function empty_fifos {
typeset _x

print -u8 fifo8
while read -u8 _x # try to empty the fifo
while read -r -u8 _x # try to empty the fifo
do
[[ $_x == fifo8 ]] && break
'log_error' $_line_num "fifo8 unexpectedly had data" "" "$_x"
'log_error' "$_line_num" "fifo8 unexpectedly had data" "" "$_x"
done

print -u9 fifo9
while read -u9 _x # try to empty the fifo
while read -r -u9 _x # try to empty the fifo
do
[[ $_x == fifo9 ]] && break
'log_error' $_line_num "fifo9 unexpectedly had data" "" "$_x"
'log_error' "$_line_num" "fifo9 unexpectedly had data" "" "$_x"
done
}
alias empty_fifos='empty_fifos $LINENO'

0 comments on commit 5efb243

Please sign in to comment.
You can’t perform that action at this time.