forked from rescript-lang/rescript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_syntax.sh
executable file
·128 lines (103 loc) · 3.67 KB
/
test_syntax.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#!/bin/bash
# Note:
# 1. This was converted from zsh to bash because zsh is not available on Linux and Windows Github action runners.
# 2. macOS still has bash 3 and therefore no globstar ("**") support.
# Therefore we need to use find + temp files for the file lists.
scriptDir=`dirname $0`
DUNE_BIN_DIR=`realpath $scriptDir/../_build/install/default/bin`
$DUNE_BIN_DIR/syntax_tests
function exp {
echo "$(dirname $1)/expected/$(basename $1).txt"
}
taskCount=0
function maybeWait {
let taskCount+=1
# spawn in batch of 20 processes
[[ $((taskCount % 20)) = 0 ]] && wait
}
pushd res_syntax
rm -rf temp
mkdir temp
# parsing
find tests/parsing/{errors,infiniteLoops,recovery} -name "*.res" -o -name "*.resi" >temp/files.txt
while read file; do
$DUNE_BIN_DIR/res_parser -recover -print ml $file &> $(exp $file) & maybeWait
done <temp/files.txt
find tests/parsing/{grammar,other} -name "*.res" -o -name "*.resi" >temp/files.txt
while read file; do
$DUNE_BIN_DIR/res_parser -print ml $file &> $(exp $file) & maybeWait
done <temp/files.txt
# printing
find tests/{printer,conversion} -name "*.res" -o -name "*.resi" -o -name "*.ml" -o -name "*.mli" >temp/files.txt
while read file; do
$DUNE_BIN_DIR/res_parser $file &> $(exp $file) & maybeWait
done <temp/files.txt
# printing with ppx
find tests/ppx/react -name "*.res" -o -name "*.resi" >temp/files.txt
while read file; do
$DUNE_BIN_DIR/res_parser -jsx-version 4 -jsx-mode "automatic" $file &> $(exp $file) & maybeWait
done <temp/files.txt
wait
warningYellow='\033[0;33m'
successGreen='\033[0;32m'
reset='\033[0m'
git diff --ignore-cr-at-eol $(find tests -name expected) >temp/diff.txt
diff=$(cat temp/diff.txt)
if [[ $diff = "" ]]; then
printf "${successGreen}✅ No unstaged tests difference.${reset}\n"
else
printf "${warningYellow}⚠️ There are unstaged differences in tests/! Did you break a test?\n${diff}\n${reset}"
rm -r temp/
exit 1
fi
# roundtrip tests
if [[ $ROUNDTRIP_TEST = 1 ]]; then
echo "Running roundtrip tests…"
roundtripTestsResult="temp/result.txt"
touch $roundtripTestsResult
find tests/{idempotency,printer} -name "*.res" -o -name "*.resi" -o -name "*.ml" -o -name "*.mli" >temp/files.txt
while read file; do {
mkdir -p temp/$(dirname $file)
sexpAst1=temp/$file.sexp
sexpAst2=temp/$file.2.sexp
rescript1=temp/$file.res
rescript2=temp/$file.2.res
case $file in
*.ml ) class="ml" ; resIntf="" ;;
*.mli ) class="ml" ; resIntf=-interface ;;
*.res ) class="res"; resIntf="" ;;
*.resi ) class="res"; resIntf=-interface ;;
esac
$DUNE_BIN_DIR/res_parser $resIntf -parse $class -print sexp $file > $sexpAst1
$DUNE_BIN_DIR/res_parser $resIntf -parse $class -print res $file > $rescript1
$DUNE_BIN_DIR/res_parser $resIntf -print sexp $rescript1 > $sexpAst2
$DUNE_BIN_DIR/res_parser $resIntf -print res $rescript1 > $rescript2
diff --unified $sexpAst1 $sexpAst2
[[ "$?" = 1 ]] && echo 1 > $roundtripTestsResult
diff --unified $rescript1 $rescript2
[[ "$?" = 1 ]] && echo 1 > $roundtripTestsResult
} & maybeWait
done <temp/files.txt
wait
result=$(cat $roundtripTestsResult)
if [[ $result = "1" ]]; then
printf "${warningYellow}⚠️ Roundtrip tests failed.${reset}\n"
exit 1
else
printf "${successGreen}✅ Roundtrip tests succeeded.${reset}\n"
fi
fi
rm -r temp/
popd
# Check format (does not work on Windows)
case "$(uname -s)" in
Darwin|Linux)
echo "Checking code formatting..."
if opam exec -- dune build @fmt; then
printf "${successGreen}✅ Code formatting ok.${reset}\n"
else
printf "${warningYellow}⚠️ Code formatting failed.${reset}\n"
exit 1
fi
;;
esac