Forbid Path.append _ (In_build_dir _)

Signed-off-by: Jeremie Dimino <jeremie@dimino.org>
This commit is contained in:
Jeremie Dimino 2018-07-09 11:47:14 +01:00 committed by Jérémie Dimino
parent 0ed758ef8a
commit 7c345b677f
2 changed files with 26 additions and 7 deletions

View File

@ -667,13 +667,14 @@ let append_local a b =
| External a -> external_ (External.relative a (Local.to_string b))
let append a b =
match kind b with
| External _ ->
Exn.code_error "Path.append called with non-local second path"
match b with
| In_build_dir _ | External _ ->
Exn.code_error "Path.append called with directory that's \
not in the source tree"
[ "a", sexp_of_t a
; "b", sexp_of_t b
]
| Local b -> append_local a b
| In_source_tree b -> append_local a b
let basename t =
match kind t with

View File

@ -243,12 +243,24 @@ Path.append Path.build_dir (Path.relative Path.root "foo")
Path.append Path.build_dir (Path.relative Path.build_dir "foo")
[%%expect{|
- : Path.t = (In_build_dir "_build/foo")
Exception:
Code_error
(List
[Quoted_string
"Path.append called with directory that's not in the source tree";
List [Atom (A "a"); List [Atom (A "In_build_dir"); Atom (A ".")]];
List [Atom (A "b"); List [Atom (A "In_build_dir"); Atom (A "foo")]]]).
|}]
Path.append Path.root (Path.relative Path.build_dir "foo")
[%%expect{|
- : Path.t = (In_source_tree "_build/foo")
Exception:
Code_error
(List
[Quoted_string
"Path.append called with directory that's not in the source tree";
List [Atom (A "a"); List [Atom (A "In_source_tree"); Atom (A ".")]];
List [Atom (A "b"); List [Atom (A "In_build_dir"); Atom (A "foo")]]]).
|}]
Path.append Path.root (Path.relative Path.root "foo")
@ -263,7 +275,13 @@ Path.append (Path.of_string "/root") (Path.relative Path.root "foo")
Path.append (Path.of_string "/root") (Path.relative Path.build_dir "foo")
[%%expect{|
- : Path.t = (External "/root/_build/foo")
Exception:
Code_error
(List
[Quoted_string
"Path.append called with directory that's not in the source tree";
List [Atom (A "a"); List [Atom (A "External"); Atom (A "/root")]];
List [Atom (A "b"); List [Atom (A "In_build_dir"); Atom (A "foo")]]]).
|}]
Path.rm_rf (Path.of_string "/does/not/exist/foo/bar/baz")