From 8fbcba1c38fecb9ac75e45ca62f28f8201b4032f Mon Sep 17 00:00:00 2001 From: project-repo Date: Fri, 17 Feb 2023 21:31:02 +0100 Subject: [PATCH] Apply shellcheck --- example_scripts/show_workspace_views.sh | 1 + meson.build | 1 + test/arguments | 26 ++++++++++++------------- test/build-w-o-warnings | 3 ++- test/build-w-o-xwayland | 3 ++- test/clang-format | 4 ++-- test/copyright-license | 18 +++++++++++------ test/environment-variables | 16 +++++++-------- test/illegal-strings | 7 +++---- test/scan-build | 1 + test/shellcheck | 16 +++++++++++++++ 11 files changed, 61 insertions(+), 35 deletions(-) create mode 100644 test/shellcheck diff --git a/example_scripts/show_workspace_views.sh b/example_scripts/show_workspace_views.sh index b5a42ae..be6f0f9 100644 --- a/example_scripts/show_workspace_views.sh +++ b/example_scripts/show_workspace_views.sh @@ -19,6 +19,7 @@ do curr_workspace="$(echo "${event}"|jq -r ".outputs.${curr_output}.curr_workspace")" # Print the process names of the view on the current workspace. jq retrieves # their PID and ps is then used to retrieve the process names. + # shellcheck disable=2046 (echo -n "message ";ps -o comm=Command -p $(echo "${event}"|jq -r ".outputs.${curr_output}.workspaces[$((curr_workspace-1))].views[].pid")|tail +2|sed ':a; N; $!ba; s/\n/||/g') >&3 break fi diff --git a/meson.build b/meson.build index 9240d98..e73851e 100644 --- a/meson.build +++ b/meson.build @@ -350,6 +350,7 @@ test('Build without warnings', find_program('test/build-w-o-warnings'), env : [ test('Build without xwayland', find_program('test/build-w-o-xwayland'), env : [ ''.join('MESONCURRENTCONFIGDIR=', meson.current_source_dir()) ], suite: 'devel') test('Copyright and LICENSE', find_program('test/copyright-license'), args : [ cagebreak_main_file + cagebreak_source_strings + cagebreak_header_strings + fuzz_sources + fuzz_headers + fuzz_override_lib ], env : [ ''.join('MESONCURRENTCONFIGDIR=', meson.current_source_dir()), ''.join('MESONLICENSE=', meson.project_license())], suite: 'devel' ) test('Clang-format (formatting check)', find_program('test/clang-format'), args : [ cagebreak_main_file + cagebreak_source_strings + cagebreak_header_strings + fuzz_sources + fuzz_headers + fuzz_override_lib ], env : [ ''.join('MESONCURRENTCONFIGDIR=', meson.current_source_dir()) ], suite: 'devel') +test('Shellcheck (script linting)', find_program('test/shellcheck'), env : [ ''.join('MESONCURRENTCONFIGDIR=', meson.current_source_dir()) ], suite: 'devel') test('Arguments', find_program('test/arguments'), args : [ meson.project_version() ], env : [ ''.join('MESONCURRENTCONFIGDIR=', meson.current_source_dir()) ], suite: 'basic') test('Environment Variables', find_program('test/environment-variables'), env : [ ''.join('MESONCURRENTCONFIGDIR=', meson.current_source_dir()) ], suite: 'basic') test('Scan-build (static analysis)', find_program('test/scan-build'), env : [ ''.join('MESONCURRENTCONFIGDIR=', meson.current_source_dir()) ], suite: 'release') diff --git a/test/arguments b/test/arguments index e5e16ea..e276516 100644 --- a/test/arguments +++ b/test/arguments @@ -24,23 +24,23 @@ RESULT=0 [[ $(2>&1 ./cagebreak -c | head -1 ) = "./cagebreak: option requires an argument -- 'c'" ]] || RESULT=1 [[ $(2>&1 ./cagebreak -c | tail -n +2 ) = "$helptext" ]] || RESULT=1 ## Check with config file -cp $MESONCURRENTCONFIGDIR/test/testing-configurations/-c-config $testdir -sed -i "s|CONFIGPATH|$testdir\/result|g" $testdir/-c-config -WLR_BACKENDS=headless ./cagebreak -c $testdir/-c-config -[[ $(cat $testdir/result) = "SUCCESS" ]] || RESULT=1 +cp "${MESONCURRENTCONFIGDIR}/test/testing-configurations/-c-config" "${testdir}" +sed -i "s|CONFIGPATH|${testdir}\/result|g" "${testdir}/-c-config" +WLR_BACKENDS=headless ./cagebreak -c "${testdir}/-c-config" +[[ $(cat "${testdir}/result") = "SUCCESS" ]] || RESULT=1 # check -e option ## Check without socket -cp $MESONCURRENTCONFIGDIR/test/testing-configurations/config $testdir +cp "${MESONCURRENTCONFIGDIR}/test/testing-configurations/config" "${testdir}" readonly oldsocket=$CAGEBREAK_SOCKET -sed -i "s|CONFIGPATH|$testdir\/socket|g" $testdir/config -$(WLR_BACKENDS=headless ./cagebreak -c $testdir/config) -[[ $(cat $testdir/socket) = $oldsocket ]] || RESULT=1 +sed -i "s|CONFIGPATH|${testdir}\/socket|g" "${testdir}/config" +(WLR_BACKENDS=headless ./cagebreak -c "${testdir}/config") +[[ $(cat "${testdir}/socket") = "${oldsocket}" ]] || RESULT=1 ## Check with socket -cp $MESONCURRENTCONFIGDIR/test/testing-configurations/config $testdir -sed -i "s|CONFIGPATH|$testdir\/socket|g" $testdir/config -$(WLR_BACKENDS=headless ./cagebreak -e -c $testdir/config) -[[ ! $(cat $testdir/socket) = $oldsocket ]] || RESULT=1 +cp "${MESONCURRENTCONFIGDIR}/test/testing-configurations/config" "${testdir}" +sed -i "s|CONFIGPATH|$testdir\/socket|g" "${testdir}/config" +(WLR_BACKENDS=headless ./cagebreak -e -c "${testdir}/config") +[[ ! $(cat "${testdir}/socket") = "${oldsocket}" ]] || RESULT=1 # check -h option [[ $(./cagebreak -h) = "$helptext" ]] || RESULT=1 @@ -52,4 +52,4 @@ $(WLR_BACKENDS=headless ./cagebreak -e -c $testdir/config) # check -v option [[ $(./cagebreak -v) = "Cagebreak version $1" ]] || RESULT=1 -exit $RESULT +exit "${RESULT}" diff --git a/test/build-w-o-warnings b/test/build-w-o-warnings index 02d049a..da76db5 100644 --- a/test/build-w-o-warnings +++ b/test/build-w-o-warnings @@ -4,7 +4,8 @@ RESULT=0 -cd $MESONCURRENTCONFIGDIR +# shellcheck disable=SC2164 +cd "${MESONCURRENTCONFIGDIR}" echo "Build standard release build" rm -rf test/test-w-o-warnings meson setup test/test-w-o-warnings -Dxwayland=true -Dman-pages=true --buildtype=release --fatal-meson-warnings || RESULT=1 diff --git a/test/build-w-o-xwayland b/test/build-w-o-xwayland index b97d62c..3c8c789 100644 --- a/test/build-w-o-xwayland +++ b/test/build-w-o-xwayland @@ -4,7 +4,8 @@ RESULT=0 -cd $MESONCURRENTCONFIGDIR +# shellcheck disable=2164 +cd "${MESONCURRENTCONFIGDIR}" echo "Build without xwayland" rm -rf test/test-w-o-xwayland meson setup test/test-w-o-xwayland -Dxwayland=false -Dman-pages=false --buildtype=release --fatal-meson-warnings || RESULT=1 diff --git a/test/clang-format b/test/clang-format index c3dc561..cf7e553 100644 --- a/test/clang-format +++ b/test/clang-format @@ -2,7 +2,7 @@ # Copyright 2023, project-repo and the cagebreak contributors # SPDX-License-Identifier: MIT -readonly declared_deps="${@}" +readonly declared_deps="${*}" readonly deps="${declared_deps}" RESULT=0 @@ -14,7 +14,7 @@ echo "${MESONCURRENTCONFIGDIR}" for file in ${deps} do echo "${file}" - if $(clang-format -Werror --dry-run "${MESONCURRENTCONFIGDIR}/${file}") + if (clang-format -Werror --dry-run "${MESONCURRENTCONFIGDIR}/${file}") then echo " [x] clang-format" else diff --git a/test/copyright-license b/test/copyright-license index a299327..4fe517f 100644 --- a/test/copyright-license +++ b/test/copyright-license @@ -1,13 +1,17 @@ -#! /bin/sh +#! /bin/bash # Copyright 2023, project-repo and the cagebreak contributors # SPDX-License-Identifier: MIT -readonly declared_deps="${@}" +readonly declared_deps="${*}" readonly hardcoded_deps="meson_options.txt meson.build" +# shellcheck disable=2155,2164,2046 readonly test_deps=$(cd "${MESONCURRENTCONFIGDIR}" ; find . -type f | grep test/) +# shellcheck disable=2155,2164,2046 readonly examples_deps=$(cd "${MESONCURRENTCONFIGDIR}" ; find . -type f | grep examples/) +# shellcheck disable=2155,2164,2046 readonly example_scripts_deps=$(cd "${MESONCURRENTCONFIGDIR}" ; find . -type f | grep example_scripts/) readonly deps="${declared_deps} ${hardcoded_deps} ${test_deps} ${examples_deps} ${example_scripts_deps}" +# shellcheck disable=2046,2155 readonly curryear=$(date +%Y) RESULT=0 @@ -15,14 +19,14 @@ RESULT=0 for file in ${deps} do echo "${file}" - if $(grep -q "Copyright.*${curryear}, project-repo and the cagebreak contributors" "$MESONCURRENTCONFIGDIR/${file}") + if (grep -q "Copyright.*${curryear}, project-repo and the cagebreak contributors" "$MESONCURRENTCONFIGDIR/${file}") then echo " [x] Copyright Notice" else RESULT=1 echo " [ ] Copyright Notice" fi - if $(grep -q "SPDX-License-Identifier: MIT" "$MESONCURRENTCONFIGDIR/${file}") + if (grep -q "SPDX-License-Identifier: MIT" "$MESONCURRENTCONFIGDIR/${file}") then echo " [x] SPDX-License-Identifier" else @@ -33,10 +37,12 @@ done [[ "${MESONLICENSE}" = "MIT" ]] || RESULT=1 +# shellcheck disable=2164 cd "${MESONCURRENTCONFIGDIR}" -[[ $(cat LICENSE) = $(cat README.md | tail -$(wc -l LICENSE)) ]] || RESULT=1 +# shellcheck disable=2046,2002 +[[ $(cat LICENSE) = $( cat README.md | tail -$(wc -l LICENSE)) ]] || RESULT=1 -[[ "Copyright (c) 2020-${curryear} The Cagebreak authors" = $(cat LICENSE | head -1) ]] || RESULT=1 +[[ "Copyright (c) 2020-${curryear} The Cagebreak authors" = $( head -1 LICENSE) ]] || RESULT=1 exit "${RESULT}" diff --git a/test/environment-variables b/test/environment-variables index a3a6d50..d0d26c6 100644 --- a/test/environment-variables +++ b/test/environment-variables @@ -9,16 +9,16 @@ RESULT=0 # CAGEBREAK_SOCKET (duplicate of arguments test) ## Check without socket -cp $MESONCURRENTCONFIGDIR/test/testing-configurations/config $testdir +cp "${MESONCURRENTCONFIGDIR}/test/testing-configurations/config" "${testdir}" readonly oldsocket=$CAGEBREAK_SOCKET -sed -i "s|CONFIGPATH|$testdir\/socket|g" $testdir/config -$(WLR_BACKENDS=headless ./cagebreak -c $testdir/config) -[[ $(cat $testdir/socket) = $oldsocket ]] || RESULT=1 +sed -i "s|CONFIGPATH|$testdir\/socket|g" "${testdir}/config" +(WLR_BACKENDS=headless ./cagebreak -c "${testdir}/config") +[[ $(cat "${testdir}/socket") = "${oldsocket}" ]] || RESULT=1 ## Check with socket -cp $MESONCURRENTCONFIGDIR/test/testing-configurations/config $testdir -sed -i "s|CONFIGPATH|$testdir\/socket|g" $testdir/config -$(WLR_BACKENDS=headless ./cagebreak -e -c $testdir/config) -[[ ! $(cat $testdir/socket) = $oldsocket ]] || RESULT=1 +cp "${MESONCURRENTCONFIGDIR}/test/testing-configurations/config" "${testdir}" +sed -i "s|CONFIGPATH|$testdir\/socket|g" "${testdir}/config" +(WLR_BACKENDS=headless ./cagebreak -e -c "${testdir}/config") +[[ ! $(cat "${testdir}/socket") = "${oldsocket}" ]] || RESULT=1 # XDG_CONFIG_HOME cp "${MESONCURRENTCONFIGDIR}/test/testing-configurations/env-var-config" "${testdir}/cagebreak/config" diff --git a/test/illegal-strings b/test/illegal-strings index fc9129d..5ae9dc0 100644 --- a/test/illegal-strings +++ b/test/illegal-strings @@ -2,10 +2,9 @@ # Copyright 2023, project-repo and the cagebreak contributors # SPDX-License-Identifier: MIT -testdir=$(mktemp -d) - RESULT=0 +# shellcheck disable=2164 cd "${MESONCURRENTCONFIGDIR}" # Check that no TODO statements remain in the release directory @@ -13,8 +12,8 @@ if ! grep -Rq "TODO" . then echo "[x] TODO" else - echo "[ ] TODO" RESULT=1 + echo "[ ] TODO" fi # Check that Cagebreak does not falsely claim to be POSIX compliant @@ -22,8 +21,8 @@ if ! grep -Rq "_POSIX_C_SOURCE" . then echo "[x] _POSIX_C_SOURCE" else - echo "[ ] _POSIX_C_SOURCE" RESULT=1 + echo "[ ] _POSIX_C_SOURCE" fi diff --git a/test/scan-build b/test/scan-build index fd5aef4..c7942fd 100644 --- a/test/scan-build +++ b/test/scan-build @@ -4,6 +4,7 @@ RESULT=0 +# shellcheck disable=2164 cd "${MESONCURRENTCONFIGDIR}" rm -rf test/test-scan-build meson setup test/test-scan-build -Dxwayland=true -Dman-pages=true --buildtype=release || RESULT=1 diff --git a/test/shellcheck b/test/shellcheck new file mode 100644 index 0000000..0727178 --- /dev/null +++ b/test/shellcheck @@ -0,0 +1,16 @@ +#!/bin/bash +# Copyright 2023, project-repo and the cagebreak contributors +# SPDX-License-Identifier: MIT + +RESULT=0 + +set -x +# shellcheck disable=2164 +cd "${MESONCURRENTCONFIGDIR}/test" +# shellcheck disable=2046 +shellcheck --source-path=../example_scripts/ $(ls -Itesting-configurations) || RESULT=1 + +cd "${MESONCURRENTCONFIGDIR}/example_scripts/" || RESULT=1 +shellcheck ./* + +exit "${RESULT}"