mirror of
https://github.com/super-linter/super-linter.git
synced 2024-11-06 01:05:54 -05:00
chore: add tests for linter rules path corner case (#5981)
Add test cases for LINTER_RULES_PATH corner cases: . and /
This commit is contained in:
parent
1ec0205b42
commit
10e132a8f7
1 changed files with 61 additions and 11 deletions
|
@ -11,6 +11,9 @@ LOG_LEVEL="DEBUG"
|
|||
# shellcheck source=/dev/null
|
||||
source "lib/functions/log.sh"
|
||||
|
||||
# shellcheck source=/dev/null
|
||||
source "lib/functions/detectFiles.sh"
|
||||
|
||||
# shellcheck source=/dev/null
|
||||
source "lib/globals/linterRules.sh"
|
||||
|
||||
|
@ -21,13 +24,6 @@ LANGUAGE_ARRAY=("${TEST_LANGUAGE_NAME}" "${TEST_LANGUAGE_NAME_WITHOUT_RULES}")
|
|||
# shellcheck source=/dev/null
|
||||
source "lib/functions/linterRules.sh"
|
||||
|
||||
DEFAULT_RULES_LOCATION="TEMPLATES"
|
||||
|
||||
# Use an existing configuration file. Can be anything inside
|
||||
# DEFAULT_RULES_LOCATION
|
||||
# shellcheck disable=SC2034
|
||||
TEST_LANGUAGE_FILE_NAME=".eslintrc.yml"
|
||||
|
||||
# shellcheck disable=SC2034
|
||||
GITHUB_WORKSPACE="$(pwd)"
|
||||
|
||||
|
@ -36,9 +32,15 @@ function GetLinterRulesTest() {
|
|||
FUNCTION_NAME="${FUNCNAME[0]}"
|
||||
info "${FUNCTION_NAME} start"
|
||||
|
||||
LinterRulesLocation
|
||||
|
||||
DEFAULT_RULES_LOCATION="${DEFAULT_RULES_LOCATION:-"TEMPLATES"}"
|
||||
# Use an existing configuration file. Can be anything inside
|
||||
# DEFAULT_RULES_LOCATION
|
||||
TEST_LANGUAGE_FILE_NAME="${TEST_LANGUAGE_FILE_NAME:-".eslintrc.yml"}"
|
||||
for LANGUAGE in "${LANGUAGE_ARRAY[@]}"; do
|
||||
debug "Loading rules for ${LANGUAGE}..."
|
||||
eval "GetLinterRules ${LANGUAGE} ${DEFAULT_RULES_LOCATION}"
|
||||
GetLinterRules "${LANGUAGE}" "${DEFAULT_RULES_LOCATION}"
|
||||
done
|
||||
|
||||
local EXPECTED_TEST_LANGUAGE_LINTER_RULES="${DEFAULT_RULES_LOCATION}/${TEST_LANGUAGE_FILE_NAME}"
|
||||
|
@ -59,24 +61,70 @@ function GetLinterRulesTest() {
|
|||
notice "${FUNCTION_NAME} PASS"
|
||||
}
|
||||
|
||||
function GetLinterRulesEmptyDotRulesPathTest() {
|
||||
local FUNCTION_NAME
|
||||
FUNCTION_NAME="${FUNCNAME[0]}"
|
||||
info "${FUNCTION_NAME} start"
|
||||
|
||||
# shellcheck disable=SC2034
|
||||
LINTER_RULES_PATH="."
|
||||
TEST_LANGUAGE_FILE_NAME="README.md"
|
||||
DEFAULT_RULES_LOCATION="$(pwd)"
|
||||
GetLinterRulesTest
|
||||
|
||||
unset LINTER_RULES_PATH
|
||||
unset TEST_LANGUAGE_FILE_NAME
|
||||
|
||||
notice "${FUNCTION_NAME} PASS"
|
||||
}
|
||||
|
||||
function GetLinterRulesEmptyRootRulesPathTest() {
|
||||
local FUNCTION_NAME
|
||||
FUNCTION_NAME="${FUNCNAME[0]}"
|
||||
info "${FUNCTION_NAME} start"
|
||||
|
||||
# shellcheck disable=SC2034
|
||||
LINTER_RULES_PATH="."
|
||||
TEST_LANGUAGE_FILE_NAME="README.md"
|
||||
DEFAULT_RULES_LOCATION="$(pwd)"
|
||||
GetLinterRulesTest
|
||||
|
||||
unset LINTER_RULES_PATH
|
||||
unset TEST_LANGUAGE_FILE_NAME
|
||||
|
||||
notice "${FUNCTION_NAME} PASS"
|
||||
}
|
||||
|
||||
function LinterRulesVariablesExportTest() {
|
||||
local FUNCTION_NAME
|
||||
FUNCTION_NAME="${FUNCNAME[0]}"
|
||||
info "${FUNCTION_NAME} start"
|
||||
|
||||
DEFAULT_RULES_LOCATION="TEMPLATES"
|
||||
TEST_LANGUAGE_FILE_NAME=".eslintrc.yml"
|
||||
|
||||
# shellcheck source=/dev/null
|
||||
source "lib/globals/linterRules.sh"
|
||||
|
||||
for LANGUAGE in "${LANGUAGE_ARRAY[@]}"; do
|
||||
debug "Loading rules for ${LANGUAGE}..."
|
||||
eval "GetLinterRules ${LANGUAGE} ${DEFAULT_RULES_LOCATION}"
|
||||
GetLinterRules "${LANGUAGE}" "${DEFAULT_RULES_LOCATION}"
|
||||
done
|
||||
|
||||
for LANGUAGE in "${LANGUAGE_ARRAY[@]}"; do
|
||||
debug "Verify that ${LANGUAGE} configuration file variable is exported"
|
||||
if [[ "${LANGUAGE}" == "${TEST_LANGUAGE_NAME_WITHOUT_RULES}" ]]; then
|
||||
debug "${LANGUAGE} doesn't have linter rules. Skipping export test."
|
||||
debug "${LANGUAGE} doesn't have linter configuration file variable. Skipping export test."
|
||||
continue
|
||||
fi
|
||||
|
||||
local LANGUAGE_LINTER_RULES_VARIABLE_NAME="${LANGUAGE}_LINTER_RULES"
|
||||
if [[ ! -v "${LANGUAGE_LINTER_RULES_VARIABLE_NAME}" ]]; then
|
||||
fatal "${LANGUAGE_LINTER_RULES_VARIABLE_NAME} is not defined"
|
||||
fi
|
||||
local -n LANGUAGE_LINTER_RULES
|
||||
LANGUAGE_LINTER_RULES="${LANGUAGE}_LINTER_RULES"
|
||||
LANGUAGE_LINTER_RULES="${LANGUAGE_LINTER_RULES_VARIABLE_NAME}"
|
||||
|
||||
debug "LANGUAGE_LINTER_RULES (${LANGUAGE}) variable attributes: ${LANGUAGE_LINTER_RULES@a}"
|
||||
if [[ "${LANGUAGE_LINTER_RULES@a}" == *x* ]]; then
|
||||
info "LANGUAGE_LINTER_RULES for ${LANGUAGE} is exported as expected"
|
||||
|
@ -90,4 +138,6 @@ function LinterRulesVariablesExportTest() {
|
|||
}
|
||||
|
||||
GetLinterRulesTest
|
||||
GetLinterRulesEmptyDotRulesPathTest
|
||||
GetLinterRulesEmptyRootRulesPathTest
|
||||
LinterRulesVariablesExportTest
|
||||
|
|
Loading…
Reference in a new issue