From 1199b1ef995aa7109e3b17e90e1d5741c9562938 Mon Sep 17 00:00:00 2001 From: Philip Sakievich Date: Sat, 8 Feb 2025 06:34:18 -0700 Subject: [PATCH] Add tests --- lib/spack/spack/test/concretization/core.py | 28 +++++++++++++++++++ .../packages/git-ref-package/package.py | 1 + 2 files changed, 29 insertions(+) diff --git a/lib/spack/spack/test/concretization/core.py b/lib/spack/spack/test/concretization/core.py index f02134782bd..42d0725588e 100644 --- a/lib/spack/spack/test/concretization/core.py +++ b/lib/spack/spack/test/concretization/core.py @@ -3305,3 +3305,31 @@ def _ensure_cache_hits(self, problem: str): # object for _ in range(5): assert h == spack.concretize.concretize_one("hdf5") + + +@pytest.mark.usefixtures("mutable_config", "mock_packages", "do_not_check_runtimes_on_reuse") +@pytest.mark.parametrize( + "spec_str, should_pass, error_type", + [ + (f"git-ref-package@main commit={'a' *40}", True, None), + (f"git-ref-package@main commit={'a' *39}", False, AssertionError), + # TODO only versions with git refs should allow the commit variant + ], +) +def test_spec_containing_commit_variant(spec_str, should_pass, error_type): + spec = spack.spec.Spec(spec_str) + if should_pass: + spec.concretize() + else: + with pytest.raises(error_type): + spec.concretize() + + +@pytest.mark.usefixtures("mutable_config", "mock_packages", "do_not_check_runtimes_on_reuse") +@pytest.mark.parametrize("version_str", [f"git.{'a' *40}=main", "git.2.1.5=main"]) +def test_relationship_git_versions_and_commit_variant(version_str): + spec = spack.spec.Spec(f"git-ref-package@{version_str}").concretized() + if spec.version.commit_sha: + assert spec.version.commit_sha == spec.variants["commit"].value + else: + assert "commit" not in spec.variants diff --git a/var/spack/repos/builtin.mock/packages/git-ref-package/package.py b/var/spack/repos/builtin.mock/packages/git-ref-package/package.py index a8004c86423..70df52156dd 100644 --- a/var/spack/repos/builtin.mock/packages/git-ref-package/package.py +++ b/var/spack/repos/builtin.mock/packages/git-ref-package/package.py @@ -14,6 +14,7 @@ class GitRefPackage(AutotoolsPackage): url = "https://github.com/dummy/dummy/archive/2.0.0.tar.gz" git = "https://github.com/dummy/dummy.git" + version("main", branch="main") version("2.1.6", sha256="a5d504c0d52e2e2721e7e7d86988dec2e290d723ced2307145dedd06aeb6fef2") version("2.1.5", sha256="3f6576971397b379d4205ae5451ff5a68edf6c103b2f03c4188ed7075fbb5f04") version("2.1.4", sha256="a0293475e6a44a3f6c045229fe50f69dc0eebc62a42405a51f19d46a5541e77a")