[nft PATCH] tests/build/run-tests.sh: fix issues reported by shellcheck

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Improve a bit the script as reported by shellcheck, also including
information about the log file.

The log file, by the way, is added to the gitignore to reduce noise
in the git tree.

Signed-off-by: Arturo Borrero Gonzalez <arturo@xxxxxxxxxxxxx>
---
 .gitignore               |    1 +
 tests/build/run-tests.sh |   34 +++++++++++++++++++---------------
 2 files changed, 20 insertions(+), 15 deletions(-)

diff --git a/.gitignore b/.gitignore
index 6b37b123..d6f17e4f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -16,6 +16,7 @@ libtool
 
 # Generated by tests
 *.payload.got
+tests/build/tests.log
 
 # Debian package build temporary files
 build-stamp
diff --git a/tests/build/run-tests.sh b/tests/build/run-tests.sh
index f78cc901..4616387f 100755
--- a/tests/build/run-tests.sh
+++ b/tests/build/run-tests.sh
@@ -1,32 +1,36 @@
 #!/bin/bash
 
-log_file="`pwd`/tests.log"
+log_file="$(pwd)/tests.log"
 dir=../..
 argument=( --without-cli --with-cli=linenoise --with-cli=editline --enable-debug --with-mini-gmp
 	   --enable-man-doc --with-xtables --with-json)
 ok=0
 failed=0
 
-[ -f $log_file ] && rm -rf $log_file
+[ -f "$log_file" ] && rm -rf "$log_file"
 
 tmpdir=$(mktemp -d)
-if [ ! -w $tmpdir ] ; then
+if [ ! -w "$tmpdir" ] ; then
         echo "Failed to create tmp file" >&2
         exit 0
 fi
 
-git clone $dir $tmpdir >/dev/null 2>>$log_file
-cd $tmpdir
+git clone "$dir" "$tmpdir" >/dev/null 2>>"$log_file"
+cd "$tmpdir" || exit
 
-autoreconf -fi >/dev/null 2>>$log_file
-./configure >/dev/null 2>>$log_file
+if ! autoreconf -fi >"$log_file" 2>>"$log_file" ; then
+	echo "Something went wrong. Check the log '${log_file}' for details."
+	exit 1
+fi
 
-echo  "Testing build with distcheck"
-make distcheck >/dev/null 2>>$log_file
-rt=$?
+if ! ./configure >"$log_file" 2>>"$log_file" ; then
+	echo "Something went wrong. Check the log '${log_file}' for details."
+	exit 1
+fi
 
-if [ $rt != 0 ] ; then
-	echo "Something went wrong. Check the log for details."
+echo  "Testing build with distcheck"
+if ! make distcheck >/dev/null 2>>"$log_file" ; then
+	echo "Something went wrong. Check the log '${log_file}' for details."
 	exit 1
 fi
 
@@ -35,8 +39,8 @@ echo "Build works. Now, testing compile options"
 
 for var in "${argument[@]}" ; do
 	echo "[EXECUTING] Testing compile option $var"
-	./configure $var >/dev/null 2>>$log_file
-	make -j 8 >/dev/null 2>>$log_file
+	./configure "$var" >/dev/null 2>>"$log_file"
+	make -j 8 >/dev/null 2>>"$log_file"
 	rt=$?
 	echo -en "\033[1A\033[K" # clean the [EXECUTING] foobar line
 
@@ -49,7 +53,7 @@ for var in "${argument[@]}" ; do
 	fi
 done
 
-rm -rf $tmpdir
+rm -rf "$tmpdir"
 
 echo "results: [OK] $ok [FAILED] $failed [TOTAL] $((ok+failed))"
 [ "$failed" -eq 0 ]




[Index of Archives]     [Netfitler Users]     [Berkeley Packet Filter]     [LARTC]     [Bugtraq]     [Yosemite Forum]

  Powered by Linux