superlint/test/lib/detectFilesTest.sh
Benjamin Wuethrich 95aabd4cfa
feat(bash-exec): add option to ignore shell library files (#5254)
Introduce a new configuration variable, BASH_EXEC_IGNORE_LIBRARIES. If
set to true, the behaviour of bash-exec is modified: if a shell file has
a file extension and no shebang line, it is ignored, i.e., allowed to be
non-executable. This allows files that are only every sourced from other
shell files, acting as libraries and not executables, to have no
executable bit set without failing the bash-exec linter.
2024-02-27 18:17:22 +00:00

110 lines
2.7 KiB
Bash
Executable file

#!/usr/bin/env bash
set -o errexit
set -o nounset
set -o pipefail
# shellcheck disable=SC2034
LOG_DEBUG="true"
# shellcheck disable=SC2034
LOG_VERBOSE="true"
# shellcheck disable=SC2034
LOG_NOTICE="true"
# shellcheck disable=SC2034
LOG_WARN="true"
# shellcheck disable=SC2034
LOG_ERROR="true"
# shellcheck source=/dev/null
source "lib/functions/log.sh"
# shellcheck disable=SC2034
CREATE_LOG_FILE=false
# shellcheck source=/dev/null
source "lib/functions/detectFiles.sh"
function RecognizeNoShebangTest() {
local FILE="test/linters/bash_exec/libraries/noShebang_bad.sh"
debug "Confirming ${FILE} has no shebang"
if ! HasNoShebang "${FILE}"; then
fatal "${FILE} is mis-classified as having a shebang"
fi
FUNCTION_NAME="${FUNCNAME[0]}"
notice "${FUNCTION_NAME} PASS"
}
RecognizeCommentIsNotShebangTest() {
local FILE="test/linters/bash_exec/libraries/comment_bad.sh"
debug "Confirming ${FILE} starting with a comment has no shebang"
if ! HasNoShebang "${FILE}"; then
fatal "${FILE} with a comment is mis-classified as having a shebang"
fi
FUNCTION_NAME="${FUNCNAME[0]}"
notice "${FUNCTION_NAME} PASS"
}
RecognizeIndentedShebangAsCommentTest() {
local FILE="test/linters/bash_exec/libraries/indentedShebang_bad.sh"
debug "Confirming indented shebang in ${FILE} is considered a comment"
if ! HasNoShebang "${FILE}"; then
fatal "${FILE} with a comment is mis-classified as having a shebang"
fi
FUNCTION_NAME="${FUNCNAME[0]}"
notice "${FUNCTION_NAME} PASS"
}
RecognizeSecondLineShebangAsCommentTest() {
local FILE="test/linters/bash_exec/libraries/secondLineShebang_bad.sh"
debug "Confirming shebang on second line in ${FILE} is considered a comment"
if ! HasNoShebang "${FILE}"; then
fatal "${FILE} with a comment is mis-classified as having a shebang"
fi
FUNCTION_NAME="${FUNCNAME[0]}"
notice "${FUNCTION_NAME} PASS"
}
function RecognizeShebangTest() {
local FILE="test/linters/bash_exec/libraries/shebang_bad.sh"
debug "Confirming ${FILE} has a shebang"
if HasNoShebang "${FILE}"; then
fatal "${FILE} is mis-classified as not having a shebang"
fi
FUNCTION_NAME="${FUNCNAME[0]}"
notice "${FUNCTION_NAME} PASS"
}
function RecognizeShebangWithBlankTest() {
local FILE="test/linters/bash_exec/libraries/shebangWithBlank_bad.sh"
debug "Confirming shebang with blank in ${FILE} is recognized"
if HasNoShebang "${FILE}"; then
fatal "${FILE} is mis-classified as not having a shebang"
fi
FUNCTION_NAME="${FUNCNAME[0]}"
notice "${FUNCTION_NAME} PASS"
}
RecognizeNoShebangTest
RecognizeCommentIsNotShebangTest
RecognizeIndentedShebangAsCommentTest
RecognizeSecondLineShebangAsCommentTest
RecognizeShebangTest
RecognizeShebangWithBlankTest