Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add some helpers to make constructing test-cases simpler #401

Merged
merged 2 commits into from
Nov 8, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
272 changes: 93 additions & 179 deletions test/lib/test_solve.ml
Original file line number Diff line number Diff line change
Expand Up @@ -33,215 +33,129 @@ let calculate universe ?(pins = []) root expected =
Alcotest.failf "error: diagnostic %s" e
| Error (`Msg e) -> Alcotest.fail e

let opam_file stanzas =
let opam_stanzas = {|opam-version: "2.0"|} :: stanzas in
let pp_stanzas = Fmt.list ~sep:(Fmt.any "\n") Fmt.string in
let opam_string = Format.asprintf "%a" pp_stanzas opam_stanzas in
OpamFile.OPAM.read_from_string opam_string

let quoted = Printf.sprintf "%s: %S"
let name = quoted "name"
let version = quoted "version"
let dev_repo = quoted "dev-repo"

let url ~src ?checksum () =
match checksum with
| Some checksum ->
Printf.sprintf {|url {
src: %S
checksum: "sha256=%064d"
}|} src
checksum
Leonidas-from-XIV marked this conversation as resolved.
Show resolved Hide resolved
| None -> Printf.sprintf {|url {
src: %S
}|} src

let pp_list = Fmt.list ~sep:Fmt.sp Fmt.Dump.string
let depends pkgs = Format.asprintf "depends: [%a]" pp_list pkgs
let conflict_class cls = Format.asprintf "conflict-class: [%a]" pp_list cls

let ocaml_base_compiler, ocaml_base_expected =
let n = "ocaml-base-compiler" in
let v = "3.14" in
(opam_file [ name n; version v ], (n, v))

let simple () =
let universe =
List.map OpamFile.OPAM.read_from_string
[
{|
opam-version: "2.0"
name: "ocaml-base-compiler"
version: "3.14"
|};
{|
opam-version: "2.0"
name: "p1"
version: "1"
|};
{|
opam-version: "2.0"
name: "p1"
version: "2"
|};
{|
opam-version: "2.0"
name: "p2"
version: "1"
|};
]
in
let root =
OpamFile.OPAM.read_from_string
{|
opam-version: "2.0"
name: "root"
version: "0"
depends: ["p1" "p2"]
|}
[
ocaml_base_compiler;
opam_file [ name "p1"; version "1" ];
opam_file [ name "p1"; version "2" ];
opam_file [ name "p2"; version "1" ];
]
in
let root = opam_file [ name "root"; version "0"; depends [ "p1"; "p2" ] ] in
calculate universe root
[ ("ocaml-base-compiler", "3.14"); ("p1", "2"); ("p2", "1"); ("root", "0") ]
[ ocaml_base_expected; ("p1", "2"); ("p2", "1"); ("root", "0") ]

let conflicts () =
let universe =
List.map OpamFile.OPAM.read_from_string
[
{|
opam-version: "2.0"
name: "ocaml-base-compiler"
version: "3.14"
|};
{|
opam-version: "2.0"
name: "p1"
version: "1"
|};
{|
opam-version: "2.0"
name: "p1"
version: "2"
conflicts: ["p2" {= "1"}]
|};
{|
opam-version: "2.0"
name: "p2"
version: "1"
|};
]
in
let root =
OpamFile.OPAM.read_from_string
{|
opam-version: "2.0"
name: "root"
version: "0"
depends: ["p1" "p2"]
|}
[
ocaml_base_compiler;
opam_file [ name "p1"; version "1" ];
opam_file [ name "p1"; version "2"; {|conflicts: ["p2" {= "1"}]|} ];
opam_file [ name "p2"; version "1" ];
]
in
let root = opam_file [ name "root"; version "0"; depends [ "p1"; "p2" ] ] in
calculate universe root
[ ("ocaml-base-compiler", "3.14"); ("p1", "1"); ("p2", "1"); ("root", "0") ]
[ ocaml_base_expected; ("p1", "1"); ("p2", "1"); ("root", "0") ]

let conflict_class () =
let universe =
List.map OpamFile.OPAM.read_from_string
[
{|
opam-version: "2.0"
name: "ocaml-base-compiler"
version: "3.14"
|};
{|
opam-version: "2.0"
name: "p1"
version: "1"
conflict-class: ["x"]
|};
{|
opam-version: "2.0"
name: "p1"
version: "2"
conflict-class: ["y"]
|};
{|
opam-version: "2.0"
name: "p2"
version: "1"
conflict-class: ["y"]
|};
]
in
let root =
OpamFile.OPAM.read_from_string
{|
opam-version: "2.0"
name: "root"
version: "0"
depends: ["p1" "p2"]
|}
[
ocaml_base_compiler;
opam_file [ name "p1"; version "1"; conflict_class [ "x" ] ];
opam_file [ name "p1"; version "2"; conflict_class [ "y" ] ];
opam_file [ name "p2"; version "1"; conflict_class [ "y" ] ];
]
in
let root = opam_file [ name "root"; version "0"; depends [ "p1"; "p2" ] ] in
calculate universe root
[ ("ocaml-base-compiler", "3.14"); ("p1", "1"); ("p2", "1"); ("root", "0") ]
[ ocaml_base_expected; ("p1", "1"); ("p2", "1"); ("root", "0") ]

let universe_with_url =
List.map OpamFile.OPAM.read_from_string
[
{|
opam-version: "2.0"
name: "ocaml-base-compiler"
version: "3.14"
|};
{|
opam-version: "2.0"
name: "p1"
version: "1"
dev-repo: "x"
url {
src: "https://p.com/p.tbz"
checksum: "sha256=0000000000000000000000000000000000000000000000000000000000000001"
}
|};
{|
opam-version: "2.0"
name: "p1"
version: "2"
dev-repo: "x"
url {
src: "https://p.com/p.tbz"
checksum: "sha256=0000000000000000000000000000000000000000000000000000000000000002"
}
|};
{|
opam-version: "2.0"
name: "p2"
version: "1"
dev-repo: "x"
url {
src: "https://p.com/p.tbz"
checksum: "sha256=0000000000000000000000000000000000000000000000000000000000000001"
}
|};
{|
opam-version: "2.0"
name: "p2"
version: "2"
dev-repo: "x"
url {
src: "https://p.com/p.tbz"
checksum: "sha256=0000000000000000000000000000000000000000000000000000000000000002"
}
|};
]
[
ocaml_base_compiler;
opam_file
[
name "p1";
version "1";
dev_repo "x";
url ~src:"https://p.com/p.tbz" ~checksum:1 ();
];
opam_file
[
name "p1";
version "2";
dev_repo "x";
url ~src:"https://p.com/p.tbz" ~checksum:2 ();
];
opam_file
[
name "p2";
version "1";
dev_repo "x";
url ~src:"https://p.com/p.tbz" ~checksum:1 ();
];
opam_file
[
name "p2";
version "2";
dev_repo "x";
url ~src:"https://p.com/p.tbz" ~checksum:2 ();
];
]

let conflict_url () =
let universe = universe_with_url in
let root =
OpamFile.OPAM.read_from_string
{|
opam-version: "2.0"
name: "root"
version: "0"
depends: ["p1" {= "1"} "p2"]
|}
opam_file [ name "root"; version "0"; {|depends: ["p1" {= "1"} "p2"] |} ]
in
calculate universe root
[ ("ocaml-base-compiler", "3.14"); ("p1", "1"); ("p2", "1"); ("root", "0") ]
[ ocaml_base_expected; ("p1", "1"); ("p2", "1"); ("root", "0") ]

let no_conflict_with_pin () =
let p2_dev =
OpamFile.OPAM.read_from_string
{|
opam-version: "2.0"
name: "p2"
version: "0"
dev-repo: "x"
url {
src: "git+https://x#hash"
}
|}
opam_file
[ name "p2"; version "0"; dev_repo "x"; url ~src:"git+https://x#hash" () ]
in
let universe = p2_dev :: universe_with_url in
let root =
OpamFile.OPAM.read_from_string
{|
opam-version: "2.0"
name: "root"
version: "0"
depends: ["p1" "p2"]
|}
in
let root = opam_file [ name "root"; version "0"; depends [ "p1"; "p2" ] ] in
calculate
~pins:[ OpamPackage.of_string "p2.0" ]
universe root
[ ("ocaml-base-compiler", "3.14"); ("p1", "2"); ("p2", "0"); ("root", "0") ]
[ ocaml_base_expected; ("p1", "2"); ("p2", "0"); ("root", "0") ]

let suite =
( "solve",
Expand Down
Loading