Skip to content

Commit

Permalink
wip: fmt before test
Browse files Browse the repository at this point in the history
  • Loading branch information
Swrup committed Nov 27, 2023
1 parent 327525e commit 1674251
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
7 changes: 7 additions & 0 deletions src/cmd_fmt.ml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,10 @@ let cmd inplace (file : string) =
let fmt = Stdlib.Format.formatter_of_out_channel chan in
Format.pp fmt "%a@\n" pp () )
else Format.pp_std "%a@\n" pp ()

let formatted_content file =
match get_printer file with
| Error e ->
Format.pp_err "%s@." e;
exit 1
| Ok pp -> Format.asprintf "%a@\n" pp ()
13 changes: 8 additions & 5 deletions test/main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ 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 ~optimize f =
let test_file ~optimize filename content =
Format.fprintf fmt "testing %s: `%a`... "
(if optimize then "optimized file" else "file ")
Fpath.pp f;
Fpath.pp filename;
try
match Owi.Parse.Script.from_file ~filename:(Fpath.to_string f) with
match Owi.Parse.Script.from_string content with
| Ok script -> begin
match Owi.Script.exec script ~optimize ~no_exhaustion:true with
| Ok () as ok ->
Expand All @@ -42,16 +42,19 @@ let test_directory d =
List.iter
(fun file ->
incr count_total;
let formatted_content =
Owi.Cmd_fmt.formatted_content (Fpath.to_string file)
in
begin
match test_file ~optimize:false file with
match test_file ~optimize:false file formatted_content with
| Ok () -> ()
| Error _e ->
incr count_error;
incr count_total_failed
end;
incr count_total;
begin
match test_file ~optimize:true file with
match test_file ~optimize:true file formatted_content with
| Ok () -> ()
| Error _e ->
incr count_error;
Expand Down

0 comments on commit 1674251

Please sign in to comment.