From 2af831f95be5c14966dbeae121faf6aebb433cff Mon Sep 17 00:00:00 2001 From: Wolf Vollprecht Date: Thu, 31 Oct 2024 11:40:35 +0100 Subject: [PATCH] add test that currently panics --- Cargo.toml | 2 +- crates/rattler_solve/tests/backends.rs | 71 +++++++++++++------ .../channels/dummy/linux-64/repodata.json | 44 ++++++++++++ 3 files changed, 93 insertions(+), 24 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 7c114c4b9..adc1e957f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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 } diff --git a/crates/rattler_solve/tests/backends.rs b/crates/rattler_solve/tests/backends.rs index 3a903824f..c09062b43 100644 --- a/crates/rattler_solve/tests/backends.rs +++ b/crates/rattler_solve/tests/backends.rs @@ -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( @@ -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() @@ -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() @@ -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() @@ -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 { @@ -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() @@ -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() @@ -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, @@ -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, @@ -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, @@ -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() @@ -508,7 +508,7 @@ macro_rules! solver_backend_tests { let date = "2021-12-12T12:12:12Z".parse::>().unwrap(); let pkgs = solve::<$T>( - dummy_channel_json_path(), + &[dummy_channel_json_path()], SimpleSolveTask { specs: &["foo"], exclude_newer: Some(date), @@ -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"], @@ -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 { @@ -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, @@ -713,7 +715,7 @@ mod resolvo { #[test] fn test_solve_locked() { let result = solve::( - dummy_channel_json_path(), + &[dummy_channel_json_path()], SimpleSolveTask { specs: &["bors >=2"], pinned_packages: vec![installed_package( @@ -735,7 +737,7 @@ mod resolvo { #[test] fn test_issue_717() { let result = solve::( - dummy_channel_json_path(), + &[dummy_channel_json_path()], SimpleSolveTask { specs: &["issue_717"], ..SimpleSolveTask::default() @@ -751,7 +753,7 @@ mod resolvo { let date = "2021-12-12T12:12:12Z".parse::>().unwrap(); let result = solve::( - dummy_channel_json_path(), + &[dummy_channel_json_path()], SimpleSolveTask { specs: &["foo>=4"], exclude_newer: Some(date), @@ -766,7 +768,7 @@ mod resolvo { #[test] fn test_lowest_version_strategy_highest_build_number() { let result = solve::( - dummy_channel_json_path(), + &[dummy_channel_json_path()], SimpleSolveTask { specs: &["foo"], strategy: rattler_solve::SolveStrategy::LowestVersion, @@ -789,7 +791,7 @@ mod resolvo { #[test] fn test_lowest_version_strategy_all() { let result = solve::( - dummy_channel_json_path(), + &[dummy_channel_json_path()], SimpleSolveTask { specs: &["foobar"], strategy: rattler_solve::SolveStrategy::LowestVersion, @@ -817,7 +819,7 @@ mod resolvo { #[test] fn test_lowest_direct_version_strategy() { let result = solve::( - dummy_channel_json_path(), + &[dummy_channel_json_path()], SimpleSolveTask { specs: &["foobar"], strategy: rattler_solve::SolveStrategy::LowestVersionDirect, @@ -918,6 +920,29 @@ mod resolvo { assert!(matches!(solve_error, SolveError::Unsolvable(_))); } + + #[test] + fn test_panic_on_constraint() { + let result = solve::( + &[dummy_channel_json_path()], + SimpleSolveTask { + specs: &["xbar"], + constraints: vec!["xfoo==1"], + pinned_packages: vec![installed_package( + "conda-forge", + "linux-64", + "xfoo", + "1", + "xxx", + 1, + )], + ..SimpleSolveTask::default() + }, + ); + + println!("{:?}", result); + } + } #[derive(Default)] @@ -932,10 +957,10 @@ struct SimpleSolveTask<'a> { } fn solve( - repo_path: String, + repo_path: &[String], task: SimpleSolveTask<'_>, ) -> Result, SolveError> { - let repo_data = read_repodata(&repo_path); + let repo_data = repo_path.iter().map(|path| read_repodata(path)).collect::>(); let specs: Vec<_> = task .specs @@ -957,7 +982,7 @@ fn solve( 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)?; diff --git a/test-data/channels/dummy/linux-64/repodata.json b/test-data/channels/dummy/linux-64/repodata.json index 378ecec96..e311449b8 100644 --- a/test-data/channels/dummy/linux-64/repodata.json +++ b/test-data/channels/dummy/linux-64/repodata.json @@ -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": {},