superlint/test/lib/detectFilesTest.sh
Marco Ferrari c99ec7784a
fix: don't skip processing ansible_directory pwd (#5790)
Don't skip processing the current item (FILE) before we give
BuildFileArrays the chance to process it as an item to eventually add to
the list of directories to lint with ansible-lint.

Fix #5789

Other related changes

- Add a new make target to open a shell in a Super-linter container.
- Use a fixed path for FILE_ARRAYS_DIRECTORY_PATH so we can verify its
  contents in tests
- Remove redundant ValidateBooleanVariable in buildFileList because we
  already check those variables in valudation.
- Move Ansible directory detection to a function so we can reuse it.
- Add missing exports for global configuration variables.
- Remove unused LOG_XXXX variables from tests. These should have been
  deleted when we moved log variables to log.sh
2024-06-19 16:58:11 +00:00

122 lines
3 KiB
Bash
Executable file

#!/usr/bin/env bash
set -o errexit
set -o nounset
set -o pipefail
# shellcheck disable=SC2034
LOG_LEVEL="DEBUG"
# 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"
}
function IsAnsibleDirectoryTest() {
local GITHUB_WORKSPACE
GITHUB_WORKSPACE="$(mktemp -d)"
local FILE="${GITHUB_WORKSPACE}/ansible"
mkdir -p "${FILE}"
local ANSIBLE_DIRECTORY="/ansible"
export ANSIBLE_DIRECTORY
debug "Confirming that ${FILE} is an Ansible directory"
if ! IsAnsibleDirectory "${FILE}"; then
fatal "${FILE} is not considered to be an Ansible directory"
fi
FUNCTION_NAME="${FUNCNAME[0]}"
notice "${FUNCTION_NAME} PASS"
}
RecognizeNoShebangTest
RecognizeCommentIsNotShebangTest
RecognizeIndentedShebangAsCommentTest
RecognizeSecondLineShebangAsCommentTest
RecognizeShebangTest
RecognizeShebangWithBlankTest
IsAnsibleDirectoryTest