3 # Usage: First do 'make -C ../src test' to generate the .out files. If there are
4 # failures, their test filenames will be printed to stdout. Pass these as
5 # arguments to this script.
7 # note: we don't use [ -z $FOO ] to check if FOO is unset because that is also
9 if [ -z "${OUT_EXT+x}" ]; then
13 if [ -z "${EXP_EXT+x}" ]; then
17 if [ -z "${NO_COPY+x}" ]; then
21 ARROW
="$(tput bold)$(tput setaf 6)==>$(tput setaf 7)"
23 function reconstitute_full_path
{
26 if [ -n "${ROOT}" ]; then
27 if [[ "$TEST_PATH" = "$SOURCE_ROOT"* ]]; then
28 FULL_PATH
="${ROOT}${TEST_PATH#"${SOURCE_ROOT}"}"
29 elif [[ "$TEST_PATH" = .
/hphp
/hack
/* ]]; then
30 FULL_PATH
="${ROOT}/${TEST_PATH#"./hphp/hack/"}"
31 elif [[ "$TEST_PATH" = hphp
/hack
/* ]]; then
32 FULL_PATH
="${ROOT}/${TEST_PATH#"hphp/hack/"}"
39 echo "$ARROW $f $(tput sgr0)"
40 # `-b a` means to number all lines; this is the same as
41 # --body-numbering=a, but works with both BSD and GNU `nl`
42 nl -b a
"$(reconstitute_full_path "$f" "$SOURCE_ROOT")"
45 OUT_BASE
=$
(reconstitute_full_path
"$f" "$OUTPUT_ROOT")
46 EXP_BASE
=$
(reconstitute_full_path
"$f" "$SOURCE_ROOT")
47 if [ -e "$OUT_BASE$OUT_EXT" ]; then
48 OUT
="$OUT_BASE$OUT_EXT"
52 EXP_TO
="$EXP_BASE$EXP_EXT"
53 if [ -e "$EXP_BASE$EXP_EXT" ]; then
54 EXP
="$EXP_BASE$EXP_EXT"
55 elif [ -n "${FALLBACK_EXP_EXT+x}" ] && [ -e "$EXP_BASE$FALLBACK_EXP_EXT" ]; then
56 EXP
="$EXP_BASE$FALLBACK_EXP_EXT"
61 echo "$ARROW Diff between $EXP and $(basename "$OUT") $(tput sgr0)"
63 # Use git diff to give us color and word diffs. The patience algorithm
64 # produces more readable diffs in some situations.
66 # --no-index makes us ignore the git repo, if any - otherwise this only
67 # works in hg checkouts (i.e. fbcode)
68 git
--no-pager diff --no-index --diff-algorithm=histogram
--color=always \
69 --word-diff=color
--word-diff-regex='[^[:space:]]+' \
70 $EXP "$OUT" |
tail -n +5
72 if [ "$NO_COPY" = true
]; then
73 if [ "$TERM" = "dumb" ]; then
74 read -r -p "$(tput bold)View next file? [Y/q] $(tput sgr0)"
76 read -p "$(tput bold)View next file? [Y/q] $(tput sgr0)" -n 1 -r
78 elif [ "$TERM" = "dumb" ]; then
79 read -r -p "$(tput bold)Copy output to expected output? [y/q/N] $(tput sgr0)"
81 read -p "$(tput bold)Copy output to expected output? [y/q/N] $(tput sgr0)" -n 1 -r
84 if [ "$REPLY" = "y" ] && [ "$NO_COPY" = false
]; then
86 elif [ "$REPLY" = "q" ]; then
90 # A single blank line between loop iterations, even if the user hit enter.
91 if [[ "$REPLY" =~
[a-zA-Z
] ]]; then