Skip to content

Commit

Permalink
chore: format code
Browse files Browse the repository at this point in the history
  • Loading branch information
eWert-Online committed Apr 19, 2024
1 parent 2e35c0c commit 40b1ed9
Show file tree
Hide file tree
Showing 24 changed files with 465 additions and 470 deletions.
10 changes: 5 additions & 5 deletions bin/Main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,12 @@ let default_cmd =
(fun () ->
OSnap.run t
|> Lwt_result.map_error (fun e ->
let () = OSnap.teardown t in
e))
let () = OSnap.teardown t in
e))
(function
| exn ->
let () = OSnap.teardown t in
Lwt_result.fail (`OSnap_Unknown_Error exn))
| exn ->
let () = OSnap.teardown t in
Lwt_result.fail (`OSnap_Unknown_Error exn))
in
Lwt_main.run run |> handle_response
in
Expand Down
100 changes: 49 additions & 51 deletions lib/OSnap.ml
Original file line number Diff line number Diff line change
Expand Up @@ -25,37 +25,35 @@ let setup ~noCreate ~noOnly ~noSkip ~parallelism ~config_path =
let*? only_tests, tests =
all_tests
|> Lwt_list.map_p_until_exception (fun test ->
test.sizes
|> Lwt_list.map_p_until_exception (fun size ->
let { name = _size_name; width; height } = size in
let filename = Test.get_filename test.name width height in
let current_image_path = snapshot_dir ^ filename in
let exists = Sys.file_exists current_image_path in
if noCreate && not exists
then
Lwt_result.fail
(`OSnap_Invalid_Run
(Printf.sprintf
"Flag --no-create is set. Cannot create new images for %s."
test.name))
else if noSkip && test.skip
then
Lwt_result.fail
(`OSnap_Invalid_Run
(Printf.sprintf
"Flag --no-skip is set. Cannot skip test %s."
test.name))
else if noOnly && test.only
then
Lwt_result.fail
(`OSnap_Invalid_Run
(Printf.sprintf
"Flag --no-only is set but the following test still has only set \
to true %s."
test.name))
else if test.only
then Lwt_result.return (Either.left (test, size, exists))
else Lwt_result.return (Either.right (test, size, exists))))
test.sizes
|> Lwt_list.map_p_until_exception (fun size ->
let { name = _size_name; width; height } = size in
let filename = Test.get_filename test.name width height in
let current_image_path = snapshot_dir ^ filename in
let exists = Sys.file_exists current_image_path in
if noCreate && not exists
then
Lwt_result.fail
(`OSnap_Invalid_Run
(Printf.sprintf
"Flag --no-create is set. Cannot create new images for %s."
test.name))
else if noSkip && test.skip
then
Lwt_result.fail
(`OSnap_Invalid_Run
(Printf.sprintf "Flag --no-skip is set. Cannot skip test %s." test.name))
else if noOnly && test.only
then
Lwt_result.fail
(`OSnap_Invalid_Run
(Printf.sprintf
"Flag --no-only is set but the following test still has only set to \
true %s."
test.name))
else if test.only
then Lwt_result.return (Either.left (test, size, exists))
else Lwt_result.return (Either.right (test, size, exists))))
|> Lwt_result.map List.flatten
|> Lwt_result.map (List.partition_map Fun.id)
in
Expand All @@ -67,7 +65,7 @@ let setup ~noCreate ~noOnly ~noSkip ~parallelism ~config_path =
let tests_to_run =
tests_to_run
|> List.fast_sort (fun (_test, _size, exists1) (_test, _size, exists2) ->
Bool.compare exists1 exists2)
Bool.compare exists1 exists2)
in
let*? browser = Browser.Launcher.make () in
Lwt_result.return { config; tests_to_run; start_time; browser }
Expand All @@ -88,25 +86,25 @@ let run t =
let*? test_results =
tests_to_run
|> Lwt_list.map_p_until_exception (fun test ->
Lwt_pool.use pool (fun target ->
let test, { name = size_name; width; height }, exists = test in
let test =
Test.Types.
{ exists
; size_name
; width
; height
; skip = test.OSnap_Config.Types.skip
; url = test.OSnap_Config.Types.url
; name = test.OSnap_Config.Types.name
; actions = test.OSnap_Config.Types.actions
; ignore_regions = test.OSnap_Config.Types.ignore
; threshold = test.OSnap_Config.Types.threshold
; warnings = []
; result = None
}
in
Test.run config (Result.get_ok target) test))
Lwt_pool.use pool (fun target ->
let test, { name = size_name; width; height }, exists = test in
let test =
Test.Types.
{ exists
; size_name
; width
; height
; skip = test.OSnap_Config.Types.skip
; url = test.OSnap_Config.Types.url
; name = test.OSnap_Config.Types.name
; actions = test.OSnap_Config.Types.actions
; ignore_regions = test.OSnap_Config.Types.ignore
; threshold = test.OSnap_Config.Types.threshold
; warnings = []
; result = None
}
in
Test.run config (Result.get_ok target) test))
in
let end_time = Unix.gettimeofday () in
let seconds = end_time -. start_time in
Expand Down
58 changes: 29 additions & 29 deletions lib/OSnap.mli
Original file line number Diff line number Diff line change
Expand Up @@ -15,42 +15,42 @@ val setup
-> parallelism:int option
-> config_path:string
-> ( t
, [> `OSnap_Chromium_Download_Failed
| `OSnap_CDP_Connection_Failed
| `OSnap_CDP_Protocol_Error of string
| `OSnap_Config_Duplicate_Size_Names of string list
| `OSnap_Config_Duplicate_Tests of string list
| `OSnap_Config_Global_Invalid of string
| `OSnap_Config_Global_Not_Found
| `OSnap_Config_Undefined_Function of string * string
| `OSnap_Config_Invalid of string * string
| `OSnap_Config_Parse_Error of string * string
| `OSnap_Config_Unsupported_Format of string
| `OSnap_Invalid_Run of string
] )
Lwt_result.t
, [> `OSnap_Chromium_Download_Failed
| `OSnap_CDP_Connection_Failed
| `OSnap_CDP_Protocol_Error of string
| `OSnap_Config_Duplicate_Size_Names of string list
| `OSnap_Config_Duplicate_Tests of string list
| `OSnap_Config_Global_Invalid of string
| `OSnap_Config_Global_Not_Found
| `OSnap_Config_Undefined_Function of string * string
| `OSnap_Config_Invalid of string * string
| `OSnap_Config_Parse_Error of string * string
| `OSnap_Config_Unsupported_Format of string
| `OSnap_Invalid_Run of string
] )
Lwt_result.t

