@@ -492,7 +492,6 @@ module Component = struct
492492 ;;
493493
494494 let test ({ context; common; options } : Options.Test.t Options.t ) =
495- (* Marking the current absence of test-specific options *)
496495 let dir = context.dir in
497496 let test_dune =
498497 Stanza_cst. test common options
@@ -526,6 +525,16 @@ module Component = struct
526525 File. Dune { dir; content; name = " dune-project" }
527526 ;;
528527
528+ (* Convert a libname to a dune atom that can be used to declare a library as
529+ a dependency *)
530+ let lib_name_to_atom lib : Dune_lang.Atom.t =
531+ Lib_name. to_string lib
532+ |> String. map ~f: (function
533+ | '-' -> '_' (* in case the lib_name is public, containing a `-` *)
534+ | c -> c)
535+ |> Dune_lang.Atom. of_string
536+ ;;
537+
529538 let proj_exec dir ({ context; common; options } : Options.Project.t Options.t ) =
530539 let lib_target =
531540 src
@@ -536,10 +545,15 @@ module Component = struct
536545 in
537546 let test_target =
538547 let test_name = " test_" ^ Dune_lang.Atom. to_string common.name in
548+ let libraries =
549+ match common.public with
550+ | None -> []
551+ | Some lib -> [ lib_name_to_atom lib ]
552+ in
539553 test
540554 { context = { context with dir = Path.Source. relative dir " test" }
541555 ; options = ()
542- ; common = { common with name = Dune_lang.Atom. of_string test_name }
556+ ; common = { common with name = Dune_lang.Atom. of_string test_name; libraries }
543557 }
544558 in
545559 let bin_target =
@@ -564,10 +578,15 @@ module Component = struct
564578 in
565579 let test_target =
566580 let test_name = " test_" ^ Dune_lang.Atom. to_string common.name in
581+ let libraries =
582+ match common.public with
583+ | None -> []
584+ | Some lib -> [ lib_name_to_atom lib ]
585+ in
567586 test
568587 { context = { context with dir = Path.Source. relative dir " test" }
569588 ; options = ()
570- ; common = { common with name = Dune_lang.Atom. of_string test_name }
589+ ; common = { common with name = Dune_lang.Atom. of_string test_name; libraries }
571590 }
572591 in
573592 lib_target @ test_target
0 commit comments