Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
Next release
------------

- Use dune.3.18 support to generate `x-maintenance-intent` entry
- Patch `ppx_yojson_conv` dependency which was missing a `v`-prefix
- Support ppxlib 0.37 and 0.38 and require dune.3.22.0 #49
- Adjust test suite to be compatible with >= dune.3.22.0 #48
- Switch to using `ppx_deriving_yojson` instead of `ppx_yojson_conv` #47
- Use dune.3.18 support to generate `x-maintenance-intent` entry #45
- Patch `ppx_yojson_conv` dependency which was missing a `v`-prefix #43
- Introduce a `mutaml.opam.template` to avoid opam linting failure #41
- Adjust RE to support `runtest` on OpenBSD too #40
- Remove `which` and `conf-which` dependency #39
Expand Down
7 changes: 3 additions & 4 deletions dune-project
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(lang dune 3.18)
(lang dune 3.22)

(name mutaml)

Expand Down Expand Up @@ -28,9 +28,8 @@
(tags ("test" "mutation testing"))
(depends
(ocaml (>= 4.12.0))
(dune (>= 3.18))
(dune (and (>= 3.22.0) :with-test))
(ppxlib (and (>= 0.28.0) (< 0.36.0)))
(ocaml (and (< 5.2.0) :with-test))
(ppxlib (>= 0.37.0))
(ppx_deriving_yojson (>= 3.7.0))
stdlib-random
conf-timeout
Expand Down
6 changes: 3 additions & 3 deletions mutaml.opam
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ homepage: "https://github.com/jmid/mutaml"
doc: "https://github.com/jmid/mutaml"
bug-reports: "https://github.com/jmid/mutaml/issues"
depends: [
"dune" {>= "3.22"}
"ocaml" {>= "4.12.0"}
"dune" {>= "3.18"}
"dune" {>= "3.22.0" & with-test}
"ppxlib" {>= "0.28.0" & < "0.36.0"}
"ocaml" {< "5.2.0" & with-test}
"ppxlib" {>= "0.37.0"}
"ppx_deriving_yojson" {>= "3.7.0"}
"stdlib-random"
"conf-timeout"
Expand Down
19 changes: 15 additions & 4 deletions src/ppx/mutaml_ppx.ml
Original file line number Diff line number Diff line change
Expand Up @@ -463,10 +463,13 @@ class mutate_mapper (rs : RS.t) =
self#mutaml_mutant ctx loc(*e0.pexp_loc*) [%expr ()] e0' (string_of_exp e1) in
{ e0 with pexp_desc = Pexp_sequence (e0'',e1') }

| _, Pexp_function cases ->
self#cases ctx cases >>| fun cases_pure -> (* all cases are pure in 'function' *)
let function_ = { e with pexp_desc = Pexp_function cases_pure } in
if Match.cases_contain_matching_patterns cases_pure
| _, Pexp_function (params, constrs, fbody) ->
self#function_body ctx fbody >>| fun fbody ->
let function_ = { e with pexp_desc = Pexp_function (params, constrs, fbody) } in
let contains_matching_patterns = (match fbody with
| Pfunction_body _ -> false
| Pfunction_cases (cases_pure,_,_) -> Match.cases_contain_matching_patterns cases_pure) in
if contains_matching_patterns
then
Exp.attr function_ (* disable pattern-match warning *)
{ attr_name = {txt = "ocaml.warning"; loc};
Expand All @@ -489,6 +492,14 @@ class mutate_mapper (rs : RS.t) =
| _ ->
super#expression ctx e

method! function_body ctx body = match body with
| Pfunction_body e ->
self#expression ctx e >>| fun e ->
Pfunction_body e
| Pfunction_cases (cases,loc,attrs) ->
self#cases ctx cases >>| fun cases_pure -> (* all cases are pure in 'function' *)
Pfunction_cases (cases_pure,loc,attrs)

(* don't mutate attribute parameters such as 'false' in [@@deriving show {with_path=false}] *)
method! attributes _ctx attrs = return attrs

Expand Down
25 changes: 13 additions & 12 deletions test/instrumentation-tests/function-merge-consecutive.t
Original file line number Diff line number Diff line change
Expand Up @@ -658,18 +658,19 @@ Same example that triggers merge-of-consecutive-patterns w/GADTs false
| X
| Lit of int
| Binop of aexp * binop * aexp
let rec interpret xval =
((function
| X -> xval
| Lit i -> i
| Binop (ae0, Add, ae1) when not (__is_mutaml_mutant__ "test:2") ->
let v0 = interpret xval ae0 in
let v1 = interpret xval ae1 in
if __is_mutaml_mutant__ "test:0" then v0 - v1 else v0 + v1
| Binop (ae0, Add, ae1) | Binop (ae0, Mul, ae1) ->
let v0 = interpret xval ae0 in
let v1 = interpret xval ae1 in
if __is_mutaml_mutant__ "test:1" then v0 + v1 else v0 * v1)
let rec interpret =
((fun xval ->
function
| X -> xval
| Lit i -> i
| Binop (ae0, Add, ae1) when not (__is_mutaml_mutant__ "test:2") ->
let v0 = interpret xval ae0 in
let v1 = interpret xval ae1 in
if __is_mutaml_mutant__ "test:0" then v0 - v1 else v0 + v1
| Binop (ae0, Add, ae1) | Binop (ae0, Mul, ae1) ->
let v0 = interpret xval ae0 in
let v1 = interpret xval ae1 in
if __is_mutaml_mutant__ "test:1" then v0 + v1 else v0 * v1)
[@ocaml.warning "-8"])
let () =
(interpret (if __is_mutaml_mutant__ "test:3" then 3 else 2)
Expand Down
2 changes: 2 additions & 0 deletions test/negative-tests/ppx-negtests.t
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,8 @@ Instrument and check that it was received
-dont-apply <names> Exclude these transformations
-cookie NAME=EXPR Set the cookie NAME to EXPR
--cookie Same as -cookie
-raise-embedded-errors Raise the first embedded error found in the processed AST
-allow-deriving-end Whether to allow [@@@deriving.end], which will soon be deprecated.
-seed Set randomness seed for mutaml's instrumentation
-mut-rate Set probability in % of mutating a syntax tree node (default: 50%)
-gadt Allow only pattern mutations compatible with GADTs (default: true)
Expand Down
Loading