Skip to content

Commit 6a626ed

Browse files
authored
Fix tests escaping their sandbox (#1217)
* Fix tests escaping their sandbox CLI tests need a `dune-project` and a `.ocamlformat` file to run. This dependencies were not declared so OCamlformat was searching until it find the root of the directory (escaping the `_build` directory). This is needed to use dune-release. * Use --root instead of depending on dune-project
1 parent dba4487 commit 6a626ed

File tree

7 files changed

+98
-50
lines changed

7 files changed

+98
-50
lines changed

test/cli/dune

Lines changed: 91 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -90,39 +90,51 @@
9090
(diff err_stdin_no_kind.expected err_stdin_no_kind.output)))
9191

9292
(rule
93-
(with-outputs-to
94-
stdin_and_impl.output
95-
(system "%{bin:ocamlformat} --impl - < %{dep:sample/b.ml}")))
93+
(targets stdin_and_impl.output)
94+
(deps .ocamlformat)
95+
(action
96+
(with-outputs-to
97+
%{targets}
98+
(system "%{bin:ocamlformat} --root=. --impl - < %{dep:sample/b.ml}"))))
9699

97100
(alias
98101
(name runtest)
99102
(action
100103
(diff stdin_and_impl.expected stdin_and_impl.output)))
101104

102105
(rule
103-
(with-outputs-to
104-
stdin_and_intf.output
105-
(system "%{bin:ocamlformat} --intf - < %{dep:sample/a.mli}")))
106+
(targets stdin_and_intf.output)
107+
(deps .ocamlformat)
108+
(action
109+
(with-outputs-to
110+
%{targets}
111+
(system "%{bin:ocamlformat} --root=. --intf - < %{dep:sample/a.mli}"))))
106112

107113
(alias
108114
(name runtest)
109115
(action
110116
(diff stdin_and_intf.expected stdin_and_intf.output)))
111117

112118
(rule
113-
(with-outputs-to
114-
stdin_and_name.output
115-
(system "%{bin:ocamlformat} --name a.ml - < %{dep:sample/b.ml}")))
119+
(targets stdin_and_name.output)
120+
(deps .ocamlformat)
121+
(action
122+
(with-outputs-to
123+
%{targets}
124+
(system "%{bin:ocamlformat} --root=. --name a.ml - < %{dep:sample/b.ml}"))))
116125

117126
(alias
118127
(name runtest)
119128
(action
120129
(diff stdin_and_name.expected stdin_and_name.output)))
121130

122131
(rule
123-
(with-outputs-to
124-
name_unknown_ext.output
125-
(system "%{bin:ocamlformat} --name b.cpp %{dep:sample/b.ml}")))
132+
(targets name_unknown_ext.output)
133+
(deps .ocamlformat)
134+
(action
135+
(with-outputs-to
136+
%{targets}
137+
(system "%{bin:ocamlformat} --root=. --name b.cpp %{dep:sample/b.ml}"))))
126138

127139
(alias
128140
(name runtest)
@@ -186,50 +198,65 @@
186198
err_several_files_and_name_inplace.output)))
187199

188200
(rule
189-
(with-outputs-to
190-
fmterr_file_and_name.output
191-
(system "! %{bin:ocamlformat} --name foo.ml %{dep:sample/syntax_error.ml}")))
201+
(targets fmterr_file_and_name.output)
202+
(deps .ocamlformat)
203+
(action
204+
(with-outputs-to
205+
%{targets}
206+
(system "! %{bin:ocamlformat} --root=. --name foo.ml %{dep:sample/syntax_error.ml}"))))
192207

193208
(alias
194209
(name runtest)
195210
(action
196211
(diff fmterr_file_and_name.expected fmterr_file_and_name.output)))
197212

198213
(rule
199-
(with-outputs-to
200-
fmterr_stdin_and_name.output
201-
(system
202-
"! %{bin:ocamlformat} --name foo.ml - < %{dep:sample/syntax_error.ml}")))
214+
(targets fmterr_stdin_and_name.output)
215+
(deps .ocamlformat)
216+
(action
217+
(with-outputs-to
218+
%{targets}
219+
(system
220+
"! %{bin:ocamlformat} --root=. --name foo.ml - < %{dep:sample/syntax_error.ml}"))))
203221

204222
(alias
205223
(name runtest)
206224
(action
207225
(diff fmterr_stdin_and_name.expected fmterr_stdin_and_name.output)))
208226

209227
(rule
210-
(with-outputs-to
211-
fmterr_file_bad_kind.output
212-
(system "! %{bin:ocamlformat} --impl %{dep:sample/a.mli}")))
228+
(targets fmterr_file_bad_kind.output)
229+
(deps .ocamlformat)
230+
(action
231+
(with-outputs-to
232+
%{targets}
233+
(system "! %{bin:ocamlformat} --root=. --impl %{dep:sample/a.mli}"))))
213234

214235
(alias
215236
(name runtest)
216237
(action
217238
(diff fmterr_file_bad_kind.expected fmterr_file_bad_kind.output)))
218239

219240
(rule
220-
(with-outputs-to
221-
fmterr_stdin_bad_kind.output
222-
(system "! %{bin:ocamlformat} --impl - < %{dep:sample/a.mli}")))
241+
(targets fmterr_stdin_bad_kind.output)
242+
(deps .ocamlformat)
243+
(action
244+
(with-outputs-to
245+
%{targets}
246+
(system "! %{bin:ocamlformat} --root=. --impl - < %{dep:sample/a.mli}"))))
223247

