#!/usr/bin/env bash # # Run the Organic compare script against a series of documents sourced from exterior places. 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 "${@}") } function die { local status_code="$1" shift (>&2 echo "${@}") exit "$status_code" } function main { cargo build --no-default-features --features compare --profile release-lto if [ "${CARGO_TARGET_DIR:-}" = "" ]; then CARGO_TARGET_DIR=$(realpath target/) fi PARSE="${CARGO_TARGET_DIR}/release-lto/compare" local all_status=0 set +e (run_compare_function "org-mode" compare_all_org_document "/foreign_documents/org-mode") if [ "$?" -ne 0 ]; then all_status=1; fi (run_compare_function "emacs" compare_all_org_document "/foreign_documents/emacs") if [ "$?" -ne 0 ]; then all_status=1; fi (run_compare_function "worg" compare_all_org_document "/foreign_documents/worg") if [ "$?" -ne 0 ]; then all_status=1; fi (run_compare_function "howard_abrams" compare_howard_abrams) if [ "$?" -ne 0 ]; then all_status=1; fi (run_compare_function "doomemacs" compare_all_org_document "/foreign_documents/doomemacs") if [ "$?" -ne 0 ]; then all_status=1; fi set -e if [ "$all_status" -ne 0 ]; then echo "$(red_text "Some tests failed.")" else echo "$(green_text "All tests passed.")" fi return "$all_status" } 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 local all_status=0 while read target_document; do local relative_path=$($REALPATH --relative-to "$root_dir" "$target_document") set +e (run_compare "$relative_path" "$target_document") if [ "$?" -ne 0 ]; then all_status=1; fi set -e done<<<$(find "$root_dir" -type f -iname '*.org') return "$all_status" } function run_compare { local name="$1" local target_document="$2" set +e ($PARSE "$target_document" &> /dev/null) local status=$? set -e if [ "$status" -eq 0 ]; then echo "$(green_text "GOOD") $name" else echo "$(red_text "FAIL") $name" return 1 fi } function compare_howard_abrams { local all_status=0 set +e (run_compare_function "dot-files" compare_all_org_document "/foreign_documents/howardabrams/dot-files") if [ "$?" -ne 0 ]; then all_status=1; fi (run_compare_function "hamacs" compare_all_org_document "/foreign_documents/howardabrams/hamacs") if [ "$?" -ne 0 ]; then all_status=1; fi (run_compare_function "demo-it" compare_all_org_document "/foreign_documents/howardabrams/demo-it") if [ "$?" -ne 0 ]; then all_status=1; fi (run_compare_function "magit-demo" compare_all_org_document "/foreign_documents/howardabrams/magit-demo") if [ "$?" -ne 0 ]; then all_status=1; fi (run_compare_function "pdx-emacs-hackers" compare_all_org_document "/foreign_documents/howardabrams/pdx-emacs-hackers") if [ "$?" -ne 0 ]; then all_status=1; fi (run_compare_function "flora-simulator" compare_all_org_document "/foreign_documents/howardabrams/flora-simulator") if [ "$?" -ne 0 ]; then all_status=1; fi (run_compare_function "literate-devops-demo" compare_all_org_document "/foreign_documents/howardabrams/literate-devops-demo") if [ "$?" -ne 0 ]; then all_status=1; fi (run_compare_function "clojure-yesql-xp" compare_all_org_document "/foreign_documents/howardabrams/clojure-yesql-xp") if [ "$?" -ne 0 ]; then all_status=1; fi (run_compare_function "veep" compare_all_org_document "/foreign_documents/howardabrams/veep") if [ "$?" -ne 0 ]; then all_status=1; fi set -e return "$all_status" } main "${@}"