Skip to content

Commit

Permalink
Better document -unused-code-warnings behaviour in tests
Browse files Browse the repository at this point in the history
Signed-off-by: Nathan Rebours <[email protected]>
  • Loading branch information
NathanReb committed Jun 4, 2024
1 parent a20f5a8 commit eaf7065
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions test/deriving_warning/run.t
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
Ppxlib driver has a variety of ways to disable warnings that can be triggered
when using `[@@deriving ...]`. These are all enabled by default but we added
flags to let driver users disable them. To allow smooth transition from always
adding them to never do so and let individual ppx-es do what they must to avoid
triggering warnings, we also added optional arguments to `Deriving.make` so that
the ppx themselves can declare whether they need the driver to disable warnings
or not.

One such flag and optional argument pair is the `-unused-code-warnings` flag and
`?unused_code_warning` `Deriving.V2.make` argument. Both of those default to
`false` and control whether we disable warnings 32 and 60 for generated code
and behave as described by the following table:

Deriver arg | Driver Flag | Unused Code Warnings
-------------|-------------|----------------------
true | true | Enabled
true | false | Disabled*
false | true | Disabled
false | false | Disabled
* By adding warning silencers like [@@@ocaml.waring "-60"] or producing code like
`let _ = zero in...`

We have a driver with 4 derivers linked in:
- zero_do_warn
- one_no_warn
Expand Down Expand Up @@ -76,6 +98,26 @@ and compare the result of both driver invocations:

-----------------------------------------------

The default value of the -unused-code-warnings should be false:

$ ./driver.exe -impl zero_do_warn.ml
type t = int[@@deriving zero_do_warn]
include struct let _ = fun (_ : t) -> () end[@@ocaml.doc "@inline"][@@merlin.hide
]
include
struct
[@@@ocaml.warning "-60"]
module Zero = struct type t =
| T0 end
let zero = Zero.T0
let _ = zero
end[@@ocaml.doc "@inline"][@@merlin.hide ]

As we can see here, the warnings were disabled by the driver, as is expected
with -unused-code-warnings=false.

-----------------------------------------------

Let's consider the following ocaml source file using the one_no_warn deriver

$ cat > one_no_warn.ml << EOF
Expand Down

0 comments on commit eaf7065

Please sign in to comment.