#!/usr/bin/env bash THIS_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" #################################################################### cd $THIS_DIR/../.. # # NOTE: We exclude the language-server-tests # function with_ext() { echo $(find . -name "EXPECTED.$1" | grep -v 'language-server-tests') } BOLD="\033[1;39m" RED="\033[0;31m" GREEN="\033[0;32m" BOLD_BLUE="\033[1;34m" RESET="\033[0m" ################################## # Command line argument processing ALWAYS_YES=no while [ $# -gt 0 ]; do case $1 in -y|--always-yes) ALWAYS_YES=yes ;; -h|--help) echo echo -e "${BOLD}Usage: $(basename $0) [-y|--always-yes]${RESET}" echo exit 0 ;; esac shift done ################################################################################ if [ "$ALWAYS_YES" != "yes" ]; then echo -e "$BOLD" echo -e "This script will compare EXPECTED vs ACTUAL files that may have been" echo -e "produced when you ran ${BOLD_BLUE}da-test-daml-foundations${BOLD}. After inspecting the differences" echo -e "you will be asked whether you wish to copy the ACTUAL file over the" echo -e "EXPECTED file. You can then run da-test-daml-foundations again to confirm that" echo -e "all tests pass now." echo -e "Diffs are done at the word level." echo -e "EXPECTED is in $RED red$BOLD" echo -e "ACTUAL is in $GREEN green$BOLD" echo -e echo -e "If you want to run non-interactively please run ${BOLD_BLUE}$(basename $0) -y${BOLD}" echo -e echo -e "Press any key to continue$RESET" read -n 1 fi ANY_DIFFS=no ANY_ACTUAL=no for EXPECTED in `with_ext json` `with_ext out`; do ACTUAL=$(echo $EXPECTED | sed "s/EXPECTED/ACTUAL/") if [ -f "$ACTUAL" ]; then ANY_ACTUAL=yes diff "$ACTUAL" "$EXPECTED" > /dev/null; RES=$? if [ "$RES" -ne 0 ]; then ANY_DIFFS=yes if [ "$ALWAYS_YES" = "no" ]; then echo -e "$BOLD" echo -e "Comparing:" echo -e "$RED $EXPECTED" echo -e "$GREEN $ACTUAL" echo -e "$RESET" TMPDIR=$(mktemp -d /tmp/update-haskell-testsXXXXXX) TEXPECTED="$TMPDIR/EXPECTED" TACTUAL="$TMPDIR/ACTUAL" cp "$EXPECTED" "$TEXPECTED" cp "$ACTUAL" "$TACTUAL" git diff --word-diff-regex='[[:blank:]]*[^[:space:]]+' --color=always "$TEXPECTED" "$TACTUAL" | cat - echo echo -n -e "${BOLD_BLUE}Copy ACTUAL to EXPECTED? [Y/n]${RESET} " read CONFIRM else CONFIRM="y" echo -e "${BOLD}Copying ${GREEN}$ACTUAL${BOLD}" echo -e "to ${RED}$EXPECTED${RESET}" fi case $CONFIRM in [nN]*) continue ;; *) cp "$ACTUAL" "$EXPECTED" ;; esac fi fi done [ "$ANY_ACTUAL" = "no" ] && { echo -e "${BOLD}No ACTUAL files present. Perhaps run da-test-haskell${RESET}"; exit 0; } [ "$ANY_DIFFS" = "no" ] && { echo -e "${BOLD}Nothing to do. All ACTUAL files same as EXPECTED files${RESET}"; exit 0; } echo echo -e "${BOLD}FINISHED!" echo echo -e "You should now run ${BOLD_BLUE}da-test-haskell${BOLD} to confirm that all tests pass${RESET}" echo