Skip to content

Commit

Permalink
use let+; do not test fmt for now
Browse files Browse the repository at this point in the history
  • Loading branch information
Swrup authored and zapashcanon committed Nov 27, 2023
1 parent 2f27671 commit bfbf51f
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 27 deletions.
13 changes: 6 additions & 7 deletions src/cmd_fmt.ml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ let get_printer filename =
let ext = Filename.extension filename in
match ext with
| ".wat" ->
Result.bind (Parse.Module.from_file ~filename) (fun v ->
Ok (fun fmt () -> Text.pp_modul fmt v) )
let+ v = Parse.Module.from_file ~filename in
fun fmt () -> Text.pp_modul fmt v
| ".wast" ->
Result.bind (Parse.Script.from_file ~filename) (fun v ->
Ok (fun fmt () -> Text.pp_script fmt v) )
let+ v = Parse.Script.from_file ~filename in
fun fmt () -> Text.pp_script fmt v
| _ -> error_s "unsupported file extension"

let cmd inplace (file : string) =
Expand All @@ -32,6 +32,5 @@ let cmd inplace (file : string) =
else Format.pp_std "%a@\n" pp ()

let format_file_to_string (file : string) =
match get_printer file with
| Error _ as e -> e
| Ok pp -> Ok (Format.asprintf "%a@\n" pp ())
let+ pp = get_printer file in
Format.asprintf "%a@\n" pp ()
50 changes: 30 additions & 20 deletions test/main.ml
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
type test_mode =
| Normal
| Fmt
| Opt
[@@warning "-37"]
(* TODO test Fmt *)

let count_total = ref 0

let count_total_failed = ref 0
Expand All @@ -13,27 +20,27 @@ let pp_ok () = Format.fprintf fmt "%a !@." pp_green "OK"
let pp_error msg = Format.fprintf fmt "%a: %s !@." pp_red "FAILED" msg

let test_file mode filename =
let open Owi.Syntax in
Format.fprintf fmt "testing %s: `%a`... "
( match mode with
| `Optimize -> "optimized file"
| `Formatted -> "formatted file"
| `Normal -> "file " )
| Normal -> "file "
| Fmt -> "formatted file"
| Opt -> "optimized file" )
Fpath.pp filename;
try
let res =
match mode with
| `Optimize | `Normal ->
| Normal | Opt ->
Owi.Parse.Script.from_file ~filename:(Fpath.to_string filename)
| `Formatted ->
Result.bind
(Owi.Cmd_fmt.format_file_to_string (Fpath.to_string filename))
Owi.Parse.Script.from_string
| Fmt ->
let* s = Owi.Cmd_fmt.format_file_to_string (Fpath.to_string filename) in
Owi.Parse.Script.from_string s
in
match res with
| Ok script -> begin
match
Owi.Script.exec script
~optimize:(match mode with `Optimize -> true | _ -> false)
~optimize:(match mode with Opt -> true | _ -> false)
~no_exhaustion:true
with
| Ok () as ok ->
Expand All @@ -55,20 +62,23 @@ let test_directory d =
Format.fprintf fmt "testing directory : `%a`@." Fpath.pp d;
match Bos.OS.Dir.contents ~rel:false d with
| Ok l ->
let run mode file =
match test_file mode file with
| Ok () -> ()
| Error _e ->
incr count_error;
incr count_total_failed
in
List.iter
(fun file ->
run Normal file;
incr count_total;
let run mode =
match test_file mode file with
| Ok () -> ()
| Error _e ->
incr count_error;
incr count_total_failed
in
run `Normal;
incr count_total;
run `Optimize;
run `Formatted )
run Opt file;
incr count_total
(* TODO
run Fmt file;
incr count_total
*) )
(List.sort compare l);
if !count_error > 0 then
Error (Format.sprintf "%d test failed" !count_error)
Expand Down

0 comments on commit bfbf51f

Please sign in to comment.