val teardown : t -> unit

val run
: t
-> ( unit
, [> `OSnap_CDP_Protocol_Error of string
| `OSnap_FS_Error of string
| `OSnap_Test_Failure
] )
Lwt_result.t
, [> `OSnap_CDP_Protocol_Error of string
| `OSnap_FS_Error of string
| `OSnap_Test_Failure
] )
Lwt_result.t

val cleanup
: config_path:string
-> ( unit
, [> `OSnap_Config_Duplicate_Size_Names of string list
| `OSnap_Config_Duplicate_Tests of string list
| `OSnap_Config_Global_Invalid of string
| `OSnap_Config_Global_Not_Found
| `OSnap_Config_Invalid of string * string
| `OSnap_Config_Parse_Error of string * string
| `OSnap_Config_Undefined_Function of string * string
| `OSnap_Config_Unsupported_Format of string
] )
Lwt_result.t
, [> `OSnap_Config_Duplicate_Size_Names of string list
| `OSnap_Config_Duplicate_Tests of string list
| `OSnap_Config_Global_Invalid of string
| `OSnap_Config_Global_Not_Found
| `OSnap_Config_Invalid of string * string
| `OSnap_Config_Parse_Error of string * string
| `OSnap_Config_Undefined_Function of string * string
| `OSnap_Config_Unsupported_Format of string
] )
Lwt_result.t
Loading

0 comments on commit 40b1ed9

Please sign in to comment.