Skip to content

Commit

Permalink
Add more MatchSpec tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AntoinePrv committed Mar 4, 2024
1 parent bd628e7 commit e9c45df
Showing 1 changed file with 125 additions and 3 deletions.
128 changes: 125 additions & 3 deletions libmamba/tests/src/specs/test_match_spec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,18 @@ TEST_SUITE("specs::match_spec")
CHECK_EQ(ms.filename(), "libgcc-ng-11.2.0-h1d223b6_13.tar.bz2");
}

SUBCASE("https://conda.anaconda.org/conda-canary/linux-64/conda-4.3.21.post699+1dab973-py36h4a561cd_0.tar.bz2"
)
{
auto ms = MatchSpec::parse(
"https://conda.anaconda.org/conda-canary/linux-64/conda-4.3.21.post699+1dab973-py36h4a561cd_0.tar.bz2"
)
.value();
CHECK_EQ(ms.name().str(), "conda");
CHECK_EQ(ms.version().str(), "==4.3.21.0post699+1dab973"); // Note the ``.0post``
CHECK_EQ(ms.build_string().str(), "py36h4a561cd_0");
}

SUBCASE("/home/randomguy/Downloads/linux-64/_libgcc_mutex-0.1-conda_forge.tar.bz2")
{
auto ms = MatchSpec::parse(
Expand Down Expand Up @@ -182,13 +194,19 @@ TEST_SUITE("specs::match_spec")
{
auto ms = MatchSpec::parse("foo=1.0=2").value();
CHECK_EQ(ms.conda_build_form(), "foo 1.0.* 2");
CHECK_EQ(ms.name().str(), "foo");
CHECK_EQ(ms.version().str(), "=1.0");
CHECK_EQ(ms.build_string().str(), "2");
CHECK_EQ(ms.str(), "foo=1.0=2");
}

SUBCASE("foo=1.0=2[md5=123123123, license=BSD-3, fn='test 123.tar.bz2']")
{
auto ms = MatchSpec::parse("foo=1.0=2[md5=123123123, license=BSD-3, fn='test 123.tar.bz2']")
.value();
CHECK_EQ(ms.name().str(), "foo");
CHECK_EQ(ms.version().str(), "=1.0");
CHECK_EQ(ms.build_string().str(), "2");
CHECK_EQ(ms.conda_build_form(), "foo 1.0.* 2");
CHECK_EQ(ms.str(), R"ms(foo=1.0=2[fn="test 123.tar.bz2",md5=123123123,license=BSD-3])ms");
}
Expand All @@ -200,24 +218,74 @@ TEST_SUITE("specs::match_spec")
)
.value();
CHECK_EQ(ms.channel().value().str(), "abcdef");
CHECK_EQ(ms.name().str(), "foo");
CHECK_EQ(ms.version().str(), "=1.0");
CHECK_EQ(ms.build_string().str(), "2");
CHECK_EQ(ms.conda_build_form(), "foo 1.0.* 2");
CHECK_EQ(
ms.str(),
R"ms(abcdef::foo=1.0=2[fn="test 123.tar.bz2",md5=123123123,license=BSD-3])ms"
);
}

SUBCASE(R"(defaults::numpy=1.8=py27_0 [name="pytorch" channel='anaconda',version=">=1.8,<2|1.9", build='3'])"
)
{
auto ms = MatchSpec::parse(
R"(defaults::numpy=1.8=py27_0 [name="pytorch" channel='anaconda',version=">=1.8,<2|1.9", build='3'])"
)
.value();
CHECK_EQ(ms.channel().value().str(), "defaults");
CHECK_EQ(ms.name().str(), "numpy");
CHECK_EQ(ms.version().str(), "=1.8");
CHECK_EQ(ms.build_string().str(), "py27_0");
}

SUBCASE(R"(defaults::numpy [ "pytorch" channel='anaconda',version=">=1.8,<2|1.9", build='3'])")
{
auto ms = MatchSpec::parse(
R"(defaults::numpy [ "pytorch" channel='anaconda',version=">=1.8,<2|1.9", build='3'])"
)
.value();
CHECK_EQ(ms.channel().value().str(), "defaults");
CHECK_EQ(ms.name().str(), "numpy");
CHECK_EQ(ms.version().str(), ">=1.8,(<2|==1.9)");
CHECK_EQ(ms.build_string().str(), "3");
}

SUBCASE("numpy >1.8,<2|==1.7,!=1.9,~=1.7.1 py34_0")
{
auto ms = MatchSpec::parse(R"(numpy >1.8,<2|==1.7,!=1.9,~=1.7.1 py34_0)").value();
CHECK_EQ(ms.name().str(), "numpy");
CHECK_EQ(ms.version().str(), ">1.8,((<2|==1.7),(!=1.9,~=1.7))");
CHECK_EQ(ms.build_string().str(), "py34_0");
}

SUBCASE("*[md5=fewjaflknd]")
{
auto ms = MatchSpec::parse("*[md5=fewjaflknd]").value();
CHECK(ms.name().is_free());
CHECK_EQ(ms.md5(), "fewjaflknd");
}

SUBCASE("libblas=*=*mkl")
{
auto ms = MatchSpec::parse("libblas=*=*mkl").value();
CHECK_EQ(ms.conda_build_form(), "libblas * *mkl");
CHECK_EQ(ms.name().str(), "libblas");
CHECK_EQ(ms.version().str(), "=*");
CHECK_EQ(ms.build_string().str(), "*mkl");
// CHECK_EQ(ms.str(), "foo==1.0=2");
}

