diff --git a/test/common/commonTest.ml b/test/common/commonTest.ml new file mode 100644 index 000000000..609116181 --- /dev/null +++ b/test/common/commonTest.ml @@ -0,0 +1,6 @@ + +let () = + let open Alcotest in + run "SATySFi-Util Test" [ + ("DependencyGraph", DependencyGraphTest.test_cases); + ] diff --git a/test/misc/dependencyGraphTest.ml b/test/common/dependencyGraphTest.ml similarity index 97% rename from test/misc/dependencyGraphTest.ml rename to test/common/dependencyGraphTest.ml index 238d5c9d6..32e0457c2 100644 --- a/test/misc/dependencyGraphTest.ml +++ b/test/common/dependencyGraphTest.ml @@ -1,12 +1,5 @@ -open Main__Types -module ResultMonad = Main__ResultMonad -module TupleList = Main__TupleList - - -module DependencyGraph = Main__DependencyGraph - - +open MyUtil module DG = DependencyGraph.Make(Int) @@ -41,6 +34,7 @@ let pp_vertex ppf vertex = let pp_vertex_set ppf vertices = + let pp_sep ppf () = Format.fprintf ppf ",@ " in Format.fprintf ppf "%a" (Format.pp_print_list ~pp_sep pp_vertex) (DG.VertexSet.elements vertices) diff --git a/test/common/dune b/test/common/dune new file mode 100644 index 000000000..9b43c5c71 --- /dev/null +++ b/test/common/dune @@ -0,0 +1,5 @@ +(test + (name commonTest) + (libraries + satysfi-util + alcotest)) diff --git a/test/misc/dune b/test/misc/dune deleted file mode 100644 index f8cc0ce1f..000000000 --- a/test/misc/dune +++ /dev/null @@ -1,5 +0,0 @@ -(test - (name miscTest) - (libraries - main - alcotest)) diff --git a/test/misc/miscTest.ml b/test/misc/miscTest.ml deleted file mode 100644 index 083e3071e..000000000 --- a/test/misc/miscTest.ml +++ /dev/null @@ -1,7 +0,0 @@ - -let () = - let open Alcotest in - run "SATySFi Misc" [ - ("DependencyGraph", DependencyGraphTest.test_cases); - ("PackageConstraintSolver", PackageConstraintSolverTest.test_cases); - ] diff --git a/test/misc/packageConstraintSolverTest.ml b/test/misc/packageConstraintSolverTest.ml deleted file mode 100644 index cef28dbba..000000000 --- a/test/misc/packageConstraintSolverTest.ml +++ /dev/null @@ -1,146 +0,0 @@ - -open Main__PackageSystemBase -module SemanticVersion = Main__SemanticVersion -module Constant = Main__Constant -module PackageConstraintSolver = Main__PackageConstraintSolver - - -let registry_hash_value = - "c0bebeef4423" - - -let make_version (s_version : string) : SemanticVersion.t = - match SemanticVersion.parse s_version with - | Some(semver) -> semver - | None -> assert false - - -let make_dependency (package_name : package_name) (s_version : string) : package_dependency = - PackageDependency{ - package_name; - spec = - RegisteredDependency{ - registry_local_name = "default"; - version_requirement = SemanticVersion.CompatibleWith(make_version s_version); - }; - } - - -let make_dependency_in_registry (package_name : package_name) (s_version : string) : package_dependency_in_registry = - PackageDependencyInRegistry{ - package_name; - version_requirement = SemanticVersion.CompatibleWith(make_version s_version); - } - - -let make_impl (s_version : string) (deps : package_dependency_in_registry list) : implementation_record = - ImplRecord{ - version = make_version s_version; - source = NoSource; - language_requirement = SemanticVersion.CompatibleWith(Constant.current_language_version); - dependencies = deps; - } - - -let make_lock (package_name : package_name) (s_version : string) : Lock.t = - Lock.{ - package_name; - registry_hash_value = registry_hash_value; - locked_version = make_version s_version; - } - - -let make_solution ?(test_only : bool = false) (package_name : package_name) (s_version : string) (deps : Lock.t list) : package_solution = - { - lock = make_lock package_name s_version; - locked_source = NoSource; - locked_dependencies = deps; - used_in_test_only = test_only; - } - - -let check package_context dependencies_with_flags expected = - let got = PackageConstraintSolver.solve package_context dependencies_with_flags in - Alcotest.(check (option (list (of_pp pp_package_solution)))) "solutions" expected got - - -let solve_test_1 () = - let package_context = - let packages_in_registry = - PackageNameMap.of_seq @@ List.to_seq [ - ("foo", [ - make_impl "1.0.0" []; - make_impl "2.0.0" []; - ]); - ("bar", [ - make_impl "1.0.0" [ make_dependency_in_registry "foo" "2.0.0" ]; - ]); - ("qux", [ - make_impl "1.0.0" [ make_dependency_in_registry "foo" "1.0.0" ]; - ]); - ] - in - let registry_spec = { packages_in_registry; registry_hash_value } in - { registries = RegistryLocalNameMap.singleton "default" registry_spec } - in - let dependencies_with_flags = - [ - (SourceDependency, make_dependency "bar" "1.0.0"); - (SourceDependency, make_dependency "qux" "1.0.0"); - ] - in - let expected = - Some([ - make_solution "bar" "1.0.0" [ - make_lock "foo" "2.0.0"; - ]; - make_solution "foo" "1.0.0" []; - make_solution "foo" "2.0.0" []; - make_solution "qux" "1.0.0" [ - make_lock "foo" "1.0.0"; - ]; - ]) - in - check package_context dependencies_with_flags expected - - -let solve_test_2 () = - let package_context = - let packages_in_registry = - PackageNameMap.of_seq @@ List.to_seq [ - ("foo", [ - make_impl "1.0.0" []; - make_impl "1.1.0" []; - ]); - ("bar", [ - make_impl "1.0.0" [ make_dependency_in_registry "foo" "1.1.0" ]; - ]); - ("qux", [ - make_impl "1.0.0" [ make_dependency_in_registry "foo" "1.0.0" ]; - ]); - ] - in - let registry_spec = { packages_in_registry; registry_hash_value } in - { registries = RegistryLocalNameMap.singleton "default" registry_spec } - in - let dependencies_with_flags = - [ - (SourceDependency, make_dependency "bar" "1.0.0"); - (SourceDependency, make_dependency "qux" "1.0.0"); - ] - in - let expected = - Some([ - make_solution "bar" "1.0.0" [ make_lock "foo" "1.1.0" ]; - make_solution "foo" "1.1.0" []; - make_solution "qux" "1.0.0" [ make_lock "foo" "1.1.0" ]; - ]) - in - check package_context dependencies_with_flags expected - - -let test_cases = - Alcotest.[ - test_case "solve 1" `Quick solve_test_1; - test_case "solve 2" `Quick solve_test_2; - ]