224248
(alias
225249
(name runtest)
226250
(action
227251
(diff fmterr_stdin_bad_kind.expected fmterr_stdin_bad_kind.output)))
228252

229253
(rule
230-
(with-outputs-to
231-
fmterr_file_and_name_bad_kind.output
232-
(system "! %{bin:ocamlformat} --name foo.ml %{dep:sample/a.mli}")))
254+
(targets fmterr_file_and_name_bad_kind.output)
255+
(deps .ocamlformat)
256+
(action
257+
(with-outputs-to
258+
%{targets}
259+
(system "! %{bin:ocamlformat} --root=. --name foo.ml %{dep:sample/a.mli}"))))
233260

234261
(alias
235262
(name runtest)
@@ -238,9 +265,12 @@
238265
fmterr_file_and_name_bad_kind.output)))
239266

240267
(rule
241-
(with-outputs-to
242-
fmterr_stdin_and_name_bad_kind.output
243-
(system "! %{bin:ocamlformat} --name foo.ml - < %{dep:sample/a.mli}")))
268+
(targets fmterr_stdin_and_name_bad_kind.output)
269+
(deps .ocamlformat)
270+
(action
271+
(with-outputs-to
272+
%{targets}
273+
(system "! %{bin:ocamlformat} --root=. --name foo.ml - < %{dep:sample/a.mli}"))))
244274

245275
(alias
246276
(name runtest)
@@ -249,49 +279,64 @@
249279
fmterr_stdin_and_name_bad_kind.output)))
250280

251281
(rule
252-
(with-outputs-to
253-
check_formatted.output
254-
(run %{bin:ocamlformat} --check %{dep:sample/a.ml})))
282+
(targets check_formatted.output)
283+
(deps .ocamlformat)
284+
(action
285+
(with-outputs-to
286+
%{targets}
287+
(run %{bin:ocamlformat} --root=. --check %{dep:sample/a.ml}))))
255288

256289
(alias
257290
(name runtest)
258291
(action
259292
(diff check_formatted.expected check_formatted.output)))
260293

261294
(rule
262-
(with-outputs-to
263-
check_not_formatted.output
264-
(system "! %{bin:ocamlformat} --check %{dep:sample/b.ml}")))
295+
(targets check_not_formatted.output)
296+
(deps .ocamlformat)
297+
(action
298+
(with-outputs-to
299+
%{targets}
300+
(system "! %{bin:ocamlformat} --root=. --check %{dep:sample/b.ml}"))))
265301

266302
(alias
267303
(name runtest)
268304
(action
269305
(diff check_not_formatted.expected check_not_formatted.output)))
270306

271307
(rule
272-
(with-outputs-to
273-
debug.output
274-
(run %{bin:ocamlformat} --debug %{dep:sample/b.ml})))
308+
(targets debug.output)
309+
(deps .ocamlformat)
310+
(action
311+
(with-outputs-to
312+
%{targets}
313+
(run %{bin:ocamlformat} --root=. --debug %{dep:sample/b.ml}))))
275314

276315
(alias
277316
(name runtest)
278317
(action
279318
(diff debug.expected debug.output)))
280319

281320
(rule
282-
(with-outputs-to
283-
max_iter_1_ok.output
284-
(run ocamlformat --max-iters=1 %{dep:sample/a.ml})))
321+
(targets max_iter_1_ok.output)
322+
(deps .ocamlformat)
323+
(action
324+
(with-outputs-to
325+
%{targets}
326+
(run ocamlformat --root=. --max-iters=1 %{dep:sample/a.ml}))))
285327

286328
(alias
287329
(name runtest)
288330
(action
289331
(diff max_iter_1_ok.expected max_iter_1_ok.output)))
290332

291333
(rule
292-
(with-outputs-to
293-
max_iter_1_failing.output
294-
(system "! %{bin:ocamlformat} --max-iters=1 %{dep:sample/b.ml}")))
334+
(targets max_iter_1_failing.output)
335+
(deps .ocamlformat)
336+
(action
337+
(with-outputs-to
338+
%{targets}
339+
(system "! %{bin:ocamlformat} --root=. --max-iters=1 %{dep:sample/b.ml}"))))
295340

296341
(alias
297342
(name runtest)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
(lang dune 1.11)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
(lang dune 1.11)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
(lang dune 1.11)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
(lang dune 1.11)

test/projects/dune

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
(rule
22
(targets enable_outside_detected_project.output)
33
(deps enable_outside_detected_project/dune-project
4-
enable_outside_detected_project/main.ml)
4+
enable_outside_detected_project/main.ml .ocamlformat)
55
(action
66
(with-stdout-to
77
%{targets}
@@ -17,7 +17,7 @@
1717

1818
(rule
1919
(targets outside_detected_project.output)
20-
(deps outside_detected_project/dune-project outside_detected_project/main.ml)
20+
(deps outside_detected_project/dune-project outside_detected_project/main.ml .ocamlformat)
2121
(action
2222
(with-outputs-to
2323
%{targets}
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
(* The following code should be formatted using OCamlformat's config and not
2-
default *)
1+
(* The following code should be formatted using OCamlformat's config and not default *)
32
type t = {foooooo: string; baaaaar: Baaaaar.t}

0 commit comments

Comments
 (0)