Skip to content

Commit b028158

Browse files
authored
Merge pull request #292 from gpetiot/no-such-file
Handle no such file exception
2 parents 7554dde + dbddc3a commit b028158

File tree

8 files changed

+39
-3
lines changed

8 files changed

+39
-3
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#### Fixed
1717

1818
- Report `#require` directive errors (#276, @gpetiot)
19+
- Handle no such file exception: the input file and the values of options `--root` and `--prelude` are checked (#292, @gpetiot)
1920

2021
#### Security
2122

bin/cli.ml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ let file =
3030
let doc = "The file to use." in
3131
named
3232
(fun x -> `File x)
33-
Arg.(required & pos 0 (some string) None & info [] ~doc ~docv:file_docv)
33+
Arg.(
34+
required & pos 0 (some non_dir_file) None & info [] ~doc ~docv:file_docv)
3435

3536
let section =
3637
let doc =
@@ -67,6 +68,12 @@ let verbose_findlib =
6768
Arg.(value & flag & info [ "verbose-findlib" ] ~doc)
6869

6970
let prelude =
71+
let parse s =
72+
let _, file = Mdx.Prelude.env_and_file s in
73+
let parse, _ = Arg.non_dir_file in
74+
match parse file with `Ok _ -> `Ok s | `Error e -> `Error e
75+
in
76+
let prelude = (parse, Fmt.string) in
7077
let doc =
7178
"A file to load as prelude. Can be prefixed with $(i,env:) to specify a \
7279
specific environment to load the prelude in. Multiple prelude files can \
@@ -75,7 +82,7 @@ let prelude =
7582
in
7683
named
7784
(fun x -> `Prelude x)
78-
Arg.(value & opt_all string [] & info [ "prelude" ] ~doc ~docv:"FILE")
85+
Arg.(value & opt_all prelude [] & info [ "prelude" ] ~doc ~docv:"FILE")
7986

8087
let prelude_str =
8188
let doc =
@@ -92,7 +99,7 @@ let root =
9299
let doc = "The directory to run the tests from." in
93100
named
94101
(fun x -> `Root x)
95-
Arg.(value & opt (some string) None & info [ "root" ] ~doc ~docv:"DIR")
102+
Arg.(value & opt (some dir) None & info [ "root" ] ~doc ~docv:"DIR")
96103

97104
let force_output =
98105
let doc = "Force generation of corrected file (even if there was no diff)" in

test/bin/mdx-test/failure/both-prelude/a

Whitespace-only changes.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
(rule
2+
(with-outputs-to
3+
test.output
4+
(with-accepted-exit-codes
5+
(not 0)
6+
(run %{bin:mdx} test foo))))
7+
8+
(rule
9+
(alias runtest)
10+
(action
11+
(diff test.expected test.output)))
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
ocaml-mdx: FILE argument: no `foo' file
2+
Usage: ocaml-mdx test [OPTION]... FILE
3+
Try `ocaml-mdx test --help' or `ocaml-mdx --help' for more information.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
(rule
2+
(with-outputs-to
3+
test.output
4+
(with-accepted-exit-codes
5+
(not 0)
6+
(run %{bin:mdx} test test.md --prelude "env:foo"))))
7+
8+
(rule
9+
(alias runtest)
10+
(action
11+
(diff test.expected test.output)))
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
ocaml-mdx: option `--prelude': no `foo' file
2+
Usage: ocaml-mdx test [OPTION]... FILE
3+
Try `ocaml-mdx test --help' or `ocaml-mdx --help' for more information.

test/bin/mdx-test/misc/no-such-prelude/test.md

Whitespace-only changes.

0 commit comments

Comments
 (0)