FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
rescript/scripts/test_syntax.sh at master · rescript-lang/rescript · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
rescript-lang
/
rescript
Public
Notifications
You must be signed in to change notification settings
Fork
485
Star
7.4k
Code
Issues
120
Pull requests
49
Discussions
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Discussions
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
rescript
/
scripts
/
test_syntax.sh
Copy path
More file actions
More file actions
Latest commit
History
History
History
executable file
·
135 lines (108 loc) · 4.32 KB
Breadcrumbs
rescript
/
scripts
/
test_syntax.sh
Copy path
File metadata and controls
executable file
·
135 lines (108 loc) · 4.32 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
#!
/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
"
}
taskCount=0
function
maybeWait
{
let
taskCount+=1
#
spawn in batch of 20 processes
[[
$((
taskCount
%
20
))
=
0 ]]
&&
wait
}
pushd
tests
legacyJsReferences=
$(
find syntax_tests/data syntax_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
find syntax_tests/data/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 syntax_tests/data/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 syntax_tests/data/{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 ast conversion
find syntax_tests/data/ast-mapping -name
"
*.res
"
-o -name
"
*.resi
"
-o -name
"
*.ml
"
-o -name
"
*.mli
"
>
temp/files.txt
while
read
file
;
do
$DUNE_BIN_DIR
/res_parser -test-ast-conversion -jsx-version 4
$file
&
>
$(
exp
$file
)
&
maybeWait
done
<
temp/files.txt
#
printing with ppx
find syntax_tests/data/ppx/react -name
"
*.res
"
-o -name
"
*.resi
"
>
temp/files.txt
while
read
file
;
do
$DUNE_BIN_DIR
/res_parser -jsx-version 4
$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 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
find syntax_tests/data/{idempotency,printer} -name
"
*.res
"
-o -name
"
*.resi
"
>
temp/files.txt
while
read
file
;
do
{
mkdir -p temp/
$(
dirname
$file
)
sexpAst1=temp/
$file
.sexp
sexpAst2=temp/
$file
.2.sexp
sexpAst3=temp/
$file
.3.sexp
rescript1=temp/
$file
.res
rescript2=temp/
$file
.2.res
case
$file
in
*
.res ) resIntf=
"
"
;;
*
.resi ) resIntf=-interface ;;
esac
#
First pass: original file -> AST1 and text1
$DUNE_BIN_DIR
/res_parser
$resIntf
-print sexp
$file
>
$sexpAst1
$DUNE_BIN_DIR
/res_parser
$resIntf
-print res
$file
>
$rescript1
#
Second pass: text1 -> AST2 and text2
$DUNE_BIN_DIR
/res_parser
$resIntf
-print sexp
$rescript1
>
$sexpAst2
$DUNE_BIN_DIR
/res_parser
$resIntf
-print res
$rescript1
>
$rescript2
#
Third pass: text2 -> AST3 (to check idempotency after normalization)
$DUNE_BIN_DIR
/res_parser
$resIntf
-print sexp
$rescript2
>
$sexpAst3
#
Check AST idempotency: AST2 should equal AST3 (allows AST1 != AST2 for canonicalization)
diff --unified
$sexpAst2
$sexpAst3
[[
"
$?
"
=
1 ]]
&&
echo
1
>
$roundtripTestsResult
#
Check text idempotency: text1 should equal text2
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
printf
"
${successGreen}
✅ All syntax tests passed.
${reset}
\n
"
Back
|
FazBrowse Home
|
New Git URL