diff --git a/CHANGELOG.md b/CHANGELOG.md index f8ba7dc586..21032f6d57 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -46,6 +46,7 @@ - Remove coercion with 2 types from internal representation. Coercion `e : t1 :> t2` was only supported in `.ml` syntax and never by the `.res` parser. https://github.com/rescript-lang/rescript-compiler/pull/6829 - Convert `caml_format` and `js_math` to `.res`. https://github.com/rescript-lang/rescript-compiler/pull/6834 - Convert `js.ml` files to `.res`. https://github.com/rescript-lang/rescript-compiler/pull/6835 +- Remove old `.ml` tests. https://github.com/rescript-lang/rescript-compiler/pull/6847 #### :nail_care: Polish diff --git a/jscomp/bsc/rescript_compiler_main.ml b/jscomp/bsc/rescript_compiler_main.ml index bbc97c1452..5914aec7a1 100644 --- a/jscomp/bsc/rescript_compiler_main.ml +++ b/jscomp/bsc/rescript_compiler_main.ml @@ -369,9 +369,6 @@ let buckle_script_flags : (string * Bsc_args.spec * string) array = "-bs-list-conditionals", unit_call (fun () -> Pp.list_variables Format.err_formatter), "*internal* List existing conditional variables"; - "-bs-eval", string_call (fun s -> eval s ~suffix:Literals.suffix_ml), - "*internal* (experimental) set the string to be evaluated in OCaml syntax"; - "-e", string_call (fun s -> eval s ~suffix:Literals.suffix_res), "(experimental) set the string to be evaluated in ReScript syntax"; diff --git a/jscomp/build_tests/cmd/input.js b/jscomp/build_tests/cmd/input.js deleted file mode 100644 index 60a7914e73..0000000000 --- a/jscomp/build_tests/cmd/input.js +++ /dev/null @@ -1,60 +0,0 @@ -var p = require("child_process"); - -var assert = require("assert"); - -var { bsc_exe: bsc_exe_path } = require("#cli/bin_path"); - -var react = ` -type u - -external a : u = "react" [@@module] - -external b : unit -> int = "bool" [@@module "react"] - -let v = a -let h = b () -`; - -var foo_react = ` -type bla - - -external foo : bla = "foo.react" [@@module] - -external bar : unit -> bla = "bar" [@@val] [@@module "foo.react"] - -let c = foo - -let d = bar () -`; - -function evalCode(code) { - var bsc_exe = p.spawnSync( - `${bsc_exe_path} -bs-no-version-header -bs-cross-module-opt -w -40 -bs-eval '${code}'`, - { - encoding: "utf8", - shell: true, - cwd: __dirname, - }, - ); - - return bsc_exe; -} - -function test(react) { - var x = evalCode(react); - console.log(x); - assert.ok(x.stdout.match(/require/g).length === 1, "react one"); -} - -test(react); - -assert.ok( - evalCode(react + foo_react).stdout.match(/require/g).length === 2, - "foo react twice ", -); - -assert.ok( - evalCode(foo_react).stdout.match(/require/g).length === 1, - "foo react one", -); diff --git a/jscomp/ext/config.ml b/jscomp/ext/config.ml index 35040eaa5a..6806968410 100644 --- a/jscomp/ext/config.ml +++ b/jscomp/ext/config.ml @@ -26,8 +26,6 @@ and cmt_magic_number = "Caml1999T022" let load_path = ref ([] : string list) -let interface_suffix = ref ".mli" - (* This is normally the same as in obj.ml, but we have to define it separately because it can differ when we're in the middle of a bootstrapping phase. *) diff --git a/jscomp/ext/config.mli b/jscomp/ext/config.mli index d409fe0b60..34c0ce584a 100644 --- a/jscomp/ext/config.mli +++ b/jscomp/ext/config.mli @@ -30,9 +30,6 @@ val unsafe_empty_array : bool ref val load_path : string list ref (* Directories in the search path for .cmi and .cmo files *) -val interface_suffix : string ref -(* Suffix for interface file names *) - val cmi_magic_number : string (* Magic number for compiled interface files *) diff --git a/jscomp/ext/ext_file_extensions.ml b/jscomp/ext/ext_file_extensions.ml index 5449c417f2..2cce993a5f 100644 --- a/jscomp/ext/ext_file_extensions.ml +++ b/jscomp/ext/ext_file_extensions.ml @@ -17,7 +17,7 @@ type valid_input = let classify_input ext = match () with | _ when ext = Literals.suffix_ml -> Ml - | _ when ext = !Config.interface_suffix -> Mli + | _ when ext = Literals.suffix_mli -> Mli | _ when ext = Literals.suffix_ast -> Impl_ast | _ when ext = Literals.suffix_iast -> Intf_ast | _ when ext = Literals.suffix_mlmap -> Mlmap diff --git a/jscomp/ml/typemod.ml b/jscomp/ml/typemod.ml index 0039f91583..d87b1ccd31 100644 --- a/jscomp/ml/typemod.ml +++ b/jscomp/ml/typemod.ml @@ -1688,14 +1688,14 @@ let type_implementation_more ?check_exists sourcefile outputprefix modulename in type_structure initial_env ast (Location.in_file sourcefile) in let simple_sg = simplify_signature sg in begin - let sourceintf = - Filename.remove_extension sourcefile ^ !Config.interface_suffix in let mli_status = !Clflags.assume_no_mli in if mli_status = Clflags.Mli_exists then begin let intf_file = try find_in_path_uncap !Config.load_path (modulename ^ ".cmi") with Not_found -> + let sourceintf = + Filename.remove_extension sourcefile ^ Literals.suffix_resi in raise(Error(Location.in_file sourcefile, Env.empty, Interface_not_compiled sourceintf)) in let dclsig = Env.read_signature modulename intf_file in diff --git a/jscomp/ounit_tests/ounit_cmd_tests.ml b/jscomp/ounit_tests/ounit_cmd_tests.ml deleted file mode 100644 index 22b5471cdf..0000000000 --- a/jscomp/ounit_tests/ounit_cmd_tests.ml +++ /dev/null @@ -1,280 +0,0 @@ -let (//) = Filename.concat - - - - -let ((>::), - (>:::)) = OUnit.((>::),(>:::)) - -let (=~) = OUnit.assert_equal - - - - - -(* let output_of_exec_command command args = - let readme, writeme = Unix.pipe () in - let pid = Unix.create_process command args Unix.stdin writeme Unix.stderr in - let in_chan = Unix.in_channel_of_descr readme *) - - - -let perform_bsc = Ounit_cmd_util.perform_bsc -let bsc_check_eval = Ounit_cmd_util.bsc_check_eval - -let ok b output = - if not b then - Ounit_cmd_util.debug_output output; - OUnit.assert_bool __LOC__ b - -let suites = - __FILE__ - >::: [ - __LOC__ >:: begin fun _ -> - let v_output = perform_bsc [| "-v" |] in - OUnit.assert_bool __LOC__ ((perform_bsc [| "-h" |]).exit_code = 0 ); - OUnit.assert_bool __LOC__ (v_output.exit_code = 0); - (* Printf.printf "\n*>%s" v_output.stdout; *) - (* Printf.printf "\n*>%s" v_output.stderr ; *) - end; - __LOC__ >:: begin fun _ -> - let v_output = - perform_bsc [| "-bs-eval"; {|let str = "'a'" |}|] in - ok (v_output.exit_code = 0) v_output - end; - __LOC__ >:: begin fun _ -> - let v_output = perform_bsc [|"-bs-eval"; {|type 'a arra = 'a array - external - f : - int -> int -> int arra -> unit - = "" - [@@bs.send.pipe:int] - [@@variadic]|}|] in - OUnit.assert_bool __LOC__ (Ext_string.contain_substring v_output.stderr "variadic") - end; - __LOC__ >:: begin fun _ -> - let v_output = perform_bsc [|"-bs-eval"; {|external - f2 : - int -> int -> ?y:int array -> unit - = "" - [@@bs.send.pipe:int] - [@@variadic] |}|] in - OUnit.assert_bool __LOC__ (Ext_string.contain_substring v_output.stderr "variadic") - end; - - __LOC__ >:: begin fun _ -> - let should_be_warning = - bsc_check_eval {| external mk : int -> ([`a|`b [@string]]) = "mk" [@@val] |} in - OUnit.assert_bool __LOC__ - (Ext_string.contain_substring - should_be_warning.stderr "Unused") - end; - __LOC__ >:: begin fun _ -> - let should_err = bsc_check_eval {| -external ff : - resp -> (_ [@as "x"]) -> int -> unit = - "x" [@@set] - |} in - OUnit.assert_bool __LOC__ - (Ext_string.contain_substring should_err.stderr - "Ill defined" - ) - end; - - __LOC__ >:: begin fun _ -> - (* used in return value - This should fail, we did not - support uncurry return value yet - *) - let should_err = bsc_check_eval {| - external v3 : - int -> int -> (int -> int -> int [@uncurry]) - = "v3"[@@val] - - |} in - (* Ounit_cmd_util.debug_output should_err;*) - OUnit.assert_bool __LOC__ - (Ext_string.contain_substring - should_err.stderr "uncurry") - end ; - - __LOC__ >:: begin fun _ -> - let should_err = bsc_check_eval {| - external v4 : - (int -> int -> int [@uncurry]) = "" - [@@val] - - |} in - (* Ounit_cmd_util.debug_output should_err ; *) - OUnit.assert_bool __LOC__ - (Ext_string.contain_substring - should_err.stderr "uncurry") - end ; - - __LOC__ >:: begin fun _ -> - let should_err = bsc_check_eval {| - {js| \uFFF|js} - |} in - OUnit.assert_bool __LOC__ (not @@ Ext_string.is_empty should_err.stderr) - end; - - __LOC__ >:: begin fun _ -> - let should_err = bsc_check_eval {| - external mk : int -> ([`a|`b] [@string]) = "" [@@val] - |} in - OUnit.assert_bool __LOC__ (not @@ Ext_string.is_empty should_err.stderr) - end; - - __LOC__ >:: begin fun _ -> - let should_err = bsc_check_eval {| - external mk : int -> ([`a|`b] ) = "mk" [@@val] - |} in - OUnit.assert_bool __LOC__ ( Ext_string.is_empty should_err.stderr) - (* give a warning or ? - ( [`a | `b ] [@string] ) - (* auto-convert to ocaml poly-variant *) - *) - end; - - __LOC__ >:: begin fun _ -> - let should_err = bsc_check_eval {| - type t - external mk : int -> (_ [@as {json| { x : 3 } |json}]) -> t = "mk" [@@val] - |} in - OUnit.assert_bool __LOC__ (Ext_string.is_empty should_err.stderr) - end - ; - __LOC__ >:: begin fun _ -> - let should_err = bsc_check_eval {| - type t - external mk : int -> (_ [@as {json| { "x" : 3 } |json}]) -> t = "mk" [@@val] - |} in - OUnit.assert_bool __LOC__ (Ext_string.is_empty should_err.stderr) - end - ; - (* #1510 *) - __LOC__ >:: begin fun _ -> - let should_err = bsc_check_eval {| - let should_fail = fun [@this] (Some x) y u -> y + u - |} in - OUnit.assert_bool __LOC__ - (Ext_string.contain_substring should_err.stderr "simple") - end; - - __LOC__ >:: begin fun _ -> - let should_err = bsc_check_eval {| - let should_fail = fun [@this] (Some x as v) y u -> y + u - |} in - (* Ounit_cmd_util.debug_output should_err; *) - OUnit.assert_bool __LOC__ - (Ext_string.contain_substring should_err.stderr "simple") - end; - - (* __LOC__ >:: begin fun _ -> - let should_err = bsc_check_eval {| - external f : string -> unit -> unit = "x.y" [@@send] - |} in - OUnit.assert_bool __LOC__ - (Ext_string.contain_substring should_err.stderr "Not a valid method name") - end; *) - - - __LOC__ >:: begin fun _ -> - let should_err = bsc_check_eval {| - (* let rec must be rejected *) -type t10 = A of t10 [@@ocaml.unboxed];; -let rec x = A x;; - |} in - OUnit.assert_bool __LOC__ - (Ext_string.contain_substring should_err.stderr "This kind of expression is not allowed") - end; - - __LOC__ >:: begin fun _ -> - let should_err = bsc_check_eval {| - type t = {x: int64} [@@unboxed];; -let rec x = {x = y} and y = 3L;; - |} in - OUnit.assert_bool __LOC__ - (Ext_string.contain_substring should_err.stderr "This kind of expression is not allowed") - end; - __LOC__ >:: begin fun _ -> - let should_err = bsc_check_eval {| - type r = A of r [@@unboxed];; -let rec y = A y;; - |} in - OUnit.assert_bool __LOC__ - (Ext_string.contain_substring should_err.stderr "This kind of expression is not allowed") - end; - - __LOC__ >:: begin fun _ -> - let should_err = bsc_check_eval {| - external f : int = "%identity" -|} in - OUnit.assert_bool __LOC__ - (not (Ext_string.is_empty should_err.stderr)) - end; - - __LOC__ >:: begin fun _ -> - let should_err = bsc_check_eval {| - external f : int -> int = "%identity" -|} in - OUnit.assert_bool __LOC__ - (Ext_string.is_empty should_err.stderr) - end; - __LOC__ >:: begin fun _ -> - let should_err = bsc_check_eval {| - external f : int -> int -> int = "%identity" -|} in - OUnit.assert_bool __LOC__ - (not (Ext_string.is_empty should_err.stderr)) - end; - __LOC__ >:: begin fun _ -> - let should_err = bsc_check_eval {| - external f : (int -> int) -> int = "%identity" -|} in - OUnit.assert_bool __LOC__ - ( (Ext_string.is_empty should_err.stderr)) - - end; - - __LOC__ >:: begin fun _ -> - let should_err = bsc_check_eval {| - external f : int -> (int-> int) = "%identity" -|} in - OUnit.assert_bool __LOC__ - (not (Ext_string.is_empty should_err.stderr)) - - end; - __LOC__ >:: begin fun _ -> - let should_err = bsc_check_eval {| - external foo_bar : - (_ [@as "foo"]) -> - string -> - string = "bar" - [@@send] - |} in - OUnit.assert_bool __LOC__ - (Ext_string.contain_substring should_err.stderr "Ill defined attribute") - end; - __LOC__ >:: begin fun _ -> - let should_err = bsc_check_eval {| - external mk : int -> - ( - [`a|`b] - [@string] - ) = "mk" [@@val] - |} in - (* Ounit_cmd_util.debug_output should_err ; *) - OUnit.assert_bool __LOC__ - (Ext_string.contain_substring should_err.stderr - "Unused") - end; - __LOC__ >:: begin fun _ -> - let should_err = bsc_check_eval {| - type -'a t = {k : 'a } [@@deriving abstract] - |} in - OUnit.assert_bool __LOC__ - (Ext_string.contain_substring should_err.stderr "contravariant") - end; - ] - diff --git a/jscomp/ounit_tests/ounit_cmd_util.ml b/jscomp/ounit_tests/ounit_cmd_util.ml deleted file mode 100644 index 9c0faa2476..0000000000 --- a/jscomp/ounit_tests/ounit_cmd_util.ml +++ /dev/null @@ -1,112 +0,0 @@ -let (//) = Filename.concat - -(** may nonterminate when [cwd] is '.' *) -let rec unsafe_root_dir_aux cwd = - if Sys.file_exists (cwd//Literals.bsconfig_json) then cwd - else unsafe_root_dir_aux (Filename.dirname cwd) - -let project_root = unsafe_root_dir_aux (Sys.getcwd ()) -let jscomp = project_root // "jscomp" - -let dune_bin_dir = project_root // "_build" // "install" // "default" // "bin" -let bsc_exe = dune_bin_dir // "bsc" -let runtime_dir = jscomp // "runtime" -let others_dir = jscomp // "others" - - -let stdlib_dir = jscomp // "stdlib-406" - -(* let rec safe_dup fd = - let new_fd = Unix.dup fd in - if (Obj.magic new_fd : int) >= 3 then - new_fd (* [dup] can not be 0, 1, 2*) - else begin - let res = safe_dup fd in - Unix.close new_fd; - res - end *) - -let safe_close fd = - try Unix.close fd with Unix.Unix_error(_,_,_) -> () - - -type output = { - stderr : string ; - stdout : string ; - exit_code : int -} - -let perform command args = - let new_fd_in, new_fd_out = Unix.pipe () in - let err_fd_in, err_fd_out = Unix.pipe () in - match Unix.fork () with - | 0 -> - begin try - safe_close new_fd_in; - safe_close err_fd_in; - Unix.dup2 err_fd_out Unix.stderr ; - Unix.dup2 new_fd_out Unix.stdout; - Unix.execv command args - with _ -> - exit 127 - end - | pid -> - (* when all the descriptors on a pipe's input are closed and the pipe is - empty, a call to [read] on its output returns zero: end of file. - when all the descriptiors on a pipe's output are closed, a call to - [write] on its input kills the writing process (EPIPE). - *) - safe_close new_fd_out ; - safe_close err_fd_out ; - let in_chan = Unix.in_channel_of_descr new_fd_in in - let err_in_chan = Unix.in_channel_of_descr err_fd_in in - let buf = Buffer.create 1024 in - let err_buf = Buffer.create 1024 in - (try - while true do - Buffer.add_string buf (input_line in_chan ); - Buffer.add_char buf '\n' - done; - with - End_of_file -> ()) ; - (try - while true do - Buffer.add_string err_buf (input_line err_in_chan ); - Buffer.add_char err_buf '\n' - done; - with - End_of_file -> ()) ; - let exit_code = match snd @@ Unix.waitpid [] pid with - | Unix.WEXITED exit_code -> exit_code - | Unix.WSIGNALED _signal_number - | Unix.WSTOPPED _signal_number -> 127 in - { - stdout = Buffer.contents buf ; - stderr = Buffer.contents err_buf; - exit_code - } - - -let perform_bsc args = - perform bsc_exe - (Array.append - [|bsc_exe ; - "-bs-package-name" ; "bs-platform"; - "-bs-no-version-header"; - "-bs-cross-module-opt"; - "-w"; - "-40"; - "-I" ; - runtime_dir ; - "-I"; - others_dir ; - "-I" ; - stdlib_dir - |] args) - -let bsc_check_eval str = - perform_bsc [|"-bs-eval"; str|] - - let debug_output o = - Printf.printf "\nexit_code:%d\nstdout:%s\nstderr:%s\n" - o.exit_code o.stdout o.stderr diff --git a/jscomp/ounit_tests/ounit_cmd_util.mli b/jscomp/ounit_tests/ounit_cmd_util.mli deleted file mode 100644 index 5ee3d69ea9..0000000000 --- a/jscomp/ounit_tests/ounit_cmd_util.mli +++ /dev/null @@ -1,16 +0,0 @@ -type output = { - stderr : string ; - stdout : string ; - exit_code : int -} - - -val perform : string -> string array -> output - - -val perform_bsc : string array -> output - - -val bsc_check_eval : string -> output - -val debug_output : output -> unit \ No newline at end of file diff --git a/jscomp/ounit_tests/ounit_ffi_error_debug_test.ml b/jscomp/ounit_tests/ounit_ffi_error_debug_test.ml deleted file mode 100644 index a8b5db5d21..0000000000 --- a/jscomp/ounit_tests/ounit_ffi_error_debug_test.ml +++ /dev/null @@ -1,78 +0,0 @@ -let (//) = Filename.concat - - - - -let ((>::), - (>:::)) = OUnit.((>::),(>:::)) - -let (=~) = OUnit.assert_equal - - - - -let bsc_eval = Ounit_cmd_util.bsc_check_eval - -let debug_output = Ounit_cmd_util.debug_output - - -let suites = - __FILE__ - >::: [ - __LOC__ >:: begin fun _ -> - let output = bsc_eval {| -external err : - hi_should_error:([`a of int | `b of string ] [@string]) -> - unit -> _ = "" [@@obj] - |} in - OUnit.assert_bool __LOC__ - (Ext_string.contain_substring output.stderr "hi_should_error") - end; - __LOC__ >:: begin fun _ -> -let output = bsc_eval {| - external err : - ?hi_should_error:([`a of int | `b of string ] [@string]) -> - unit -> _ = "" [@@obj] - |} in - OUnit.assert_bool __LOC__ - (Ext_string.contain_substring output.stderr "hi_should_error") - end; - __LOC__ >:: begin fun _ -> - let output = bsc_eval {| - external err : - ?hi_should_error:([`a of int | `b of string ] [@string]) -> - unit -> unit = "err" [@@val] - |} in - OUnit.assert_bool __LOC__ - (Ext_string.contain_substring output.stderr "hi_should_error") - end; - - __LOC__ >:: begin fun _ -> - (* - Each [@unwrap] variant constructor requires an argument - *) - let output = - bsc_eval {| - external err : - ?hi_should_error:([`a of int | `b] [@unwrap]) -> unit -> unit = "err" [@@val] - |} - in - OUnit.assert_bool __LOC__ - (Ext_string.contain_substring output.stderr "unwrap") - end; - - __LOC__ >:: begin fun _ -> - (* - [@unwrap] args are not supported in [@@obj] functions - *) - let output = - bsc_eval {| - external err : - ?hi_should_error:([`a of int] [@unwrap]) -> unit -> _ = "" [@@obj] - |} - in - OUnit.assert_bool __LOC__ - (Ext_string.contain_substring output.stderr "hi_should_error") - end - - ] diff --git a/jscomp/ounit_tests/ounit_sexp_tests.ml b/jscomp/ounit_tests/ounit_sexp_tests.ml deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/jscomp/ounit_tests/ounit_tests_main.ml b/jscomp/ounit_tests/ounit_tests_main.ml index b3f4543fa7..daa402ec07 100644 --- a/jscomp/ounit_tests/ounit_tests_main.ml +++ b/jscomp/ounit_tests/ounit_tests_main.ml @@ -1,26 +1,5 @@ -[@@@warning "-32"] - -module Int_array = Vec.Make (struct - type t = int - - let null = 0 -end) - -let v = Int_array.init 10 (fun i -> i) - -let ( >:: ), ( >::: ) = OUnit.(( >:: ), ( >::: )) - -let ( =~ ) x y = - OUnit.assert_equal ~cmp:(Int_array.equal (fun (x : int) y -> x = y)) x y - -let ( =~~ ) x y = - OUnit.assert_equal - ~cmp:(Int_array.equal (fun (x : int) y -> x = y)) - x (Int_array.of_array y) - let suites = - __FILE__ - >::: [ + OUnit.(>:::) __FILE__ [ Ounit_vec_test.suites; Ounit_json_tests.suites; Ounit_path_tests.suites; @@ -35,11 +14,8 @@ let suites = Ounit_hashtbl_tests.suites; Ounit_string_tests.suites; Ounit_topsort_tests.suites; - (* Ounit_sexp_tests.suites; *) Ounit_int_vec_tests.suites; Ounit_ident_mask_tests.suites; - Ounit_cmd_tests.suites; - Ounit_ffi_error_debug_test.suites; Ounit_js_regex_checker_tests.suites; Ounit_utf8_test.suites; Ounit_unicode_tests.suites; diff --git a/jscomp/test/event_ffi.res b/jscomp/test/event_ffi.res index 30f6738f9a..67d76dcc0f 100644 --- a/jscomp/test/event_ffi.res +++ b/jscomp/test/event_ffi.res @@ -40,10 +40,6 @@ let h0 = x => x(.) let h00 = x => x(.) let h1 = (x, y) => x(. y) /* weird case */ -/* -bucklescript$bsc -bs-syntax-only -dsource -bs-eval 'let h1 x = fun y -> x y' -let h1 x y = x y -*/ let h10 = x => x(. 3) let h30 = x => (. a) => x(. 3, 3, a)