Skip to content

Commit

Permalink
add test that currently panics
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfv committed Oct 31, 2024
1 parent 9e9eaa2 commit 2af831f
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 24 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -155,5 +155,5 @@ url = { version = "2.5.0" }
uuid = { version = "1.8.0", default-features = false }
walkdir = "2.5.0"
windows-sys = { version = "0.52.0", default-features = false }
zip = { version = "2.1.3", default-features = false }
zip = { version = "2.2.0", default-features = false }
zstd = { version = "0.13.1", default-features = false }
71 changes: 48 additions & 23 deletions crates/rattler_solve/tests/backends.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ macro_rules! solver_backend_tests {
#[test]
fn test_solve_favored() {
let result = solve::<$T>(
dummy_channel_json_path(),
&[dummy_channel_json_path()],
SimpleSolveTask {
specs: &["bors"],
installed_packages: vec![installed_package(
Expand All @@ -267,7 +267,7 @@ macro_rules! solver_backend_tests {
#[test]
fn test_solve_with_error() {
let result = solve::<$T>(
dummy_channel_json_path(),
&[dummy_channel_json_path()],
SimpleSolveTask {
specs: &["foobar >=2", "bors >= 2"],
..SimpleSolveTask::default()
Expand All @@ -283,7 +283,7 @@ macro_rules! solver_backend_tests {
#[test]
fn test_solve_dummy_repo_install_non_existent() {
let result = solve::<$T>(
dummy_channel_json_path(),
&[dummy_channel_json_path()],
SimpleSolveTask {
specs: &["asdfasdf", "foo<4"],
..SimpleSolveTask::default()
Expand All @@ -299,7 +299,7 @@ macro_rules! solver_backend_tests {
#[test]
fn test_solve_dummy_repo_missing_virtual_package() {
let result = solve::<$T>(
dummy_channel_json_path(),
&[dummy_channel_json_path()],
SimpleSolveTask {
specs: &["bar"],
..SimpleSolveTask::default()
Expand All @@ -312,7 +312,7 @@ macro_rules! solver_backend_tests {
#[test]
fn test_solve_dummy_repo_with_virtual_package() {
let pkgs = solve::<$T>(
dummy_channel_json_path(),
&[dummy_channel_json_path()],
SimpleSolveTask {
specs: &["bar"],
virtual_packages: vec![GenericVirtualPackage {
Expand All @@ -335,7 +335,7 @@ macro_rules! solver_backend_tests {
#[test]
fn test_solve_dummy_repo_install_new() {
let pkgs = solve::<$T>(
dummy_channel_json_path(),
&[dummy_channel_json_path()],
SimpleSolveTask {
specs: &["foo<4"],
..SimpleSolveTask::default()
Expand Down Expand Up @@ -381,7 +381,7 @@ macro_rules! solver_backend_tests {
let match_spec = "foo=3.0.2=py36h1af98f8_1";

let operations = solve::<$T>(
dummy_channel_json_path(),
&[dummy_channel_json_path()],
SimpleSolveTask {
specs: &[match_spec],
..SimpleSolveTask::default()
Expand All @@ -406,7 +406,7 @@ macro_rules! solver_backend_tests {
)];

let pkgs = solve::<$T>(
dummy_channel_json_path(),
&[dummy_channel_json_path()],
SimpleSolveTask {
specs: &["foo<4"],
installed_packages: already_installed,
Expand Down Expand Up @@ -435,7 +435,7 @@ macro_rules! solver_backend_tests {
)];

let pkgs = solve::<$T>(
dummy_channel_json_path(),
&[dummy_channel_json_path()],
SimpleSolveTask {
specs: &["foo>=4"],
installed_packages: already_installed,
Expand All @@ -462,7 +462,7 @@ macro_rules! solver_backend_tests {
)];

let pkgs = solve::<$T>(
dummy_channel_json_path(),
&[dummy_channel_json_path()],
SimpleSolveTask {
specs: &["foo<4"],
installed_packages: already_installed,
Expand Down Expand Up @@ -491,7 +491,7 @@ macro_rules! solver_backend_tests {
)];

let pkgs = solve::<$T>(
dummy_channel_json_path(),
&[dummy_channel_json_path()],
SimpleSolveTask {
installed_packages: already_installed,
..SimpleSolveTask::default()
Expand All @@ -508,7 +508,7 @@ macro_rules! solver_backend_tests {
let date = "2021-12-12T12:12:12Z".parse::<DateTime<Utc>>().unwrap();

let pkgs = solve::<$T>(
dummy_channel_json_path(),
&[dummy_channel_json_path()],
SimpleSolveTask {
specs: &["foo"],
exclude_newer: Some(date),
Expand Down Expand Up @@ -546,7 +546,7 @@ macro_rules! solver_backend_tests {
fn test_constraints() {
// There following package is provided as .tar.bz and as .conda in repodata.json
let mut operations = solve::<$T>(
dummy_channel_json_path(),
&[dummy_channel_json_path()],
SimpleSolveTask {
specs: &["foobar"],
constraints: vec!["bors <=1", "nonexisting"],
Expand All @@ -568,7 +568,7 @@ macro_rules! solver_backend_tests {
// This tests that a package that has a constrains on a virtual package is
// properly restricted.
let result = solve::<$T>(
dummy_channel_json_path(),
&[dummy_channel_json_path()],
SimpleSolveTask {
specs: &["cuda-version"],
virtual_packages: vec![GenericVirtualPackage {
Expand Down Expand Up @@ -703,6 +703,8 @@ mod resolvo {
use rattler_solve::{SolveStrategy, SolverImpl, SolverTask};
use url::Url;

use crate::{conda_json_path, conda_json_path_noarch};

use super::{
dummy_channel_json_path, installed_package, solve, solve_real_world, FromStr,
GenericVirtualPackage, SimpleSolveTask, SolveError, Version,
Expand All @@ -713,7 +715,7 @@ mod resolvo {
#[test]
fn test_solve_locked() {
let result = solve::<rattler_solve::resolvo::Solver>(
dummy_channel_json_path(),
&[dummy_channel_json_path()],
SimpleSolveTask {
specs: &["bors >=2"],
pinned_packages: vec![installed_package(
Expand All @@ -735,7 +737,7 @@ mod resolvo {
#[test]
fn test_issue_717() {
let result = solve::<rattler_solve::resolvo::Solver>(
dummy_channel_json_path(),
&[dummy_channel_json_path()],
SimpleSolveTask {
specs: &["issue_717"],
..SimpleSolveTask::default()
Expand All @@ -751,7 +753,7 @@ mod resolvo {
let date = "2021-12-12T12:12:12Z".parse::<DateTime<Utc>>().unwrap();

let result = solve::<rattler_solve::resolvo::Solver>(
dummy_channel_json_path(),
&[dummy_channel_json_path()],
SimpleSolveTask {
specs: &["foo>=4"],
exclude_newer: Some(date),
Expand All @@ -766,7 +768,7 @@ mod resolvo {
#[test]
fn test_lowest_version_strategy_highest_build_number() {
let result = solve::<rattler_solve::resolvo::Solver>(
dummy_channel_json_path(),
&[dummy_channel_json_path()],
SimpleSolveTask {
specs: &["foo"],
strategy: rattler_solve::SolveStrategy::LowestVersion,
Expand All @@ -789,7 +791,7 @@ mod resolvo {
#[test]
fn test_lowest_version_strategy_all() {
let result = solve::<rattler_solve::resolvo::Solver>(
dummy_channel_json_path(),
&[dummy_channel_json_path()],
SimpleSolveTask {
specs: &["foobar"],
strategy: rattler_solve::SolveStrategy::LowestVersion,
Expand Down Expand Up @@ -817,7 +819,7 @@ mod resolvo {
#[test]
fn test_lowest_direct_version_strategy() {
let result = solve::<rattler_solve::resolvo::Solver>(
dummy_channel_json_path(),
&[dummy_channel_json_path()],
SimpleSolveTask {
specs: &["foobar"],
strategy: rattler_solve::SolveStrategy::LowestVersionDirect,
Expand Down Expand Up @@ -918,6 +920,29 @@ mod resolvo {

assert!(matches!(solve_error, SolveError::Unsolvable(_)));
}

#[test]
fn test_panic_on_constraint() {
let result = solve::<rattler_solve::resolvo::Solver>(
&[dummy_channel_json_path()],
SimpleSolveTask {
specs: &["xbar"],
constraints: vec!["xfoo==1"],
pinned_packages: vec![installed_package(
"conda-forge",
"linux-64",
"xfoo",
"1",

Check warning on line 935 in crates/rattler_solve/tests/backends.rs

View workflow job for this annotation

GitHub Actions / Format and Lint

Diff in /home/runner/work/rattler/rattler/crates/rattler_solve/tests/backends.rs

Check warning on line 935 in crates/rattler_solve/tests/backends.rs

View workflow job for this annotation

GitHub Actions / Format, Lint and Test the Python bindings

Diff in /home/runner/work/rattler/rattler/crates/rattler_solve/tests/backends.rs
"xxx",
1,
)],
..SimpleSolveTask::default()
},
);

Check warning on line 942 in crates/rattler_solve/tests/backends.rs

View workflow job for this annotation

GitHub Actions / Format and Lint

Diff in /home/runner/work/rattler/rattler/crates/rattler_solve/tests/backends.rs

Check warning on line 942 in crates/rattler_solve/tests/backends.rs

View workflow job for this annotation

GitHub Actions / Format, Lint and Test the Python bindings

Diff in /home/runner/work/rattler/rattler/crates/rattler_solve/tests/backends.rs
println!("{:?}", result);
}

}

#[derive(Default)]
Expand All @@ -932,10 +957,10 @@ struct SimpleSolveTask<'a> {
}

fn solve<T: SolverImpl + Default>(
repo_path: String,
repo_path: &[String],

Check warning on line 960 in crates/rattler_solve/tests/backends.rs

View workflow job for this annotation

GitHub Actions / Format and Lint

Diff in /home/runner/work/rattler/rattler/crates/rattler_solve/tests/backends.rs

Check warning on line 960 in crates/rattler_solve/tests/backends.rs

View workflow job for this annotation

GitHub Actions / Format, Lint and Test the Python bindings

Diff in /home/runner/work/rattler/rattler/crates/rattler_solve/tests/backends.rs
task: SimpleSolveTask<'_>,
) -> Result<Vec<RepoDataRecord>, SolveError> {
let repo_data = read_repodata(&repo_path);
let repo_data = repo_path.iter().map(|path| read_repodata(path)).collect::<Vec<_>>();

let specs: Vec<_> = task
.specs
Expand All @@ -957,7 +982,7 @@ fn solve<T: SolverImpl + Default>(
pinned_packages: task.pinned_packages,
exclude_newer: task.exclude_newer,
strategy: task.strategy,
..SolverTask::from_iter([&repo_data])
..SolverTask::from_iter(&repo_data)
};

let pkgs = T::default().solve(task)?;
Expand Down
44 changes: 44 additions & 0 deletions test-data/channels/dummy/linux-64/repodata.json
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,50 @@
"subdir": "linux-64",
"timestamp": 1715610974000,
"version": "2.1"
},
"xfoo-1-xxx.tar.bz2": {
"build": "xxx",
"build_number": 0,
"depends": [],
"license": "MIT",
"license_family": "MIT",
"md5": "bc13aa58e2092bcb0b97c561373d3905",
"name": "xfoo",
"sha256": "97ec377d2ad83dfef1194b7aa31b0c9076194e10d995a6e696c9d07dd782b14a",
"size": 414494,
"subdir": "linux-64",
"timestamp": 1715610974000,
"version": "1"
},
"xfoo-2-xxx.tar.bz2": {
"build": "xxx",
"build_number": 0,
"depends": [],
"license": "MIT",
"license_family": "MIT",
"md5": "bc13aa58e2092bcb0b97c561373d3905",
"name": "xfoo",
"sha256": "97ec377d2ad83dfef1194b7aa31b0c9076194e10d995a6e696c9d07dd782b14a",
"size": 414494,
"subdir": "linux-64",
"timestamp": 1715610974000,
"version": "2"
},
"xbar-1-xxx.tar.bz2": {
"build": "xxx",
"build_number": 0,
"depends": [
"xfoo >=2"
],
"license": "MIT",
"license_family": "MIT",
"md5": "bc13aa58e2092bcb0b97c561373d3905",
"name": "xbar",
"sha256": "97ec377d2ad83dfef1194b7aa31b0c9076194e10d995a6e696c9d07dd782b14a",
"size": 414494,
"subdir": "linux-64",
"timestamp": 1715610974000,
"version": "1"
}
},
"packages.conda": {},
Expand Down

0 comments on commit 2af831f

Please sign in to comment.