Skip to content

Commit 7407445

Browse files
authored
Merge pull request #29 from jmid/fix-attributes
Avoid mutations in attribute parameters
2 parents b9dbf5d + 668132d commit 7407445

File tree

5 files changed

+63
-1
lines changed

5 files changed

+63
-1
lines changed

CHANGES.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Next version
22
------------
33

4-
- ...
4+
- Avoid mutations in attribute parameters #29
55

66
0.2
77
---

dune-project

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,5 @@
3636
(ocaml-compiler-libs (>= v0.12.0))
3737
(ppx_derivers (>= 1.2.1))
3838
(yojson (>= 2.0.0))
39+
(ppx_deriving :with-test)
3940
(ounit2 :with-test)))

mutaml.opam

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ depends: [
2828
"ocaml-compiler-libs" {>= "v0.12.0"}
2929
"ppx_derivers" {>= "1.2.1"}
3030
"yojson" {>= "2.0.0"}
31+
"ppx_deriving" {with-test}
3132
"ounit2" {with-test}
3233
"odoc" {with-doc}
3334
]

src/ppx/mutaml_ppx.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,8 @@ class mutate_mapper (rs : RS.t) =
488488
| _ ->
489489
super#expression ctx e
490490

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

492494
method transform_impl_file ctx impl_ast =
493495
let input_name = Base_exp_context.input_name ctx in

test/issue-attributes.t/run.t

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
Let us try something:
2+
3+
$ ls ../filter_dune_build.sh
4+
../filter_dune_build.sh
5+
6+
Create a file with a deriving show attribute https://github.com/jmid/mutaml/issues/28
7+
$ cat > test.ml << EOF
8+
> type some_type = A | B [@@deriving show {with_path = false}]
9+
> type another_type = C | D of some_type [@@deriving show {with_path = false}]
10+
> ;;
11+
> assert (show_another_type C = "C")
12+
> EOF
13+
14+
Create the dune files:
15+
$ cat > dune-project << EOF
16+
> (lang dune 2.9)
17+
> EOF
18+
19+
$ cat > dune <<'EOF'
20+
> (executable
21+
> (name test)
22+
> (preprocess (pps ppx_deriving.show))
23+
> (instrumentation (backend mutaml))
24+
> )
25+
> EOF
26+
27+
Check that files were created as expected:
28+
$ ls dune* test.ml
29+
dune
30+
dune-project
31+
test.ml
32+
33+
Set seed and (full) mutation rate as environment variables, for repeatability
34+
$ export MUTAML_SEED=896745231
35+
$ export MUTAML_MUT_RATE=100
36+
37+
$ ../filter_dune_build.sh ./test.exe --instrument-with mutaml
38+
Running mutaml instrumentation on "test.ml"
39+
Randomness seed: 896745231 Mutation rate: 100 GADTs enabled: true
40+
Created 0 mutations of test.ml
41+
Writing mutation info to test.muts
42+
43+
$ ls _build
44+
default
45+
log
46+
47+
$ ls _build/default
48+
mutaml-mut-files.txt
49+
test.exe
50+
test.ml
51+
test.muts
52+
test.pp.ml
53+
54+
$ mutaml-runner _build/default/test.exe
55+
read mut file test.muts
56+
Warning: No mutations were listed in test.muts
57+
Did not find any mutations across the files listed in mutaml-mut-files.txt
58+
[1]

0 commit comments

Comments
 (0)