[lxc-devel] [lxd/master] test: Fix static analysis

monstermunchkin on Github lxc-bot at linuxcontainers.org
Fri Jun 22 11:07:55 UTC 2018


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 403 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20180622/a902a953/attachment.bin>
-------------- next part --------------
From def6d1f09fa47d364fb365270b60991307424021 Mon Sep 17 00:00:00 2001
From: Thomas Hipp <thomas.hipp at canonical.com>
Date: Fri, 22 Jun 2018 12:59:57 +0200
Subject: [PATCH] test: Fix static analysis

Signed-off-by: Thomas Hipp <thomas.hipp at canonical.com>
---
 test/main.sh                   | 3 +++
 test/suites/basic.sh           | 2 +-
 test/suites/config.sh          | 2 +-
 test/suites/kernel_limits.sh   | 2 +-
 test/suites/static_analysis.sh | 4 ++--
 5 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/test/main.sh b/test/main.sh
index 2dc2500bd..ed534c6d8 100755
--- a/test/main.sh
+++ b/test/main.sh
@@ -30,6 +30,9 @@ LXD_NETNS=""
 # shellcheck disable=SC2034
 LXD_ALT_CERT=""
 
+# Always ignore SC2230 ('which' is non-standard. Use builtin 'command -v' instead.)
+export SHELLCHECK_OPTS="-e SC2230"
+
 import_subdir_files() {
     test "$1"
     # shellcheck disable=SC2039
diff --git a/test/suites/basic.sh b/test/suites/basic.sh
index 2ee05cc8e..e7822f7dc 100644
--- a/test/suites/basic.sh
+++ b/test/suites/basic.sh
@@ -376,7 +376,7 @@ test_basic_usage() {
       MINOR=$(awk -F. '{print $2}' < /sys/kernel/security/apparmor/features/domain/version)
     fi
 
-    if [ "${MAJOR}" -gt "1" ] || ([ "${MAJOR}" = "1" ] && [ "${MINOR}" -ge "2" ]); then
+    if [ "${MAJOR}" -gt "1" ] || { [ "${MAJOR}" = "1" ] && [ "${MINOR}" -ge "2" ]; }; then
       aa_namespace="lxd-lxd-apparmor-test_<$(echo "${LXD_DIR}" | sed -e 's/\//-/g' -e 's/^.//')>"
       aa-status | grep -q ":${aa_namespace}:unconfined" || aa-status | grep -q ":${aa_namespace}://unconfined"
       lxc stop lxd-apparmor-test --force
diff --git a/test/suites/config.sh b/test/suites/config.sh
index aa69210c4..04551325e 100644
--- a/test/suites/config.sh
+++ b/test/suites/config.sh
@@ -159,7 +159,7 @@ test_config_profiles() {
   lxc_version=$(lxc info | grep "driver_version: " | cut -d' ' -f4)
   lxc_major=$(echo "${lxc_version}" | cut -d. -f1)
   lxc_minor=$(echo "${lxc_version}" | cut -d. -f2)
-  if [ "${lxc_major}" -lt 2 ] || ([ "${lxc_major}" = "2" ] && [ "${lxc_minor}" -lt "1" ]); then
+  if [ "${lxc_major}" -lt 2 ] || { [ "${lxc_major}" = "2" ] && [ "${lxc_minor}" -lt "1" ]; }; then
       lxc profile set unconfined raw.lxc "lxc.aa_profile=unconfined"
   else
       lxc profile set unconfined raw.lxc "lxc.apparmor.profile=unconfined"
diff --git a/test/suites/kernel_limits.sh b/test/suites/kernel_limits.sh
index 19490d533..b193ee64d 100644
--- a/test/suites/kernel_limits.sh
+++ b/test/suites/kernel_limits.sh
@@ -3,7 +3,7 @@ test_kernel_limits() {
   lxc_major=$(echo "${lxc_version}" | cut -d. -f1)
   lxc_minor=$(echo "${lxc_version}" | cut -d. -f2)
 
-  if [ "${lxc_major}" -lt 2 ] || ([ "${lxc_major}" = "2" ] && [ "${lxc_minor}" -lt "1" ]); then
+  if [ "${lxc_major}" -lt 2 ] || { [ "${lxc_major}" = "2" ] && [ "${lxc_minor}" -lt "1" ]; }; then
     echo "==> SKIP: kernel_limits require liblxc 2.1 or higher"
     return
   fi
diff --git a/test/suites/static_analysis.sh b/test/suites/static_analysis.sh
index 60cd179c0..2aa61bf96 100644
--- a/test/suites/static_analysis.sh
+++ b/test/suites/static_analysis.sh
@@ -29,14 +29,14 @@ test_static_analysis() {
     fi
 
     ## Mixed tabs/spaces in scripts
-    OUT=$(grep -Pr "\t" . | grep "\.sh:" || true)
+    OUT=$(grep -Pr '\t' . | grep '\.sh:' || true)
     if [ -n "${OUT}" ]; then
       echo "ERROR: mixed tabs and spaces in script: ${OUT}"
       false
     fi
 
     ## Trailing whitespace in scripts
-    OUT=$(grep -r " $" . | grep "\.sh:" || true)
+    OUT=$(grep -r " $" . | grep '\.sh:' || true)
     if [ -n "${OUT}" ]; then
       echo "ERROR: trailing whitespace in script: ${OUT}"
       false


More information about the lxc-devel mailing list