Skip to content

Commit

Permalink
Add test for duplicate project name error (ocaml#2372)
Browse files Browse the repository at this point in the history
Add test for duplicate project name error
  • Loading branch information
rgrinberg authored Jul 8, 2019
2 parents f41c7e7 + a76994f commit 5d97787
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 9 deletions.
3 changes: 2 additions & 1 deletion bin/alias.ml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ let in_dir ~name ~recursive ~contexts dir =
let checked = Util.check_path contexts dir in
match checked with
| External _ ->
User_error.raise [ Pp.textf "@@ on the command line must be followed by a relative path" ]
User_error.raise
[ Pp.textf "@@ on the command line must be followed by a relative path" ]
| In_source_dir dir ->
{ dir
; recursive
Expand Down
15 changes: 7 additions & 8 deletions src/scope.ml
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,13 @@ module DB = struct
|> Dune_project.Name.Map.of_list
|> function
| Ok x -> x
| Error (_name, project1, project2) ->
let to_dyn (project : Dune_project.t) =
Dyn.Encoder.(pair Dune_project.Name.to_dyn Path.Source.to_dyn)
(Dune_project.name project, Dune_project.root project)
in
Code_error.raise "Scope.DB.create got two projects with the same name"
[ "project1", to_dyn project1
; "project2", to_dyn project2
| Error (name, project1, project2) ->
let loc = Loc.in_file (Path.source (Dune_project.file project1)) in
let name = Dune_project.Name.to_string_hum name in
let dup_path = Path.source (Dune_project.file project2) in
User_error.raise ~loc
[ Pp.textf "Project %s is already defined in %s"
name (Path.to_string_maybe_quoted dup_path)
]
in
let libs_by_project_name =
Expand Down
10 changes: 10 additions & 0 deletions test/blackbox-tests/dune.inc
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,14 @@
test-cases/duplicate-c-cxx-obj
(progn (run %{exe:cram.exe} -test run.t) (diff? run.t run.t.corrected)))))

(alias
(name duplicate-project-names)
(deps (package dune) (source_tree test-cases/duplicate-project-names))
(action
(chdir
test-cases/duplicate-project-names
(progn (run %{exe:cram.exe} -test run.t) (diff? run.t run.t.corrected)))))

(alias
(name duplicate-target-no-loc)
(deps (package dune) (source_tree test-cases/duplicate-target-no-loc))
Expand Down Expand Up @@ -1631,6 +1639,7 @@
(alias dup-fields)
(alias duplicate-c-cxx)
(alias duplicate-c-cxx-obj)
(alias duplicate-project-names)
(alias duplicate-target-no-loc)
(alias embed-jbuild)
(alias enabled_if)
Expand Down Expand Up @@ -1823,6 +1832,7 @@
(alias dup-fields)
(alias duplicate-c-cxx)
(alias duplicate-c-cxx-obj)
(alias duplicate-project-names)
(alias duplicate-target-no-loc)
(alias embed-jbuild)
(alias enabled_if)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
(lang dune 1.11)
(name foo)
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
(lang dune 1.11)
(name foo)
5 changes: 5 additions & 0 deletions test/blackbox-tests/test-cases/duplicate-project-names/run.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Duplicate project names are currently not allowed:
$ dune build @all
File "b/dune-project", line 1, characters 0-0:
Error: Project foo is already defined in a/dune-project
[1]

0 comments on commit 5d97787

Please sign in to comment.