mirror of
https://github.com/super-linter/super-linter.git
synced 2024-11-30 10:01:12 -05:00
ef57e132e1
- Remove the previous summary file is present to avoid showing stale contents from old summaries. - Extract the logic to write summary heading and lines to dedicated functions in output.sh to make it easier adding new formats in the future.
114 lines
3.4 KiB
Bash
Executable file
114 lines
3.4 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
set -o errexit
|
|
set -o nounset
|
|
set -o pipefail
|
|
|
|
# shellcheck disable=SC2034
|
|
CREATE_LOG_FILE=false
|
|
# Default log level
|
|
# shellcheck disable=SC2034
|
|
LOG_LEVEL="DEBUG"
|
|
|
|
# shellcheck source=/dev/null
|
|
source "lib/functions/log.sh"
|
|
|
|
# shellcheck source=/dev/null
|
|
source "lib/functions/output.sh"
|
|
|
|
TEMP_WORKSPACE="$(pwd)/super-linter-output"
|
|
|
|
function InitWorkspace() {
|
|
CleanupWorkspace
|
|
mkdir -p "${TEMP_WORKSPACE}"
|
|
}
|
|
|
|
function CleanupWorkspace() {
|
|
rm -rf "${TEMP_WORKSPACE}"
|
|
}
|
|
|
|
function CheckIfFileDiff() {
|
|
local INPUT_FILE="${1}"
|
|
local EXPECTED_FILE="${2}"
|
|
# Remove eventual HTML comments from the expected file because we use them to disable certain linter rules
|
|
if ! diff "${INPUT_FILE}" <(grep -vE '^\s*<!--' "${EXPECTED_FILE}"); then
|
|
fatal "${INPUT_FILE} contents don't match with the expected contents (${EXPECTED_FILE})"
|
|
else
|
|
echo "${INPUT_FILE} contents match with the expected contents (${EXPECTED_FILE})"
|
|
fi
|
|
}
|
|
|
|
function WriteSummaryMarkdownTableHeaderTest() {
|
|
local FUNCTION_NAME
|
|
FUNCTION_NAME="${FUNCNAME[0]}"
|
|
info "${FUNCTION_NAME} start"
|
|
|
|
local RESULTS_FILE="${TEMP_WORKSPACE}/${FUNCTION_NAME}-output.md"
|
|
InitWorkspace
|
|
WriteSummaryHeader "${RESULTS_FILE}"
|
|
CheckIfFileDiff "${RESULTS_FILE}" "test/data/super-linter-summary/markdown/table/expected-summary-heading.md"
|
|
CleanupWorkspace
|
|
|
|
notice "${FUNCTION_NAME} PASS"
|
|
}
|
|
|
|
function WriteSummaryMarkdownTableLineSuccessTest() {
|
|
local FUNCTION_NAME
|
|
FUNCTION_NAME="${FUNCNAME[0]}"
|
|
info "${FUNCTION_NAME} start"
|
|
|
|
local RESULTS_FILE="${TEMP_WORKSPACE}/${FUNCTION_NAME}-output-${FUNCTION_NAME}.md"
|
|
InitWorkspace
|
|
WriteSummaryLineSuccess "${RESULTS_FILE}" "Test Language"
|
|
CheckIfFileDiff "${RESULTS_FILE}" "test/data/super-linter-summary/markdown/table/expected-summary-line-success.md"
|
|
CleanupWorkspace
|
|
|
|
notice "${FUNCTION_NAME} PASS"
|
|
}
|
|
|
|
function WriteSummaryMarkdownTableLineFailureTest() {
|
|
local FUNCTION_NAME
|
|
FUNCTION_NAME="${FUNCNAME[0]}"
|
|
info "${FUNCTION_NAME} start"
|
|
|
|
local RESULTS_FILE="${TEMP_WORKSPACE}/${FUNCTION_NAME}-output-${FUNCTION_NAME}.md"
|
|
InitWorkspace
|
|
WriteSummaryLineFailure "${RESULTS_FILE}" "Test Language"
|
|
CheckIfFileDiff "${RESULTS_FILE}" "test/data/super-linter-summary/markdown/table/expected-summary-line-failure.md"
|
|
CleanupWorkspace
|
|
|
|
notice "${FUNCTION_NAME} PASS"
|
|
}
|
|
|
|
function WriteSummaryMarkdownTableFooterSuccessTest() {
|
|
local FUNCTION_NAME
|
|
FUNCTION_NAME="${FUNCNAME[0]}"
|
|
info "${FUNCTION_NAME} start"
|
|
|
|
local RESULTS_FILE="${TEMP_WORKSPACE}/${FUNCTION_NAME}-output-${FUNCTION_NAME}.md"
|
|
InitWorkspace
|
|
WriteSummaryFooterSuccess "${RESULTS_FILE}"
|
|
CheckIfFileDiff "${RESULTS_FILE}" "test/data/super-linter-summary/markdown/table/expected-summary-footer-success.md"
|
|
CleanupWorkspace
|
|
|
|
notice "${FUNCTION_NAME} PASS"
|
|
}
|
|
|
|
function WriteSummaryMarkdownTableFooterFailureTest() {
|
|
local FUNCTION_NAME
|
|
FUNCTION_NAME="${FUNCNAME[0]}"
|
|
info "${FUNCTION_NAME} start"
|
|
|
|
local RESULTS_FILE="${TEMP_WORKSPACE}/${FUNCTION_NAME}-output-${FUNCTION_NAME}.md"
|
|
InitWorkspace
|
|
WriteSummaryFooterFailure "${RESULTS_FILE}"
|
|
CheckIfFileDiff "${RESULTS_FILE}" "test/data/super-linter-summary/markdown/table/expected-summary-footer-failure.md"
|
|
CleanupWorkspace
|
|
|
|
notice "${FUNCTION_NAME} PASS"
|
|
}
|
|
|
|
WriteSummaryMarkdownTableHeaderTest
|
|
WriteSummaryMarkdownTableLineSuccessTest
|
|
WriteSummaryMarkdownTableLineFailureTest
|
|
WriteSummaryMarkdownTableFooterSuccessTest
|
|
WriteSummaryMarkdownTableFooterFailureTest
|