summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authoraur-build <aur-build@localhost>2026-11-20 20:14:27 +0000
committeraur-build <aur-build@localhost>2026-11-20 20:14:27 +0000
commit68ec6971b872d8be561e8c2c2748c6c143bfef7d (patch)
tree6d8489dbf6d05106b67770b529dc5eb3e849805e /tests
parente6c3a02229994a9e007d8e6618add778e1ec021c (diff)
downloadaur-build-68ec6971b872d8be561e8c2c2748c6c143bfef7d.tar.gz
aur-build-68ec6971b872d8be561e8c2c2748c6c143bfef7d.zip
pkgver: move the pure version and dependency tests into the module
Ten tests in tests/versions.rs were unit tests of pkgver wearing an integration test's clothing: the comparison vectors, the chunk rule, the epoch rules, the dependency grammar, the constraint checks, the recorded oracle. None of them touched a database or a fixture. They were written against the crate's public API because that was the only way to reach them from outside, and that single fact — that a test had to import a name to exercise it — is what had been keeping five items public: vercmp_string, Dep, DepOp, Dep::satisfied_by, split_full_version All five are private now. `vercmp_string` is called by `vercmp` and by nothing else; `Dep` and `DepOp` are the internals of `dep_names`, which *is* used in production; `satisfied_by` and `Dep::name` are used only by this module's tests, so they are gated rather than merely private, and `cargo check --release` without the test-support feature compiles clean, which is the proof that nothing production needs them was left behind. The oracle test now resolves testcorpus/ through CARGO_MANIFEST_DIR rather than the harness helper, so it no longer depends on the working directory. The live pacman differential came with it and stays gated on AUR_LIVE_VERCMP, recording its absence the same way. What remains in tests/versions.rs is two tests that genuinely need the harness: they build a package, publish it, and move its upstream. pkgver: 14 pub / 5 test-only -> 8 pub / 0 test-only. Suite: 281 passed, 0 failed.
Diffstat (limited to 'tests')
-rw-r--r--tests/architecture-budget.json18
-rw-r--r--tests/versions.rs243
2 files changed, 15 insertions, 246 deletions
diff --git a/tests/architecture-budget.json b/tests/architecture-budget.json
index 4df78b1..93578fb 100644
--- a/tests/architecture-budget.json
+++ b/tests/architecture-budget.json
@@ -210,15 +210,15 @@
"test": 0
},
"pkgver": {
- "dead": 5,
+ "dead": 0,
"deadonly": 0,
"glob": 0,
- "largest": 343,
+ "largest": 545,
"largest_file": "src/pkgver/mod.rs",
- "lines": 343,
+ "lines": 545,
"priv": 0,
- "pub": 14,
- "test": 5
+ "pub": 8,
+ "test": 0
},
"recipe": {
"dead": 0,
@@ -310,15 +310,15 @@
}
},
"totals": {
- "dead": 105,
+ "dead": 100,
"deadonly": 33,
"edges": 87,
"glob": 0,
"largest": 603,
"largest_file": "src/shims/mod.rs",
- "lines": 14291,
+ "lines": 14493,
"priv": 109,
- "pub": 505,
- "test": 72
+ "pub": 499,
+ "test": 67
}
}
diff --git a/tests/versions.rs b/tests/versions.rs
index 2d808ba..175938d 100644
--- a/tests/versions.rs
+++ b/tests/versions.rs
@@ -4,233 +4,15 @@ use std::cmp::Ordering;
use aur_build::db::model::*;
use aur_build::pipeline;
-use aur_build::pkgver::{self, Dep, DepOp};
+use aur_build::pkgver;
use aur_build::review::{candidates, diff};
use common::*;
-const ORDERED: &[(&str, &str)] = &[
- ("v1.2.3", "v1.2.4"),
- ("1.0", "1.1"),
- ("1.1", "1.2"),
- ("1.2", "2.0"),
- ("2.0", "2.1.0"),
- ("2.1.0", "2.1.1"),
- ("1.0rc1", "1.0"),
- ("1.0", "1.0.0"),
- ("1.0.0", "1.0.1"),
- ("1.0.1", "1.1.0"),
- ("1.1", "1.1.0"),
- ("1", "1.0"),
- ("1.0", "1.0.1"),
- ("1.0.1", "1.1"),
- ("1.1", "1.1.1"),
- ("1.1.1", "1.2"),
- ("1.2", "1.2.2"),
- ("1.2.2", "1.3"),
- ("1.3", "1.3.1"),
- ("1.3.1", "1.4"),
- ("1.4", "1.4.1"),
- ("1.4.1", "2.0"),
- ("2.0", "2.0.1"),
- ("2.0.1", "2.1.0"),
- ("2.1.0", "2.1.1"),
- ("2.1.1", "3.0"),
- ("3.0", "3.0.1"),
- ("3.0.1", "4.0"),
- ("1.0.a", "1.0.1"),
- ("1.0.b", "1.0.2"),
- ("1.0.2", "1.0.2.a"),
- ("1.0.2.a", "1.0.2.aa"),
- ("1.0.2.aa", "1.0.2.b"),
- ("1.0.2.b", "1.0.2.bb"),
- ("1.0.2.bb", "1.0.3"),
- ("1.0.3a", "1.0.3b"),
- ("1.0.3b", "1.1"),
- ("1.1a", "1.2"),
- ("1:0.8", "2:0.1"),
- ("2:0.1", "3:0.1"),
- ("1.0-1", "1.0-2"),
- ("1.0-2", "1.0-3"),
- ("1.0-3", "1.1-1"),
- ("1:1.0-1", "1:1.0-2"),
- ("1:1.0-2", "2:0.1-1"),
- ("2.5", "2.24"),
- ("2.0", "2.0.01"),
-];
-
-#[test]
-fn vercmp_orders_the_canonical_vectors() {
- for (a, b) in ORDERED {
- assert_eq!(
- pkgver::vercmp(a, b),
- Ordering::Less,
- "vercmp({a:?}, {b:?}) should be Less"
- );
- assert_eq!(
- pkgver::vercmp(b, a),
- Ordering::Greater,
- "vercmp({b:?}, {a:?}) should be Greater (comparison must be antisymmetric)"
- );
- }
-}
-
-fn sign(o: Ordering) -> i32 {
- match o {
- Ordering::Less => -1,
- Ordering::Equal => 0,
- Ordering::Greater => 1,
- }
-}
-
-#[test]
-fn vercmp_matches_the_recorded_oracle() {
- let table = std::fs::read_to_string(corpus_root().join("vercmp-oracle.tsv"))
- .expect("testcorpus/vercmp-oracle.tsv; regenerate with tools/gen-vercmp-oracle.py");
- let mut recorded = std::collections::HashMap::new();
- let mut checked = 0;
- for line in table.lines().filter(|l| !l.starts_with('#') && !l.is_empty()) {
- let mut cols = line.split('\t');
- let (a, b) = (cols.next().unwrap(), cols.next().unwrap());
- let theirs: i32 = cols.next().unwrap().parse().expect("verdict column");
- assert_eq!(
- sign(pkgver::vercmp_string(a, b)),
- theirs,
- "vercmp({a:?}, {b:?}) disagrees with the recorded oracle"
- );
- checked += 1;
- recorded.insert((a, b), theirs);
- }
- assert!(checked >= 1089, "the cross-product should be substantial, checked {checked}");
- for ((a, b), verdict) in &recorded {
- assert_eq!(
- recorded.get(&(*b, *a)),
- Some(&-*verdict),
- "the recorded table is not antisymmetric at {a:?} / {b:?}"
- );
- }
-}
-
-#[test]
-fn the_live_vercmp_tier_is_recorded_not_silently_absent() {
- if std::env::var("AUR_LIVE_VERCMP").is_err() {
- println!("note: AUR_LIVE_VERCMP unset; the live vercmp differential is skipped, not passed");
- return;
- }
- if std::process::Command::new("vercmp").arg("1").arg("2").output().is_err() {
- println!("note: AUR_LIVE_VERCMP set but pacman's vercmp is not on PATH; tier skipped");
- return;
- }
- 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",
- "1.02", "1.0_2", "1.0.p", "1.0.3a", "1.0.3b", "1.a", "1a", "1.0+git", "1.0~beta", "2.0_1",
- "1.0.x", "2024.01",
- ];
- let mut checked = 0;
- for a in fragments {
- for b in fragments {
- let theirs = std::process::Command::new("vercmp")
- .arg(a)
- .arg(b)
- .output()
- .expect("vercmp");
- let theirs: i32 = String::from_utf8_lossy(&theirs.stdout).trim().parse().expect("vercmp output");
- assert_eq!(
- sign(pkgver::vercmp_string(a, b)),
- theirs,
- "vercmp({a:?}, {b:?}) disagrees with pacman"
- );
- checked += 1;
- }
- }
- assert!(checked > 1000, "the cross-product should be substantial, checked {checked}");
-}
-
-#[test]
-fn equal_versions_compare_equal_and_leading_zeros_do_not_matter() {
- for (a, b) in [
- ("1.0-1", "1.0-1"),
- ("1:1.0-1", "1:1.0-1"),
- ("1.02-1", "1.2-1"),
- ("01.0-1", "1.0-1"),
- ("1.0-01", "1.0-1"),
- ] {
- assert_eq!(pkgver::vercmp(a, b), Ordering::Equal, "{a} vs {b}");
- }
-}
-
-#[test]
-fn an_epoch_always_beats_a_larger_version_without_one() {
- assert_eq!(pkgver::vercmp("1:0.1-1", "9.9.9-1"), Ordering::Greater);
- assert_eq!(pkgver::vercmp("9.9.9-1", "1:0.1-1"), Ordering::Less);
- assert_eq!(pkgver::vercmp("0:1.0-1", "1.0-1"), Ordering::Equal);
- assert_eq!(pkgver::vercmp("1:1.0-1", "1.0-1"), Ordering::Greater);
-}
-
-#[test]
-fn a_pkgrel_reset_under_a_newer_pkgver_is_still_an_upgrade() {
- assert_eq!(pkgver::vercmp("1.2.3-4", "1.2.4-1"), Ordering::Less);
- assert!(!pkgver::is_downgrade("1.2.3-4", "1.2.4-1"));
- assert!(pkgver::is_downgrade("1.2.4-1", "1.2.3-9"));
-}
-
-#[test]
-fn alpha_numeric_boundaries_follow_the_chunk_rule() {
- assert_eq!(pkgver::vercmp("1.0.1", "1.0.a"), Ordering::Greater);
- assert_eq!(pkgver::vercmp("1.0.a", "1.0.1"), Ordering::Less);
- 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);
- assert_eq!(pkgver::vercmp("1.0", "1.0rc1"), Ordering::Greater);
-}
-
-#[test]
-fn dependency_strings_parse_with_their_constraints() {
- let cases = [
- ("gcc", "gcc", DepOp::Any, None),
- ("python>=3.11", "python", DepOp::Ge, Some("3.11")),
- ("openssl<3", "openssl", DepOp::Lt, Some("3")),
- ("glibc>=2.39-1", "glibc", DepOp::Ge, Some("2.39-1")),
- ("linux-api-headers=6.0", "linux-api-headers", DepOp::Eq, Some("6.0")),
- ("gcc-libs<=13.2.1-2", "gcc-libs", DepOp::Le, Some("13.2.1-2")),
- ("foo>=1:2.3-4", "foo", DepOp::Ge, Some("1:2.3-4")),
- ("python-pytest: for tests", "python-pytest", DepOp::Any, None),
- ];
- for (src, name, op, ver) in cases {
- let d = Dep::parse(src).unwrap_or_else(|| panic!("failed to parse {src:?}"));
- assert_eq!(d.name(), name, "{src:?} name");
- assert_eq!(d.op, op, "{src:?} operator");
- assert_eq!(d.version.as_deref(), ver, "{src:?} version");
- }
- 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"]);
-}
-
-#[test]
-fn version_constraints_are_satisfied_by_the_right_versions() {
- let d = Dep::parse("glibc>=2.39-1").unwrap();
- assert!(d.satisfied_by("2.39-1"));
- assert!(d.satisfied_by("2.40-1"));
- assert!(!d.satisfied_by("2.38-1"));
- assert!(Dep::parse("foo>=1.0").unwrap().satisfied_by("1:0.1-1"));
- assert!(Dep::parse("foo=1.0-1").unwrap().satisfied_by("1.0-1"));
- assert!(!Dep::parse("foo=1.0-1").unwrap().satisfied_by("1.0-2"));
- assert!(Dep::parse("foo").unwrap().satisfied_by("0"));
-}
-
-#[test]
-fn provides_and_conflicts_use_the_same_grammar() {
- 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());
- assert!(!d.name().contains(['>', '<', '=']));
- }
- assert_eq!(
- pkgver::dep_names(&["aur-build=0.1-1".into(), "other".into()]),
- vec!["aur-build", "other"]
- );
-}
+// What remains here is what a unit test cannot be: both tests build a real
+// package, publish it, and then move its upstream, so they need the fixture
+// harness and a database. The pure comparison vectors, the chunk rule, the
+// epoch rules and the dependency grammar all moved into src/pkgver/mod.rs,
+// where they are unit tests of the module rather than consumers of it.
#[test]
fn a_downgrade_in_the_aur_is_flagged_not_silently_served() {
@@ -271,19 +53,6 @@ fn an_epoch_bump_is_an_upgrade_even_though_the_version_went_down() {
assert!(!version.body.contains("DOWNGRADE"), "an epoch bump must not read as a downgrade: {:?}", version.body);
}
-#[test]
-fn full_version_round_trips_through_split() {
- for (epoch, pkgver, pkgrel, full) in [
- ("0", "1.2.3", "4", "1.2.3-4".to_string()),
- ("1", "1.2.3", "4", "1:1.2.3-4".to_string()),
- ("2", "1.0", "1", "2:1.0-1".to_string()),
- ] {
- assert_eq!(pkgver::full_version(epoch, pkgver, pkgrel), full);
- let (e, v, r) = pkgver::split_full_version(&full);
- assert_eq!((e.as_str(), v.as_str(), r.as_str()), (epoch, pkgver, pkgrel), "round trip of {full}");
- }
-}
-
// --- helpers -------------------------------------------------------------
fn publish(env: &Env, name: &str) {