Skip to content

Commit 285376a

Browse files
hhugovouillon
authored andcommitted
Tests: promote with new compilation strategy
1 parent 825941b commit 285376a

File tree

4 files changed

+105
-4
lines changed

4 files changed

+105
-4
lines changed

compiler/tests-compiler/dune.inc

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -666,7 +666,22 @@
666666
(modules rec)
667667
(libraries js_of_ocaml_compiler unix str jsoo_compiler_expect_tests_helper)
668668
(inline_tests
669-
(enabled_if true)
669+
(enabled_if (< %{ocaml_version} 5.2))
670+
(deps
671+
(file %{project_root}/compiler/bin-js_of_ocaml/js_of_ocaml.exe)
672+
(file %{project_root}/compiler/bin-jsoo_minify/jsoo_minify.exe)))
673+
(flags (:standard -open Jsoo_compiler_expect_tests_helper))
674+
(preprocess
675+
(pps ppx_expect)))
676+
677+
(library
678+
;; compiler/tests-compiler/rec52.ml
679+
(name rec52_15)
680+
(enabled_if %{env:js-enabled=})
681+
(modules rec52)
682+
(libraries js_of_ocaml_compiler unix str jsoo_compiler_expect_tests_helper)
683+
(inline_tests
684+
(enabled_if (>= %{ocaml_version} 5.2))
670685
(deps
671686
(file %{project_root}/compiler/bin-js_of_ocaml/js_of_ocaml.exe)
672687
(file %{project_root}/compiler/bin-jsoo_minify/jsoo_minify.exe)))

compiler/tests-compiler/gen-rules/gen.ml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ let prefix : string =
4747

4848
type enabled_if =
4949
| GE5
50+
| GE52
51+
| LT52
5052
| B64
5153
| Any
5254

@@ -58,12 +60,15 @@ let lib_enabled_if = function
5860
let test_enabled_if = function
5961
| "obj" | "lazy" -> GE5
6062
| "gh1051" -> B64
63+
| "rec52" -> GE52
64+
| "rec" -> LT52
6165
| _ -> Any
6266

63-
let enabled_if cond =
64-
match cond with
67+
let enabled_if = function
6568
| Any -> "true"
6669
| GE5 -> "(>= %{ocaml_version} 5)"
70+
| GE52 -> "(>= %{ocaml_version} 5.2)"
71+
| LT52 -> "(< %{ocaml_version} 5.2)"
6772
| B64 -> "%{arch_sixtyfour}"
6873

6974
let js_enabled = function

compiler/tests-compiler/rec.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,5 @@ let%expect_test "let rec" =
7979
return;
8080
}
8181
(globalThis));
82-
//end |}]
82+
//end
83+
|}]

compiler/tests-compiler/rec52.ml

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
(* Js_of_ocaml compiler
2+
* http://www.ocsigen.org/js_of_ocaml/
3+
* Copyright (C) 2024 Hugo Heuzard
4+
*
5+
* This program is free software; you can redistribute it and/or modify
6+
* it under the terms of the GNU Lesser General Public License as published by
7+
* the Free Software Foundation, with linking exception;
8+
* either version 2.1 of the License, or (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU Lesser General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Lesser General Public License
16+
* along with this program; if not, write to the Free Software
17+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18+
*)
19+
20+
open Util
21+
22+
let%expect_test "let rec" =
23+
let p =
24+
{|
25+
let rec a x =
26+
(* syntactic function *)
27+
b x
28+
and b =
29+
(* non-syntactic function *)
30+
let tbl : (int, int) Hashtbl.t = Hashtbl.create 17 in
31+
fun x -> `T (tbl, c, a 0)
32+
and c =
33+
(* block *)
34+
Some (d, default)
35+
and d =
36+
(* 'dynamic' value (not recursive *)
37+
Array.make 5 0
38+
and default =
39+
(* constant, with (spurious) use
40+
of a recursive neighbor *)
41+
let _ = a in
42+
42
43+
|}
44+
in
45+
let p = compile_and_parse p in
46+
print_program p;
47+
[%expect
48+
{|
49+
(function(globalThis){
50+
"use strict";
51+
var
52+
runtime = globalThis.jsoo_runtime,
53+
caml_update_dummy = runtime.caml_update_dummy;
54+
function caml_call2(f, a0, a1){
55+
return (f.l >= 0 ? f.l : f.l = f.length) === 2
56+
? f(a0, a1)
57+
: runtime.caml_call_gen(f, [a0, a1]);
58+
}
59+
var
60+
global_data = runtime.caml_get_global_data(),
61+
Stdlib_Hashtbl = global_data.Stdlib__Hashtbl,
62+
letrec_function_context = [],
63+
c = [],
64+
d = runtime.caml_make_vect(5, 0),
65+
default$0 = 42;
66+
function a(x){return b(x);}
67+
function b(x){
68+
var _a_ = b(0);
69+
return [0, 84, [0, letrec_function_context[1], c, _a_]];
70+
}
71+
var tbl = caml_call2(Stdlib_Hashtbl[1], 0, 17);
72+
caml_update_dummy(letrec_function_context, [0, tbl]);
73+
caml_update_dummy(c, [0, [0, d, default$0]]);
74+
var Test = [0, a, b, c, d, default$0];
75+
runtime.caml_register_global(1, Test, "Test");
76+
return;
77+
}
78+
(globalThis));
79+
//end
80+
|}]

0 commit comments

Comments
 (0)