Repository navigation
Expand file tree
/
Copy pathtest_syntax.sh
More file actions
executable file
·139 lines (112 loc) · 3.93 KB
/
Copy pathtest_syntax.sh
File metadata and controls
executable file
·139 lines (112 loc) · 3.93 KB
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
129
130
131
132
133
134
135
136
137
138
139
#!/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`
# macOS 12 does not have the realpath utility,
# so let's use this workaround instead.
DUNE_BIN_DIR=`cd "$scriptDir/../_build/install/default/bin"; pwd -P`
function exp {
echo "$(dirname $1)/expected/$(basename $1).txt"
}
# Lists the .res and .resi files under the given directories in the array
# files. The list is read before any test runs in the background: under MSYS
# on Windows, starting background jobs while a loop reads the list from a file
# corrupts what the loop reads.
function listFiles {
files=()
while IFS= read -r file; do
files+=("$file")
done < <(find "$@" -name "*.res" -o -name "*.resi")
}
taskCount=0
function maybeWait {
let taskCount+=1
# spawn in batch of 20 processes
[[ $((taskCount % 20)) = 0 ]] && wait
}
# printer API, outcome printer snapshot, parser position and UTF-8 tests
if ! $DUNE_BIN_DIR/syntax_tests; then
printf "syntax_tests failed\n"
exit 1
fi
pushd tests
legacyJsReferences=$(find syntax_tests/data compiler_benchmarks/data \( -name "*.res" -o -name "*.resi" \) -exec grep -nHE '(^|[^[:alnum:]_])Js\.' {} + || true)
if [[ $legacyJsReferences != "" ]]; then
printf "Legacy Js. references remain in syntax fixtures:\n%s\n" "$legacyJsReferences"
exit 1
fi
rm -rf temp
mkdir temp
# parsing
listFiles syntax_tests/data/parsing/{errors,infiniteLoops,recovery}
for file in "${files[@]}"; do
$DUNE_BIN_DIR/res_parser -recover -print ml $file &> $(exp $file) & maybeWait
done
listFiles syntax_tests/data/parsing/{grammar,other}
for file in "${files[@]}"; do
$DUNE_BIN_DIR/res_parser -print ml $file &> $(exp $file) & maybeWait
done
# printing
listFiles syntax_tests/data/{printer,conversion}
for file in "${files[@]}"; do
$DUNE_BIN_DIR/res_parser $file &> $(exp $file) & maybeWait
done
# printing with ast conversion
listFiles syntax_tests/data/ast-mapping
for file in "${files[@]}"; do
$DUNE_BIN_DIR/res_parser -test-ast-conversion -jsx-version 4 $file &> $(exp $file) & maybeWait
done
# printing with ppx
listFiles syntax_tests/data/ppx/react
for file in "${files[@]}"; do
$DUNE_BIN_DIR/res_parser -jsx-version 4 $file &> $(exp $file) & maybeWait
done
wait
warningYellow='\033[0;33m'
successGreen='\033[0;32m'
reset='\033[0m'
git diff --ignore-cr-at-eol $(find syntax_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 syntax_tests/data/! Did you break a test?\n%s\n${reset}" "$diff"
rm -r temp/
exit 1
fi
# roundtrip tests
if [[ $ROUNDTRIP_TEST = 1 ]]; then
echo "Running roundtrip tests…"
roundtripTestsResult="temp/result.txt"
touch $roundtripTestsResult
listFiles syntax_tests/data/printer
for file in "${files[@]}"; do {
mkdir -p temp/$(dirname $file)
rescript1=temp/$file.res
rescript2=temp/$file.2.res
case $file in
*.res ) resIntf="" ;;
*.resi ) resIntf=-interface ;;
esac
# Format the original file, then format the result again
$DUNE_BIN_DIR/res_parser $resIntf -print res $file > $rescript1
$DUNE_BIN_DIR/res_parser $resIntf -print res $rescript1 > $rescript2
# Check idempotency: formatting the formatted text must not change it
diff --unified $rescript1 $rescript2
[[ "$?" = 1 ]] && echo 1 > $roundtripTestsResult
} & maybeWait
done
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
printf "${successGreen}✅ All syntax tests passed.${reset}\n"