improve Shapes::idx / Shapes::idx lint by underlining invalid property
[hiphop-php.git] / hphp / hack / test / review.sh
blob788af5c5e4a76b2370c39f1843eb53950fe06575
1 #! /usr/bin/env bash
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
8 # true if FOO=""
9 if [ -z "${OUT_EXT+x}" ]; then
10 OUT_EXT=".out"
13 if [ -z "${EXP_EXT+x}" ]; then
14 EXP_EXT=".exp"
17 if [ -z "${NO_COPY+x}" ]; then
18 NO_COPY=false
21 ARROW="$(tput bold)$(tput setaf 6)==>$(tput setaf 7)"
23 function reconstitute_full_path {
24 TEST_PATH=$1
25 ROOT=$2
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/"}"
35 echo "$FULL_PATH"
38 for f in "$@"; do
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")"
43 echo
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"
49 else
50 OUT=/dev/null
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"
57 else
58 EXP=/dev/null
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
71 echo
72 if [ "$NO_COPY" = true ]; then
73 if [ "$TERM" = "dumb" ]; then
74 read -r -p "$(tput bold)View next file? [Y/q] $(tput sgr0)"
75 else
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)"
80 else
81 read -p "$(tput bold)Copy output to expected output? [y/q/N] $(tput sgr0)" -n 1 -r
83 echo ""
84 if [ "$REPLY" = "y" ] && [ "$NO_COPY" = false ]; then
85 cp "$OUT" "$EXP_TO"
86 elif [ "$REPLY" = "q" ]; then
87 exit 0
90 # A single blank line between loop iterations, even if the user hit enter.
91 if [[ "$REPLY" =~ [a-zA-Z] ]]; then
92 echo
94 done