Skip to content

Commit

Permalink
Add a test for loading the included example packages repository
Browse files Browse the repository at this point in the history
We should verify that the example repo is and remains valid and this
also serves as a useful test with a more complex repo.

This should resolve science-computing#23 (we already have such an example packages repo
in this butido Git repo and this test does at least verify that it can
be loaded, i.e., that the definitions are syntactically valid (regarding
the type checking) - ideally we'd also have a high-level test that
actually runs some builds to verify the logic (semantics) but that can
be done as part of science-computing#109 / the CLI tests in science-computing#43).

Signed-off-by: Michael Weiss <[email protected]>
  • Loading branch information
primeos-work authored and ammernico committed Apr 30, 2024
1 parent 0426596 commit d01956e
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/repository/repository.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,4 +274,32 @@ pub mod tests {
assert_eq!(*p.version(), pversion("2"));
assert!(!p.version_is_semver());
}

#[test]
fn test_load_example_pkg_repo() -> Result<()> {
fn assert_pkg(repo: &Repository, name: &str, version: &str) {
let constraint =
PackageVersionConstraint::from_version(String::from("="), pversion(version));
let ps = repo.find_with_version(&pname(name), &constraint);
assert_eq!(ps.len(), 1, "Failed to find pkg: {name} ={version}");
let p = ps.first().unwrap();
assert_eq!(*p.name(), pname(name));
assert_eq!(*p.version(), pversion(version));
assert_eq!(p.sources().len(), 1);
}

let repo = Repository::load(
&PathBuf::from("examples/packages/repo/"),
&indicatif::ProgressBar::hidden(),
)?;

assert_pkg(&repo, "a", "1");
assert_pkg(&repo, "b", "2");
assert_pkg(&repo, "c", "3");
assert_pkg(&repo, "s", "19.0");
assert_pkg(&repo, "s", "19.1");
assert_pkg(&repo, "z", "26");

Ok(())
}
}

0 comments on commit d01956e

Please sign in to comment.