mirror of
https://github.com/super-linter/super-linter.git
synced 2024-11-24 17:50:58 -05:00
chore: add linter commands tests (#5957)
This commit is contained in:
parent
14a6ee6da6
commit
16dbf17306
2 changed files with 83 additions and 1 deletions
10
Makefile
10
Makefile
|
@ -281,7 +281,7 @@ lint-subset-files-enable-expensive-io-checks: ## Lint a small subset of files in
|
|||
$(SUPER_LINTER_TEST_CONTAINER_URL)
|
||||
|
||||
.PHONY: test-lib
|
||||
test-lib: test-globals-languages test-linter-rules test-build-file-list test-detect-files test-github-event test-setup-ssh test-validation test-output ## Test super-linter libs and globals
|
||||
test-lib: test-globals-languages test-linter-rules test-build-file-list test-detect-files test-github-event test-setup-ssh test-validation test-output test-linter-commands ## Test super-linter libs and globals
|
||||
|
||||
.PHONY: test-globals-languages
|
||||
test-globals-languages: ## Test globals/languages.sh
|
||||
|
@ -348,6 +348,14 @@ test-output: ## Test output
|
|||
--entrypoint /tmp/lint/test/lib/outputTest.sh \
|
||||
$(SUPER_LINTER_TEST_CONTAINER_URL)
|
||||
|
||||
.PHONY: test-linter-commands
|
||||
test-linter-commands: ## Test linterCommands
|
||||
docker run \
|
||||
-v "$(CURDIR):/tmp/lint" \
|
||||
-w /tmp/lint \
|
||||
--entrypoint /tmp/lint/test/lib/linterCommandsTest.sh \
|
||||
$(SUPER_LINTER_TEST_CONTAINER_URL)
|
||||
|
||||
# Run this test against a small directory because we're only interested in
|
||||
# loading default configuration files. The directory that we run super-linter
|
||||
# against should not be .github because that includes default linter rules.
|
||||
|
|
74
test/lib/linterCommandsTest.sh
Executable file
74
test/lib/linterCommandsTest.sh
Executable file
|
@ -0,0 +1,74 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
set -o errexit
|
||||
set -o nounset
|
||||
set -o pipefail
|
||||
|
||||
# Default log level
|
||||
# shellcheck disable=SC2034
|
||||
LOG_LEVEL="DEBUG"
|
||||
|
||||
# shellcheck source=/dev/null
|
||||
source "lib/functions/log.sh"
|
||||
|
||||
# linterCommands.sh needs these
|
||||
|
||||
# shellcheck source=/dev/null
|
||||
source "lib/globals/languages.sh"
|
||||
# shellcheck source=/dev/null
|
||||
source "lib/globals/linterRules.sh"
|
||||
# shellcheck source=/dev/null
|
||||
source "lib/functions/linterRules.sh"
|
||||
# shellcheck source=/dev/null
|
||||
source "lib/functions/validation.sh"
|
||||
|
||||
# Initialize the environment
|
||||
# shellcheck disable=SC2034
|
||||
BASH_EXEC_IGNORE_LIBRARIES="false"
|
||||
# shellcheck disable=SC2034
|
||||
GITHUB_WORKSPACE="$(pwd)"
|
||||
# shellcheck disable=SC2034
|
||||
IGNORE_GITIGNORED_FILES="false"
|
||||
LINTER_RULES_PATH="TEMPLATES"
|
||||
# shellcheck disable=SC2034
|
||||
TYPESCRIPT_STANDARD_TSCONFIG_FILE=".github/linters/tsconfig.json"
|
||||
# shellcheck disable=SC2034
|
||||
YAML_ERROR_ON_WARNING="false"
|
||||
for LANGUAGE in "${LANGUAGE_ARRAY_FOR_LINTER_RULES[@]}"; do
|
||||
GetLinterRules "${LANGUAGE}" "${LINTER_RULES_PATH}"
|
||||
done
|
||||
ValidateValidationVariables
|
||||
|
||||
# The slim image might not have this variable defined
|
||||
if [[ ! -v ARM_TTK_PSD1 ]]; then
|
||||
ARM_TTK_PSD1="/usr/lib/microsoft/arm-ttk/arm-ttk.psd1"
|
||||
fi
|
||||
|
||||
# Source the file so we can load commands to compare them without redefining
|
||||
# each command. We're not interested in the actual values of those commands, but
|
||||
# only in how we eventually modify them.
|
||||
|
||||
# shellcheck source=/dev/null
|
||||
source "lib/functions/linterCommands.sh"
|
||||
|
||||
function LinterCommandPresenceTest() {
|
||||
local FUNCTION_NAME
|
||||
FUNCTION_NAME="${FUNCNAME[0]}"
|
||||
info "${FUNCTION_NAME} start"
|
||||
|
||||
for LANGUAGE in "${LANGUAGE_ARRAY[@]}"; do
|
||||
local LINTER_COMMAND_ARRAY_VARIABLE_NAME="LINTER_COMMANDS_ARRAY_${LANGUAGE}"
|
||||
debug "Check if ${LINTER_COMMAND_ARRAY_VARIABLE_NAME} has at least one element"
|
||||
local -n LINTER_COMMAND_ARRAY="${LINTER_COMMAND_ARRAY_VARIABLE_NAME}"
|
||||
if [ ${#LINTER_COMMAND_ARRAY[@]} -eq 0 ]; then
|
||||
fatal "LINTER_COMMAND_ARRAY for ${LANGUAGE} is empty."
|
||||
else
|
||||
debug "LINTER_COMMAND_ARRAY for ${LANGUAGE} has ${#LINTER_COMMAND_ARRAY[@]} elements: ${LINTER_COMMAND_ARRAY[*]}"
|
||||
fi
|
||||
unset -n LINTER_COMMAND_ARRAY
|
||||
done
|
||||
|
||||
notice "${FUNCTION_NAME} PASS"
|
||||
}
|
||||
|
||||
LinterCommandPresenceTest
|
Loading…
Reference in a new issue