testing semdiff
[hiphop-php.git] / hphp / hack / test / semdiff / run_semdiff_tests.sh
blobd84b6d1cd245a269a46ac3448fa327588bdbbdcb
1 #!/bin/bash
3 # This script semdiff files with similar names e.g. myfile.1.hhas and
4 # myfile.2.hhas, and compares the result with the corresponding expected
5 # file e.g. myfile.semdiff.exp, or creates it if it does not exists with
6 # a .out extensnion e.g. myfile.semdiff.exp.out
8 if [ "$1" ]; then
9 echo 'ERROR: unexpected argument'
10 echo 'usage: run_semdiff_tests.sh'
11 exit 1
14 RED='\033[0;31m'
15 GREEN='\033[0;32m'
16 YELLOW='\033[0;33m'
17 NC='\033[0m'
19 BASEDIR="$HOME/fbsource/fbcode"
20 BUCK="$BASEDIR/tools/build/buck/bin/buck"
21 DIFF_TMP=/tmp/semdiff_tmp.exp
22 DIFF_RESULT=/tmp/diff_tmp.result
24 # prepare semdiff
25 echo "compiling semdiff"
26 "$BUCK" build @mode/dbgo //hphp/hack/src/hhbc/semdiff:semdiff 2> /dev/null
27 SEMDIFF_PATH=$("$BUCK" targets --show-output //hphp/hack/src/hhbc/semdiff:semdiff 2> /dev/null | cut -d' ' -f2)
28 echo "retrieving path: $SEMDIFF_PATH"
30 HHAS_FILES=$(find "$BASEDIR"/hphp/hack/test/semdiff -type f -name '*.1.hhas')
32 NUM_SUCCESS=0
33 NUM_FAIL=0
34 for FILE in $HHAS_FILES; do
35 basename=${FILE%.1.hhas}
36 test_name=${basename##*/}
37 "$SEMDIFF_PATH" "$FILE" "$basename.2.hhas" > "$DIFF_TMP"
38 if [ ! -f "$basename.semdiff.exp" ]
39 then
40 new_file="$basename.semdiff.exp.out"
41 echo -e "\tcreating $YELLOW $test_name.semdiff.exp.out $NC"
42 mv "$DIFF_TMP" "$new_file"
43 else
44 test_name=${basename##*/}
45 printf "\tdiff'ing %s:\t" "$test_name"
46 diff "$DIFF_TMP" "$basename.semdiff.exp" > "$DIFF_RESULT"
47 if [ -z "$(cat $DIFF_RESULT)" ]
48 then
49 echo -e "$GREEN OK $NC"
50 NUM_SUCCESS=$((NUM_SUCCESS + 1))
51 else
52 echo -e "$RED KO $NC"
53 NUM_FAIL=$((NUM_FAIL + 1))
56 done
58 echo -e "successes:\t$GREEN $NUM_SUCCESS $NC / $((NUM_SUCCESS + NUM_FAIL))"
59 echo -e "failures:\t$RED $NUM_FAIL $NC / $((NUM_SUCCESS + NUM_FAIL))"