Skip to content

Commit f06b607

Browse files
committed
Add simple ppx test.
1 parent c8e4904 commit f06b607

File tree

4 files changed

+50
-0
lines changed

4 files changed

+50
-0
lines changed

tests/tools_tests/ppx/TestPpx.res

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Console.log("ppx test")
2+
3+
type t = [ #A | #B ]
4+
5+
let a: t = #A
6+
let b: t = #B
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Generated by ReScript, PLEASE EDIT WITH CARE
2+
'use strict';
3+
4+
5+
console.log("ppx test");
6+
7+
console.log("ppx test");
8+
9+
let a = "A";
10+
11+
let b = "B";
12+
13+
exports.a = a;
14+
exports.b = b;
15+
/* Not a pure module */

tests/tools_tests/test.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@ for file in src/*.{res,resi}; do
77
fi
88
done
99

10+
for file in ppx/*.res; do
11+
output="src/expected/$(basename $file).jsout"
12+
../../cli/bsc -ppx "../../_build/install/default/bin/rescript-tools ppx" $file > $output
13+
# # CI. We use LF, and the CI OCaml fork prints CRLF. Convert.
14+
if [ "$RUNNER_OS" == "Windows" ]; then
15+
perl -pi -e 's/\r\n/\n/g' -- $output
16+
fi
17+
done
18+
1019
warningYellow='\033[0;33m'
1120
successGreen='\033[0;32m'
1221
reset='\033[0m'

tools/bin/main.ml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,26 @@ let main () =
5656
(Tools.extractEmbedded
5757
~extensionPoints:(extPointNames |> String.split_on_char ',')
5858
~filename))
59+
| ["ppx"; file_in; file_out] ->
60+
let ic = open_in_bin file_in in
61+
let magic =
62+
really_input_string ic (String.length Config.ast_impl_magic_number)
63+
in
64+
let loc = input_value ic in
65+
let ast0 : Parsetree0.structure = input_value ic in
66+
let prefix =
67+
match ast0 with
68+
| c1 :: c2 :: _ -> [c1; c2]
69+
| _ -> []
70+
in
71+
let ast = prefix @ ast0 in
72+
close_in ic;
73+
let oc = open_out_bin file_out in
74+
output_string oc magic;
75+
output_value oc loc;
76+
output_value oc ast;
77+
close_out oc;
78+
exit 0
5979
| ["-h"] | ["--help"] -> logAndExit (Ok help)
6080
| ["-v"] | ["--version"] -> logAndExit (Ok version)
6181
| _ -> logAndExit (Error help)

0 commit comments

Comments
 (0)