53 lines
1.5 KiB
Bash
53 lines
1.5 KiB
Bash
#!/bin/bash
|
|
set -euo pipefail
|
|
|
|
SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
|
|
REPO_ROOT=$(cd "${SCRIPT_DIR}/.." && pwd)
|
|
|
|
fail() {
|
|
echo "FAIL: $*" >&2
|
|
exit 1
|
|
}
|
|
|
|
has_crlf() {
|
|
local file_path=$1
|
|
|
|
file "${file_path}" | grep -qi "CRLF\|with CR"
|
|
}
|
|
|
|
test_check_crlf_works_from_preset_directory() {
|
|
local temp_root common_dir preset_dir output_file file_name
|
|
|
|
temp_root=$(mktemp -d)
|
|
common_dir="${temp_root}/common"
|
|
preset_dir="${temp_root}/preset"
|
|
output_file="${temp_root}/output.txt"
|
|
|
|
mkdir -p "${common_dir}" "${preset_dir}"
|
|
cp "${REPO_ROOT}/docker-runner/common/check_crlf.sh" "${common_dir}/check_crlf.sh"
|
|
chmod +x "${common_dir}/check_crlf.sh"
|
|
|
|
for file_name in entrypoint.sh setup.sh upgrade.sh register.sh manage.sh; do
|
|
printf '#!/bin/bash\r\necho test\r\n' > "${common_dir}/${file_name}"
|
|
chmod 644 "${common_dir}/${file_name}"
|
|
done
|
|
|
|
(
|
|
cd "${preset_dir}"
|
|
printf 'n\n' | ../common/check_crlf.sh > "${output_file}"
|
|
)
|
|
|
|
! rg -q "文件不存在" "${output_file}" || fail "check_crlf.sh should inspect sibling common scripts even when invoked from preset directory"
|
|
|
|
for file_name in entrypoint.sh setup.sh upgrade.sh register.sh manage.sh; do
|
|
! has_crlf "${common_dir}/${file_name}" || fail "${file_name} should have CRLF fixed"
|
|
[ -x "${common_dir}/${file_name}" ] || fail "${file_name} should be made executable"
|
|
done
|
|
|
|
rm -rf "${temp_root}"
|
|
}
|
|
|
|
test_check_crlf_works_from_preset_directory
|
|
|
|
echo "check_crlf_test.sh: PASS"
|