diff --git a/docker/organic_test/Dockerfile b/docker/organic_test/Dockerfile index 927b8ed0..f7d90007 100644 --- a/docker/organic_test/Dockerfile +++ b/docker/organic_test/Dockerfile @@ -40,9 +40,9 @@ RUN mkdir /foreign_documents FROM tester as foreign-document-test -RUN apk add --no-cache bash +RUN apk add --no-cache bash coreutils RUN mkdir /foreign_documents -COPY --from=build-org-mode /root/org-mode/doc /foreign_documents/org-mode +COPY --from=build-org-mode /root/org-mode /foreign_documents/org-mode COPY foreign_document_test_entrypoint.sh /entrypoint.sh RUN chmod +x /entrypoint.sh ENTRYPOINT ["/entrypoint.sh"] diff --git a/docker/organic_test/foreign_document_test_entrypoint.sh b/docker/organic_test/foreign_document_test_entrypoint.sh index 8f0c90f0..a09d6723 100644 --- a/docker/organic_test/foreign_document_test_entrypoint.sh +++ b/docker/organic_test/foreign_document_test_entrypoint.sh @@ -5,6 +5,8 @@ set -euo pipefail IFS=$'\n\t' DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +REALPATH=$(command -v uu-realpath || command -v realpath) + function log { (>&2 echo "${@}") } @@ -23,8 +25,56 @@ function main { fi PARSE="${CARGO_TARGET_DIR}/release-lto/parse" - run_compare "org-mode/org-guide.org" "/foreign_documents/org-mode/org-guide.org" - run_compare "org-mode/org-manual.org" "/foreign_documents/org-mode/org-manual.org" + run_compare_function "org-mode" compare_all_org_document "/foreign_documents/org-mode" +} + +function green_text { + (IFS=' '; printf '\x1b[38;2;0;255;0m%s\x1b[0m' "${*}") +} + +function red_text { + (IFS=' '; printf '\x1b[38;2;255;0;0m%s\x1b[0m' "${*}") +} + +function yellow_text { + (IFS=' '; printf '\x1b[38;2;255;255;0m%s\x1b[0m' "${*}") +} + +function indent { + local depth="$1" + local scaled_depth=$((depth * 2)) + shift 1 + local prefix=$(printf -- "%${scaled_depth}s") + while read l; do + (IFS=' '; printf -- '%s%s\n' "$prefix" "$l") + done +} + +function run_compare_function { + local name="$1" + local stdoutput + shift 1 + set +e + stdoutput=$("${@}") + local status=$? + set -e + if [ "$status" -eq 0 ]; then + echo "$(green_text "GOOD") $name" + indent 1 <<<"$stdoutput" + else + echo "$(red_text "FAIL") $name" + indent 1 <<<"$stdoutput" + return 1 + fi +} + +function compare_all_org_document { + local root_dir="$1" + local target_document + find "$root_dir" -type f -iname '*.org' | while read target_document; do + local relative_path=$($REALPATH --relative-to "$root_dir" "$target_document") + (run_compare "$relative_path" "$target_document") + done } function run_compare { @@ -42,16 +92,4 @@ function run_compare { fi } -function green_text { - (IFS=' '; printf '\x1b[38;2;0;255;0m%s\x1b[0m' "${*}") -} - -function red_text { - (IFS=' '; printf '\x1b[38;2;255;0;0m%s\x1b[0m' "${*}") -} - -function yellow_text { - (IFS=' '; printf '\x1b[38;2;255;255;0m%s\x1b[0m' "${*}") -} - main "${@}"