SUBCASE("libblas=0.15*")
{
// '*' is part of the version, not the glob
auto ms = MatchSpec::parse("libblas=0.15*").value();
CHECK_EQ(ms.conda_build_form(), "libblas 0.15*.*");
CHECK_EQ(ms.name().str(), "libblas");
CHECK_EQ(ms.version().str(), "=0.15*");
CHECK(ms.build_string().is_free());
}

SUBCASE("xtensor =0.15*")
Expand All @@ -226,49 +294,103 @@ TEST_SUITE("specs::match_spec")
auto ms = MatchSpec::parse("xtensor =0.15*").value();
CHECK_EQ(ms.conda_build_form(), "xtensor 0.15*.*");
CHECK_EQ(ms.str(), "xtensor=0.15*");
CHECK_EQ(ms.name().str(), "xtensor");
CHECK_EQ(ms.version().str(), "=0.15*");
CHECK(ms.build_string().is_free());
}

SUBCASE("numpy=1.20")
{
auto ms = MatchSpec::parse("numpy=1.20").value();
CHECK_EQ(ms.str(), "numpy=1.20");
CHECK_EQ(ms.name().str(), "numpy");
CHECK_EQ(ms.version().str(), "=1.20");
CHECK(ms.build_string().is_free());
}

SUBCASE("conda-forge::tzdata")
{
auto ms = MatchSpec::parse("conda-forge::tzdata").value();
CHECK_EQ(ms.str(), "conda-forge::tzdata");
CHECK_EQ(ms.channel().value().str(), "conda-forge");
CHECK_EQ(ms.name().str(), "tzdata");
CHECK(ms.version().is_explicitly_free());
CHECK(ms.build_string().is_free());
}

SUBCASE("conda-forge/noarch::tzdata")
{
auto ms = MatchSpec::parse("conda-forge/noarch::tzdata").value();
CHECK_EQ(ms.str(), "conda-forge[noarch]::tzdata");
CHECK_EQ(ms.channel().value().str(), "conda-forge[noarch]");
CHECK_EQ(ms.name().str(), "tzdata");
CHECK(ms.version().is_explicitly_free());
CHECK(ms.build_string().is_free());
}

SUBCASE("conda-forge::noarch/tzdata")
SUBCASE("conda-forge[noarch]::tzdata")
{
auto ms = MatchSpec::parse("conda-forge::noarch/tzdata").value();
CHECK_EQ(ms.str(), "conda-forge::noarch/tzdata");
auto ms = MatchSpec::parse("conda-forge/noarch::tzdata").value();
CHECK_EQ(ms.str(), "conda-forge[noarch]::tzdata");
CHECK_EQ(ms.channel().value().str(), "conda-forge[noarch]");
CHECK_EQ(ms.name().str(), "tzdata");
CHECK(ms.version().is_explicitly_free());
CHECK(ms.build_string().is_free());
}

SUBCASE("pkgs/main::tzdata")
{
auto ms = MatchSpec::parse("pkgs/main::tzdata").value();
CHECK_EQ(ms.str(), "pkgs/main::tzdata");
CHECK_EQ(ms.channel().value().str(), "pkgs/main");
CHECK_EQ(ms.name().str(), "tzdata");
CHECK(ms.version().is_explicitly_free());
CHECK(ms.build_string().is_free());
}

SUBCASE("pkgs/main/noarch::tzdata")
{
auto ms = MatchSpec::parse("pkgs/main/noarch::tzdata").value();
CHECK_EQ(ms.str(), "pkgs/main[noarch]::tzdata");
CHECK_EQ(ms.channel().value().str(), "pkgs/main[noarch]");
CHECK_EQ(ms.name().str(), "tzdata");
CHECK(ms.version().is_explicitly_free());
CHECK(ms.build_string().is_free());
}

SUBCASE("conda-forge[noarch]::tzdata[subdir=linux64]")
{
auto ms = MatchSpec::parse("conda-forge[noarch]::tzdata[subdir=linux64]").value();
CHECK_EQ(ms.str(), "conda-forge[noarch]::tzdata");
CHECK_EQ(ms.channel().value().str(), "conda-forge[noarch]");
CHECK_EQ(ms.subdirs().value().get(), MatchSpec::subdir_list{ "noarch" });
CHECK_EQ(ms.name().str(), "tzdata");
CHECK(ms.version().is_explicitly_free());
CHECK(ms.build_string().is_free());
}

SUBCASE("conda-forge::tzdata[subdir=mamba-37]")
{
auto ms = MatchSpec::parse("conda-forge::tzdata[subdir=mamba-37]").value();
CHECK_EQ(ms.str(), "conda-forge[mamba-37]::tzdata");
CHECK_EQ(ms.channel().value().str(), "conda-forge[mamba-37]");
CHECK_EQ(ms.subdirs().value().get(), MatchSpec::subdir_list{ "mamba-37" });
CHECK_EQ(ms.name().str(), "tzdata");
CHECK(ms.version().is_explicitly_free());
CHECK(ms.build_string().is_free());
}

SUBCASE("conda-canary/linux-64::conda==4.3.21.post699+1dab973=py36h4a561cd_0")
{
auto ms = MatchSpec::parse(
"conda-canary/linux-64::conda==4.3.21.post699+1dab973=py36h4a561cd_0"
)
.value();
CHECK_EQ(ms.channel().value().str(), "conda-canary[linux-64]");
CHECK_EQ(ms.subdirs().value().get(), MatchSpec::subdir_list{ "linux-64" });
CHECK_EQ(ms.name().str(), "conda");
CHECK_EQ(ms.version().str(), "==4.3.21.0post699+1dab973"); // Not ``.0post`` diff
CHECK_EQ(ms.build_string().str(), "py36h4a561cd_0");
}
}

Expand Down

0 comments on commit e9c45df

Please sign in to comment.