Skip to content

Commit

Permalink
Add -no-fail-on-assert CLI flag per #270
Browse files Browse the repository at this point in the history
  • Loading branch information
denismerigoux committed Nov 15, 2024
1 parent b11751f commit cb7ab5a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
16 changes: 13 additions & 3 deletions compiler/catala_utils/cli.ml
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,14 @@ module Flags = struct
& info ["x"; "stop-on-error"]
~doc:"Stops the compilation as soon as an error is encountered."

let no_fail_on_assert =
value
& flag
& info ["no-fail-on-assert"]
~doc:
"Instead of aborting the execution on assertion failure, continues \
as if the assertion had succeeded and reports a warning."

let flags =
let make
language
Expand All @@ -219,7 +227,8 @@ module Flags = struct
disable_warnings
max_prec_digits
directory
stop_on_error : options =
stop_on_error
no_fail_on_assert : options =
if debug then Printexc.record_backtrace true;
let path_rewrite =
match directory with
Expand All @@ -234,7 +243,7 @@ module Flags = struct
returns the options record. *)
Global.enforce_options ~language ~debug ~color ~message_format ~trace
~plugins_dirs ~disable_warnings ~max_prec_digits ~path_rewrite
~stop_on_error ()
~stop_on_error ~no_fail_on_assert ()
in
Term.(
const make
Expand All @@ -247,7 +256,8 @@ module Flags = struct
$ disable_warnings
$ max_prec_digits
$ directory
$ stop_on_error)
$ stop_on_error
$ no_fail_on_assert)

let options =
let make input_src name directory options : options =
Expand Down
4 changes: 4 additions & 0 deletions compiler/catala_utils/global.ml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type options = {
mutable max_prec_digits : int;
mutable path_rewrite : raw_file -> file;
mutable stop_on_error : bool;
mutable no_fail_on_assert : bool;
}

(* Note: we force that the global options (ie options common to all commands)
Expand All @@ -58,6 +59,7 @@ let options =
max_prec_digits = 20;
path_rewrite = (fun _ -> assert false);
stop_on_error = false;
no_fail_on_assert = false;
}

let enforce_options
Expand All @@ -72,6 +74,7 @@ let enforce_options
?max_prec_digits
?path_rewrite
?stop_on_error
?no_fail_on_assert
() =
Option.iter (fun x -> options.input_src <- x) input_src;
Option.iter (fun x -> options.language <- x) language;
Expand All @@ -84,6 +87,7 @@ let enforce_options
Option.iter (fun x -> options.max_prec_digits <- x) max_prec_digits;
Option.iter (fun x -> options.path_rewrite <- x) path_rewrite;
Option.iter (fun x -> options.stop_on_error <- x) stop_on_error;
Option.iter (fun x -> options.no_fail_on_assert <- x) no_fail_on_assert;
options

let input_src_file = function FileName f | Contents (_, f) | Stdin f -> f
Expand Down
2 changes: 2 additions & 0 deletions compiler/catala_utils/global.mli
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ type options = private {
mutable max_prec_digits : int;
mutable path_rewrite : raw_file -> file;
mutable stop_on_error : bool;
mutable no_fail_on_assert : bool;
}
(** Global options, common to all subcommands (note: the fields are internally
mutable only for purposes of the [globals] toplevel value defined below) *)
Expand All @@ -77,6 +78,7 @@ val enforce_options :
?max_prec_digits:int ->
?path_rewrite:(raw_file -> file) ->
?stop_on_error:bool ->
?no_fail_on_assert:bool ->
unit ->
options
(** Sets up the global options (side-effect); for specific use-cases only, this
Expand Down

0 comments on commit cb7ab5a

Please sign in to comment.