Skip to content

Commit

Permalink
Add some tests for opam-0install-cudf
Browse files Browse the repository at this point in the history
  • Loading branch information
kit-ty-kate committed Jul 30, 2024
1 parent 8a554d2 commit 76ffd4a
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 3 deletions.
5 changes: 3 additions & 2 deletions dune-project
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,6 @@ the CUDF interface.
")
(depends
cudf
(ocaml (>= 4.10.0))
0install-solver))
(ocaml (>= 4.08.0))
0install-solver
(alcotest :with-test)))
3 changes: 2 additions & 1 deletion opam-0install-cudf.opam
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ bug-reports: "https://github.com/ocaml-opam/opam-0install-solver/issues"
depends: [
"dune" {>= "2.7"}
"cudf"
"ocaml" {>= "4.10.0"}
"ocaml" {>= "4.08.0"}
"0install-solver"
"alcotest" {with-test}
"odoc" {with-doc}
]
build: [
Expand Down
4 changes: 4 additions & 0 deletions test/cudf/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
(test
(name test)
(package opam-0install-cudf)
(libraries alcotest opam-0install-cudf))
87 changes: 87 additions & 0 deletions test/cudf/test.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
let universe =
Cudf.load_universe [
{Cudf.default_package with package = "a"; version = 1};
{Cudf.default_package with package = "a"; version = 2};
{Cudf.default_package with package = "a"; version = 3};
{Cudf.default_package with package = "a"; version = 4};

{Cudf.default_package with package = "b"; version = 1};
{Cudf.default_package with package = "b"; version = 2; pkg_extra = [("avoid-version", `Int 1)]};
{Cudf.default_package with package = "b"; version = 3; pkg_extra = [("avoid-version", `Int 0)]};
{Cudf.default_package with package = "b"; version = 4};

{Cudf.default_package with package = "c"; version = 1; pkg_extra = [("avoid-version", `Int 1)]};
{Cudf.default_package with package = "c"; version = 2};
{Cudf.default_package with package = "c"; version = 3};
{Cudf.default_package with package = "c"; version = 4; pkg_extra = [("avoid-version", `Int 0)]};

{Cudf.default_package with package = "d"; version = 1; pkg_extra = [("avoid-version", `Int 0)]};
{Cudf.default_package with package = "d"; version = 2};
{Cudf.default_package with package = "d"; version = 3};
{Cudf.default_package with package = "d"; version = 4; pkg_extra = [("avoid-version", `Int 1)]};
]

let solve ?prefer_oldest req =
let x = Opam_0install_cudf.create ?prefer_oldest ~constraints:[] universe in
match Opam_0install_cudf.solve x req with
| Ok sel -> Ok (Opam_0install_cudf.packages_of_result sel)
| Error diag -> Error (Opam_0install_cudf.diagnostics ~verbose:true diag)

let simple_solve () =
Alcotest.(check (result (list (pair string int)) string))
"equal" (Ok [("a", 4)])
(solve [("a", `Essential)])

let simple_oldest () =
Alcotest.(check (result (list (pair string int)) string))
"equal" (Ok [("a", 1)])
(solve ~prefer_oldest:true [("a", `Essential)])

let simple_avoid_1 () =
Alcotest.(check (result (list (pair string int)) string))
"equal" (Ok [("b", 4)])
(solve [("b", `Essential)])

let oldest_avoid_1 () =
Alcotest.(check (result (list (pair string int)) string))
"equal" (Ok [("b", 1)])
(solve ~prefer_oldest:true [("b", `Essential)])

let simple_avoid_2 () =
Alcotest.(check (result (list (pair string int)) string))
"equal" (Ok [("c", 4)])
(solve [("c", `Essential)])

let oldest_avoid_2 () =
Alcotest.(check (result (list (pair string int)) string))
"equal" (Ok [("c", 2)])
(solve ~prefer_oldest:true [("c", `Essential)])

let simple_avoid_3 () =
Alcotest.(check (result (list (pair string int)) string))
"equal" (Ok [("d", 3)])
(solve [("d", `Essential)])

let oldest_avoid_3 () =
Alcotest.(check (result (list (pair string int)) string))
"equal" (Ok [("d", 1)])
(solve ~prefer_oldest:true [("d", `Essential)])

let () =
Alcotest.run "cudf"
[
( "simple solve",
[
Alcotest.test_case "normal" `Quick simple_solve;
Alcotest.test_case "oldest" `Quick simple_oldest;
] );
( "avoid-version",
[
Alcotest.test_case "normal 1" `Quick simple_avoid_1;
Alcotest.test_case "oldest 1" `Quick oldest_avoid_2;
Alcotest.test_case "normal 2" `Quick simple_avoid_2;
Alcotest.test_case "oldest 2" `Quick oldest_avoid_2;
Alcotest.test_case "normal 3" `Quick simple_avoid_3;
Alcotest.test_case "oldest 3" `Quick oldest_avoid_3;
] );
]
1 change: 1 addition & 0 deletions test/diagnostics/dune
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
packages/main/main.1/opam
packages/foo/foo.1/opam
packages/foo/foo.2/opam)
(package opam-0install)
(action
(with-stdout-to
test_diagnostics.output
Expand Down

0 comments on commit 76ffd4a

Please sign in to comment.