diff mbox series

[libgpiod,v2,2/8] tools: tests: declare and assign separately

Message ID 20240603115628.102616-3-warthog618@gmail.com
State New
Headers show
Series tools: tests: fix shellcheck warnings | expand

Commit Message

Kent Gibson June 3, 2024, 11:56 a.m. UTC
Fix shellcheck SC2155[1] - declare and assign separately to avoid
masking return values.

[1] https://www.shellcheck.net/wiki/SC2155

Signed-off-by: Kent Gibson <warthog618@gmail.com>
---
 tools/gpio-tools-test.bash | 28 +++++++++++++++++-----------
 1 file changed, 17 insertions(+), 11 deletions(-)
diff mbox series

Patch

diff --git a/tools/gpio-tools-test.bash b/tools/gpio-tools-test.bash
index 34ea744..6bbb06c 100755
--- a/tools/gpio-tools-test.bash
+++ b/tools/gpio-tools-test.bash
@@ -49,7 +49,8 @@  output_is() {
 
 num_lines_is() {
 	[ "$1" -eq "0" ] || [ -z "$output" ] && return 0
-	local NUM_LINES=$(echo "$output" | wc -l)
+	local NUM_LINES
+	NUM_LINES=$(echo "$output" | wc -l)
 	assertEquals " number of lines:" "$1" "$NUM_LINES"
 }
 
@@ -73,16 +74,18 @@  gpiosim_chip() {
 
 	for ARG in "$@"
 	do
-		local KEY=$(echo $ARG | cut -d"=" -f1)
-		local VAL=$(echo $ARG | cut -d"=" -f2)
+		local KEY VAL
+		KEY=$(echo "$ARG" | cut -d"=" -f1)
+		VAL=$(echo "$ARG" | cut -d"=" -f2)
 
 		if [ "$KEY" = "num_lines" ]
 		then
 			echo $VAL > $BANKPATH/num_lines
 		elif [ "$KEY" = "line_name" ]
 		then
-			local OFFSET=$(echo $VAL | cut -d":" -f1)
-			local LINENAME=$(echo $VAL | cut -d":" -f2)
+			local OFFSET LINENAME
+			OFFSET=$(echo "$VAL" | cut -d":" -f1)
+			LINENAME=$(echo "$VAL" | cut -d":" -f2)
 			local LINEPATH=$BANKPATH/line$OFFSET
 
 			mkdir -p $LINEPATH
@@ -92,10 +95,11 @@  gpiosim_chip() {
 
 	echo 1 > $DEVPATH/live
 
-	local chip_name=$(<$BANKPATH/chip_name)
-	GPIOSIM_CHIP_NAME[$1]=$chip_name
-	GPIOSIM_CHIP_PATH[$1]="/dev/$chip_name"
-	GPIOSIM_DEV_NAME[$1]=$(<$DEVPATH/dev_name)
+	local CHIP_NAME
+	CHIP_NAME=$(<"$BANKPATH/chip_name")
+	GPIOSIM_CHIP_NAME[$1]=$CHIP_NAME
+	GPIOSIM_CHIP_PATH[$1]="/dev/$CHIP_NAME"
+	GPIOSIM_DEV_NAME[$1]=$(<"$DEVPATH/dev_name")
 }
 
 gpiosim_chip_number() {
@@ -3044,14 +3048,16 @@  die() {
 # Must be done after we sources shunit2 as we need SHUNIT_VERSION to be set.
 oneTimeSetUp() {
 	test "$SHUNIT_VERSION" = "$MIN_SHUNIT_VERSION" && return 0
-	local FIRST=$(printf "$SHUNIT_VERSION\n$MIN_SHUNIT_VERSION\n" | sort -Vr | head -1)
+	local FIRST
+	FIRST=$(printf "$SHUNIT_VERSION\n$MIN_SHUNIT_VERSION\n" | sort -Vr | head -1)
 	test "$FIRST" = "$MIN_SHUNIT_VERSION" && \
 		die "minimum shunit version required is $MIN_SHUNIT_VERSION (current version is $SHUNIT_VERSION"
 }
 
 check_kernel() {
 	local REQUIRED=$1
-	local CURRENT=$(uname -r)
+	local CURRENT
+	CURRENT=$(uname -r)
 
 	SORTED=$(printf "$REQUIRED\n$CURRENT" | sort -V | head -n 1)