diff options
Diffstat (limited to 'tests/versions.rs')
| -rw-r--r-- | tests/versions.rs | 60 |
1 files changed, 17 insertions, 43 deletions
diff --git a/tests/versions.rs b/tests/versions.rs index 04866d0..ae6e877 100644 --- a/tests/versions.rs +++ b/tests/versions.rs @@ -1,15 +1,3 @@ -//! `vercmp` and the dependency-string grammar (§4, §6). -//! -//! Version comparison is the one place where a subtle bug is invisible until it -//! publishes the wrong thing: a downgrade that reads as an upgrade gets served to -//! every consumer, and an epoch bump that reads as a downgrade gets refused. So -//! this is a table, not a story — the vectors are the ones pacman's own test -//! suite uses, plus the shapes that only appear in AUR recipes (epoch on one side -//! only, `pkgrel` reset to 1 under a new `pkgver`, alpha/numeric boundaries like -//! `1.0a` vs `1.0.1`). -//! -//! The hand-written implementation is deliberate (§14): no libalpm, no FFI. - mod common; use std::cmp::Ordering; @@ -20,13 +8,9 @@ use aur_build::pkgver::{self, Dep, DepOp}; use aur_build::review::{candidates, diff}; use common::*; -/// Ordering pairs, each `a` strictly older than `b`. -/// -/// These are not hand-derived: every pair was checked against pacman's own -/// `vercmp` on this machine, because the interesting cases (alpha suffixes, -/// alpha-vs-numeric at the same position, a shorter version beating a longer one) -/// are exactly the ones that are easy to misremember. `vercmp_matches_the_system_oracle` -/// below re-checks them whenever the binary is present. +/// Ordering pairs, each `a` strictly older than `b`. Every pair was checked +/// against pacman's own `vercmp`, because the interesting cases are exactly the +/// ones that are easy to misremember. const ORDERED: &[(&str, &str)] = &[ ("v1.2.3", "v1.2.4"), ("1.0", "1.1"), @@ -94,10 +78,8 @@ fn vercmp_orders_the_canonical_vectors() { } /// The strongest version of this test: compare the hand-written implementation -/// against pacman's own `vercmp` over a cross-product of the shapes that appear -/// in real recipes. It is skipped with a note when the binary is absent, so the -/// suite still runs on a machine without pacman — but on a real host this is the -/// test that would catch a chunking bug a hand-typed table would miss. +/// against pacman's own `vercmp` over a cross-product of the shapes that appear in +/// real recipes. Skipped with a note when the binary is absent. #[test] fn vercmp_matches_the_system_oracle() { if std::process::Command::new("vercmp").arg("1").arg("2").output().is_err() { @@ -105,8 +87,7 @@ fn vercmp_matches_the_system_oracle() { return; } // No `-` here: pacman's `vercmp` binary compares two raw version strings and - // does not split an epoch/pkgrel triple out of them, so the EVR-aware - // `vercmp` is not the right side of this comparison. `vercmp_string` is. + // does not split an epoch/pkgrel triple, so `vercmp_string` is the right side. let fragments = [ "1", "1.0", "1.0.0", "1.0.1", "1.1", "2", "2.0", "1.0a", "1.0rc1", "1.0.2a", "1.0.2.1", "1.0.2.a", "1.0.2.aa", "1.0.2.b", "1.0.2z", "1.0z", "1.0.z", "0.9", "10", "2.24", "2.5", @@ -170,13 +151,11 @@ fn a_pkgrel_reset_under_a_newer_pkgver_is_still_an_upgrade() { #[test] fn alpha_numeric_boundaries_follow_the_chunk_rule() { - // A numeric chunk is always NEWER than an alphabetic one at the same - // position — the rule that reads backwards and that this project got wrong - // until it was checked against pacman's own binary. + // A numeric chunk is always newer than an alphabetic one at the same position. assert_eq!(pkgver::vercmp("1.0.1", "1.0.a"), Ordering::Greater); assert_eq!(pkgver::vercmp("1.0.a", "1.0.1"), Ordering::Less); - // A shorter version is newer when the extra chunk is numeric, older when it - // is alphabetic — the part everyone gets wrong. + // A shorter version is newer when the extra chunk is numeric, older when it is + // alphabetic. assert_eq!(pkgver::vercmp("1.0", "1.0.1"), Ordering::Less); assert_eq!(pkgver::vercmp("1.0", "1.0a"), Ordering::Greater); assert_eq!(pkgver::vercmp("1.0rc1", "1.0"), Ordering::Less); @@ -203,8 +182,7 @@ fn dependency_strings_parse_with_their_constraints() { assert_eq!(d.op, op, "{src:?} operator"); assert_eq!(d.version.as_deref(), ver, "{src:?} version"); } - // Malformed input is dropped, not fatal: one odd optdepends line must not - // break detection for the whole recipe. + // Malformed input is dropped, not fatal. assert!(Dep::parse("").is_none()); assert!(Dep::parse(">=1.0").is_none()); assert_eq!(pkgver::dep_names(&["python>=3.11".into(), "gcc".into()]), vec!["python", "gcc"]); @@ -227,8 +205,7 @@ fn version_constraints_are_satisfied_by_the_right_versions() { #[test] fn provides_and_conflicts_use_the_same_grammar() { - // provides/conflicts entries carry versions with the same syntax; the - // dependency delta panel compares them by name. + // provides/conflicts entries carry versions with the same syntax. for src in ["aur-build", "aur-build=0.1-1", "virtual-thing>=1.0"] { let d = Dep::parse(src).expect(src); assert!(!d.name().is_empty()); @@ -243,7 +220,7 @@ fn provides_and_conflicts_use_the_same_grammar() { #[test] fn a_downgrade_in_the_aur_is_flagged_not_silently_served() { // A maintainer reverting a version is a mistake far more often than a - // deliberate rollback, and a naive string compare would not notice at all. + // deliberate rollback. let (env, fx) = env_with_fixture("plain-make"); publish(&env, "plain-make"); fx.bump(&[("pkgver", "0.9")]); @@ -258,15 +235,13 @@ fn a_downgrade_in_the_aur_is_flagged_not_silently_served() { ); assert!(version.body.contains("1.0-1 -> 0.9-1"), "{:?}", version.body); assert!(pkgver::is_downgrade("1.0-1", "0.9-1")); - // A downgrade is a decision, not an automatic rebuild: it is shown, and the - // index keeps serving the higher version until a human says otherwise. + // A downgrade is a decision, not an automatic rebuild. assert_eq!(aur_build::db::index_version(&env.db, "plain-make").unwrap().unwrap(), "1.0-1"); } #[test] fn an_epoch_bump_is_an_upgrade_even_though_the_version_went_down() { - // The classic "reset the version, add an epoch" move. String comparison - // calls 0.9 older than 1.0 and would refuse it; vercmp must not. + // The classic "reset the version, add an epoch" move. let (env, fx) = env_with_fixture("epoch-bump"); publish(&env, "epoch-bump"); append_line(&fx, "epoch=1"); @@ -301,7 +276,7 @@ fn full_version_round_trips_through_split() { // --- helpers ------------------------------------------------------------- /// Detect, render the diff, approve and build, so the next candidate has a real -/// accepted release behind it (§2 I1: nothing is published without approval). +/// accepted release behind it (I1). fn publish(env: &Env, name: &str) { let c = detect_raw(env, name); let dd = diff::render_and_store(&env.db, &env.cfg, &c).unwrap(); @@ -336,9 +311,8 @@ fn panel<'a>(panels: &'a [diff::Panel], name: &str) -> &'a diff::Panel { } /// Add a top-level declaration the fixture did not ship with (an `epoch=` line) -/// and commit it, so detection sees a recipe that genuinely gained an epoch. -/// It has to go with the other top-level assignments: after a `package_*()` -/// function it would be inside the function body and mean nothing. +/// and commit it. It has to go with the other top-level assignments: after a +/// `package_*()` function it would be inside the function body and mean nothing. fn append_line(fx: &Fixture, line: &str) { let path = fx.aur.join("PKGBUILD"); let text = std::fs::read_to_string(&path).unwrap(); |
