Skip to content

Commit c759df6

Browse files
committed
Format to canonical form before checking for idempotency test
1 parent e8d70af commit c759df6

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

scripts/test_syntax.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ if [[ $ROUNDTRIP_TEST = 1 ]]; then
8181
mkdir -p temp/$(dirname $file)
8282
sexpAst1=temp/$file.sexp
8383
sexpAst2=temp/$file.2.sexp
84+
sexpAst3=temp/$file.3.sexp
8485
rescript1=temp/$file.res
8586
rescript2=temp/$file.2.res
8687

@@ -89,14 +90,21 @@ if [[ $ROUNDTRIP_TEST = 1 ]]; then
8990
*.resi ) resIntf=-interface ;;
9091
esac
9192

93+
# First pass: original file -> AST1 and text1
9294
$DUNE_BIN_DIR/res_parser $resIntf -print sexp $file > $sexpAst1
9395
$DUNE_BIN_DIR/res_parser $resIntf -print res $file > $rescript1
9496

97+
# Second pass: text1 -> AST2 and text2
9598
$DUNE_BIN_DIR/res_parser $resIntf -print sexp $rescript1 > $sexpAst2
9699
$DUNE_BIN_DIR/res_parser $resIntf -print res $rescript1 > $rescript2
97100

98-
diff --unified $sexpAst1 $sexpAst2
101+
# Third pass: text2 -> AST3 (to check idempotency after normalization)
102+
$DUNE_BIN_DIR/res_parser $resIntf -print sexp $rescript2 > $sexpAst3
103+
104+
# Check AST idempotency: AST2 should equal AST3 (allows AST1 != AST2 for canonicalization)
105+
diff --unified $sexpAst2 $sexpAst3
99106
[[ "$?" = 1 ]] && echo 1 > $roundtripTestsResult
107+
# Check text idempotency: text1 should equal text2
100108
diff --unified $rescript1 $rescript2
101109
[[ "$?" = 1 ]] && echo 1 > $roundtripTestsResult
102110
} & maybeWait

0 commit comments

Comments
 (0)